-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: improve gitInfo close #71 * test: add gitInfo spec * test: add git class * test: remove unnecessary test case
- Loading branch information
1 parent
945ae88
commit 3413a25
Showing
8 changed files
with
107 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
import { Inquirer, QuestionCollection } from "inquirer"; | ||
import { GitRepoInfo } from "git-repo-info"; | ||
import { StatusResult } from "simple-git"; | ||
|
||
export type CZ = Inquirer; | ||
export type Commit = (commitMessage: string) => void; | ||
|
||
type GitInfo = GitRepoInfo & | ||
Pick< | ||
StatusResult, | ||
"not_added" | "created" | "deleted" | "modified" | "renamed" | "staged" | ||
>; | ||
|
||
export type Config<T> = { | ||
questions: ({ | ||
inquirer, | ||
gitInfo, | ||
}: { | ||
inquirer: Inquirer; | ||
gitInfo: GitRepoInfo; | ||
gitInfo: GitInfo; | ||
}) => QuestionCollection; | ||
commitMessage: ({ | ||
answers, | ||
gitInfo, | ||
}: { | ||
answers: T; | ||
gitInfo: GitRepoInfo; | ||
gitInfo: GitInfo; | ||
}) => string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import gitRepoInfo from "git-repo-info"; | ||
import simpleGit from "simple-git"; | ||
|
||
export const getGitInfo = async (repoPath: string = process.cwd()) => { | ||
const repoInfo = gitRepoInfo(repoPath); | ||
const gitStatus = simpleGit(repoPath); | ||
const status = await gitStatus.status(); | ||
|
||
const { not_added, created, deleted, modified, renamed, staged } = status; | ||
|
||
const gitInfo = { | ||
...repoInfo, | ||
not_added, | ||
created, | ||
deleted, | ||
modified, | ||
renamed, | ||
staged, | ||
}; | ||
|
||
return { gitInfo }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./const"; | ||
export * from "./initialize"; | ||
export * from "./gitInfo"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { getGitInfo } from "../../src/util"; | ||
|
||
describe("getGitInfo", () => { | ||
it("when run function, should return some property that helpful to use information about Git", async () => { | ||
const { gitInfo } = await getGitInfo(); | ||
|
||
// By git-repo-info | ||
expect(gitInfo).toHaveProperty("sha"); | ||
expect(gitInfo).toHaveProperty("abbreviatedSha"); | ||
expect(gitInfo).toHaveProperty("branch"); | ||
expect(gitInfo).toHaveProperty("tag"); | ||
expect(gitInfo).toHaveProperty("committer"); | ||
expect(gitInfo).toHaveProperty("committerDate"); | ||
expect(gitInfo).toHaveProperty("author"); | ||
expect(gitInfo).toHaveProperty("authorDate"); | ||
expect(gitInfo).toHaveProperty("commitMessage"); | ||
expect(gitInfo).toHaveProperty("root"); | ||
expect(gitInfo).toHaveProperty("commonGitDir"); | ||
expect(gitInfo).toHaveProperty("worktreeGitDir"); | ||
expect(gitInfo).toHaveProperty("lastTag"); | ||
expect(gitInfo).toHaveProperty("commitsSinceLastTag"); | ||
expect(gitInfo).toHaveProperty("parents"); | ||
|
||
// By simple-git | ||
expect(gitInfo).toHaveProperty("not_added"); | ||
expect(gitInfo).toHaveProperty("created"); | ||
expect(gitInfo).toHaveProperty("deleted"); | ||
expect(gitInfo).toHaveProperty("modified"); | ||
expect(gitInfo).toHaveProperty("renamed"); | ||
expect(gitInfo).toHaveProperty("staged"); | ||
}); | ||
}); |