mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
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:
parent
3878502a48
commit
fd190d35ae
30
types/git-parse/git-parse-tests.ts
Normal file
30
types/git-parse/git-parse-tests.ts
Normal 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
64
types/git-parse/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
23
types/git-parse/tsconfig.json
Normal file
23
types/git-parse/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/git-parse/tslint.json
Normal file
1
types/git-parse/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user