feat(git-parse): new definition (#46909)

- definition file
- tests

https://www.npmjs.com/package/git-parse
https://github.com/wayfair/git-parse#api

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-08-21 06:41:37 +02:00 committed by GitHub
parent 3878502a48
commit fd190d35ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,30 @@
/// <reference types="node" />
import { gitToJs, checkoutCommit, gitDiff, gitPull } from 'git-parse';
const repoPath = '.';
const commitsPromise = gitToJs(repoPath);
commitsPromise.then(commits => console.log(JSON.stringify(commits, null, 2)));
async () => {
try {
await checkoutCommit('.', 'invalidHash');
const parsedRepo = await gitToJs(repoPath);
} catch (e) {
//
}
};
gitToJs('/some_crazy_directory_that_does_not_exist/asdfasdfasdfasdfxxxx').catch(() => {
//
});
gitToJs(repoPath).then(data => {
console.log(data);
});
gitDiff(repoPath, '3bbdbc5').then(diff => console.log(diff));
gitPull(repoPath)
.then(() => console.log('Done'))
.catch(err => console.log(err));

64
types/git-parse/index.d.ts vendored Normal file
View File

@ -0,0 +1,64 @@
// Type definitions for git-parse 1.0
// Project: https://github.com/wayfair/git-parse#readme
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* A utility which generates an array of javascript objects representing the current branch of a local git repository's commit history.
* Returns a promise which resolves with a list of objects describing git commits on the current branch.
*/
export function gitToJs(repoPath: string, options?: GitToJsOptions): Promise<GitCommit[]>;
/**
* Checks out a commit given its repo and hash.
* @async
*/
export function checkoutCommit(pathToRepo: string, hash: string, options?: CheckoutCommmitOptions): Promise<void>;
/**
* Pulls a repo given its path.
* @async
*/
export function gitPull(pathToRepo: string): Promise<void>;
/**
* Returns a git diff given a path to the repo, a commit,
* an optional second commit, and an optional file.
*/
export function gitDiff(pathToRepo: string, commitHash1: string, commitHash2?: string, file?: string): Promise<string>;
// types
export interface FileModification {
path: string;
linesAdded?: number;
linesDeleted?: number;
}
export interface FileRename {
oldPath: string;
newPath: string;
}
/**
* Object representing the current branch of a local git repository's commit history
*/
export interface GitCommit {
hash: string;
authorName: string;
authorEmail: string;
date: string;
message: string;
filesAdded: FileModification[];
filesDeleted: FileModification[];
filesModified: FileModification[];
filesRenamed: FileRename[];
}
export interface GitToJsOptions {
sinceCommit?: string;
}
export interface CheckoutCommmitOptions {
force?: boolean;
}

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"git-parse-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }