Skip to content

Commit

Permalink
feat(Commit): add sha getter
Browse files Browse the repository at this point in the history
  • Loading branch information
ijsKoud committed Jun 22, 2023
1 parent a37132f commit 0a72365
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/release/src/lib/Commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import type { Endpoints } from "@octokit/types";
export class Commit {
public constructor(public data: GitHubCommit) {}

/**
* Parses the commit message
* @returns
*/
public parse(): CommitParserResult | null {
const commitRegex =
/^(?<type>build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|types|¯\\_\(ツ\)_\/¯)(?<scope>\(\w+\)?((?=:\s)|(?=!:\s)))?(?<breaking>!)?(?<subject>:\s.*)?|^(?<merge>Merge \w+)/gm;
Expand All @@ -23,12 +27,20 @@ export class Commit {
merge: Boolean(merge)
};
}

public get sha() {
const name = this.data.sha.slice(0, 7);
const url = this.data.html_url;

return { name, url };
}
}

export interface CommitParserResult {
type: CommitType;
scope: string;
scope?: string;
message: string;

breaking: boolean;
merge: boolean;
}
Expand Down
8 changes: 8 additions & 0 deletions packages/release/tests/commit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ describe("Commit", () => {
scope: "Manager"
});
});

test("sha", () => {
const commit = new Commit(featBreakingMockCommit);
expect(commit.sha).toStrictEqual({
name: "6dcb09b5b57875f334f61aebed695e2e4193db5e",
url: "https://github.com/octocat/Hello-World/commit/6dcb09b5b57875f334f61aebed695e2e4193db5e"
});
});
});

0 comments on commit 0a72365

Please sign in to comment.