From 0a72365b1e831b90c351cbe09e7f5759de79aad0 Mon Sep 17 00:00:00 2001 From: Daan Klarenbeek Date: Thu, 22 Jun 2023 20:02:14 +0200 Subject: [PATCH] feat(Commit): add sha getter --- packages/release/src/lib/Commit.ts | 14 +++++++++++++- packages/release/tests/commit.test.ts | 8 ++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/release/src/lib/Commit.ts b/packages/release/src/lib/Commit.ts index 81a815b7..81d3c1cc 100644 --- a/packages/release/src/lib/Commit.ts +++ b/packages/release/src/lib/Commit.ts @@ -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 = /^(?build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test|types|¯\\_\(ツ\)_\/¯)(?\(\w+\)?((?=:\s)|(?=!:\s)))?(?!)?(?:\s.*)?|^(?Merge \w+)/gm; @@ -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; } diff --git a/packages/release/tests/commit.test.ts b/packages/release/tests/commit.test.ts index d1cb072e..cd70e365 100644 --- a/packages/release/tests/commit.test.ts +++ b/packages/release/tests/commit.test.ts @@ -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" + }); + }); });