Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

コミットメッセージに ';' が含まれていてもPRが取得できるようにする #7

Merged
merged 1 commit into from
Feb 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ export interface CommitListItem {
date: string;
}

function parseLogMessage(commit: string): CommitListItem | null {
const parts = commit.match(/hash<(.+)> ref<(.*)> message<(.*)> date<(.*)>/) || [];

if (!parts || parts.length === 0) {
return null;
}

return {
sha: parts[1],
refName: parts[2],
summary: parts[3],
date: parts[4],
};
}

export function listCommits(from: string, to: string = "", duplicateCheckBranches: string[] = []): CommitListItem[] {
execa.sync("git", ["fetch"])

Expand All @@ -41,20 +56,20 @@ export function listCommits(from: string, to: string = "", duplicateCheckBranche
Array.prototype.push.apply(targetCommits, commits)
})

// Prints "<short-hash>;<ref-name>;<summary>;<date>"
// Prints "hash<short-hash> ref<ref-name> message<summary> date<date>"
// This format is used in `getCommitInfos` for easily analize the commit.
return execa
.sync("git", ["log", "--oneline", "--pretty=%h;%D;%s;%cd", "--date=short", `${from}..${to}`])
.sync("git", [
"log",
"--oneline",
"--pretty=hash<%h> ref<%D> message<%s> date<%cd>",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsonにできると分かりやすそうですが、ここjsonで出力できないですかね

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あ、もとのrepositoryがこの修正なんですね

"--date=short",
`${from}..${to}`,
])
.stdout.split("\n")
.filter(Boolean)
.map((commit: string) => {
const parts = commit.split(";");
const sha = parts[0];
const refName = parts[1];
const summary = parts[2];
const date = parts[3];
return { sha, refName, summary, date };
})
.map(parseLogMessage)
.filter(Boolean)
.filter((item: CommitListItem) => {
return !targetCommits.includes(item.summary)
})
Expand Down