diff --git a/src/git.test.ts b/src/git.test.ts index 1c9343e..a18707a 100644 --- a/src/git.test.ts +++ b/src/git.test.ts @@ -287,6 +287,23 @@ describe("extractBranchNameFromMergeMessage", () => { }); }); + describe("GitLab format", () => { + it("should extract branch name from GitLab merge message with target", () => { + const message = "Merge branch 'ax/ENG-123-add-button' into 'develop'"; + expect(extractBranchNameFromMergeMessage(message)).toBe("ax/ENG-123-add-button"); + }); + + it("should extract branch name from GitLab merge message without target", () => { + const message = "Merge branch 'feature/ENG-456-fix-auth'"; + expect(extractBranchNameFromMergeMessage(message)).toBe("feature/ENG-456-fix-auth"); + }); + + it("should handle case insensitivity for GitLab format", () => { + const message = "MERGE BRANCH 'feature/LIN-100'"; + expect(extractBranchNameFromMergeMessage(message)).toBe("feature/LIN-100"); + }); + }); + describe("edge cases", () => { it("should return null for non-merge messages", () => { expect(extractBranchNameFromMergeMessage("Some regular commit")).toBeNull(); diff --git a/src/git.ts b/src/git.ts index 229fdcf..7b6774f 100644 --- a/src/git.ts +++ b/src/git.ts @@ -132,15 +132,24 @@ export function isMergeCommit(sha: string, cwd: string = process.cwd()): boolean } /** - * Extracts the branch name from a GitHub merge commit message. - * Matches: "Merge pull request #X from owner/branch-name" + * Extracts the branch name from a merge commit message. + * Supports: + * - GitHub: "Merge pull request #X from owner/branch-name" + * - GitLab: "Merge branch 'branch-name' into 'target'" + * - GitLab (no target): "Merge branch 'branch-name'" */ export function extractBranchNameFromMergeMessage(message: string | null | undefined): string | null { if (!message) { return null; } - const match = message.match(/Merge pull request #\d+ from [^/]+\/(\S+)/i); - return match?.[1] ?? null; + // GitHub: "Merge pull request #123 from owner/branch-name" + const githubMatch = message.match(/Merge pull request #\d+ from [^/]+\/(\S+)/i); + if (githubMatch?.[1]) { + return githubMatch[1]; + } + // GitLab: "Merge branch 'branch-name' into 'target'" or "Merge branch 'branch-name'" + const gitlabMatch = message.match(/Merge branch '([^']+)'/i); + return gitlabMatch?.[1] ?? null; } /**