From 56dbb5846397601a6dc2c238d4b4a828604cb7f1 Mon Sep 17 00:00:00 2001 From: Simon Mumenthaler Date: Thu, 4 Sep 2025 08:15:43 +0200 Subject: [PATCH 1/9] feat(branch-utilities): support naming convention for github copilot branch names BREAKING CHANGE: REGEX_BRANCH_NAME is no longer exported. use the utility function `parseBranchName` instead --- .../src/lib/base.utils.spec.ts | 11 ++++++++- .../branch-utilities/src/lib/base.utils.ts | 23 ++++++++++++------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/branch-utilities/src/lib/base.utils.spec.ts b/packages/branch-utilities/src/lib/base.utils.spec.ts index fdaf49b..24be4d9 100644 --- a/packages/branch-utilities/src/lib/base.utils.spec.ts +++ b/packages/branch-utilities/src/lib/base.utils.spec.ts @@ -81,12 +81,21 @@ describe('base utils', () => { }) describe('parseBranchName', () => { + test('works when valid pattern', () => { - expect(parseBranchName('#7-abc').branchId).toBe(7) + expect(parseBranchName('#7-abc')).toEqual({ branchId: 7, branchName: 'abc' } satisfies ReturnType) + expect(parseBranchName('#72-abc').branchId).toBe(72) + expect(parseBranchName('#000-int').branchId).toBe(0) + expect(parseBranchName('#001-test').branchId).toBe(1) + expect(parseBranchName('#72- whatever').branchId).toBe(72) expect(parseBranchName('feature/#72-ok').branchId).toBe(72) }) + + test('works for github copilot created branches', () => { + expect(parseBranchName('copilot/fix-123')).toEqual({ branchId: 123, branchName: 'fix' } satisfies ReturnType) + }) test('throws when invalid pattern', () => { expect(() => parseBranchName('whrjwe')).toThrow() }) diff --git a/packages/branch-utilities/src/lib/base.utils.ts b/packages/branch-utilities/src/lib/base.utils.ts index df60bf8..3bb9853 100644 --- a/packages/branch-utilities/src/lib/base.utils.ts +++ b/packages/branch-utilities/src/lib/base.utils.ts @@ -8,8 +8,17 @@ export const REGEX_MASTER = /^master$/ /** regex to match the main branch */ export const REGEX_MAIN = /^main$/ -/** regex to match our branch conventions with the following capture groups: fullMatch / branch id / branch name */ -export const REGEX_BRANCH_NAME = /^[a-z]*\/?#(\d+)-(.*)/ +/** + * regex to match our branch conventions with the following named capture groups: id, name + * @example #123-my-feature -> { id: '123', name: 'my-feature' } + * @example feature/#456-yanr -> { id: '456', name: 'yanr' } + */ +const REGEX_BRANCH_NAME_DEFAULT = /^[a-z]*\/?#(?\d+)-(?.*)$/ +/** + * regex to match the branch convention github copilot uses with the following named capture groups: id, name + * @example copilot/fix-789 -> { id: '789', name: 'fix' } + */ +const REGEX_BRANCH_NAME_COPILOT = /copilot\/(?fix)-(?\d+)/ export interface StageInfo { isProd: boolean @@ -134,13 +143,11 @@ export function isMainBranch(branchName: string): boolean { * @throws Throws an error if given branchName does not match our convention */ export function parseBranchName(branchName: string): { branchId: number; branchName: string } { - const matches = branchName.match(REGEX_BRANCH_NAME) - if (matches) { - // [0] full match / [1] branch id / [2] branch name - const [, branchId, branchN] = matches + const matches = REGEX_BRANCH_NAME_DEFAULT.exec(branchName) || REGEX_BRANCH_NAME_COPILOT.exec(branchName) + if (matches && matches.groups) { return { - branchId: parseInt(branchId, 10), - branchName: branchN, + branchId: parseInt(matches.groups['id'], 10), + branchName: matches.groups['name'], } } else { throw new Error( From 04b8d80b088003ffe86a70be4413d44d6960c175 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Thu, 4 Sep 2025 06:51:02 +0000 Subject: [PATCH 2/9] build(release): next version [skip_build] - @shiftcode/branch-utilities@5.0.0-pr58.0 - @shiftcode/publish-helper@4.0.1-pr58.0 --- package-lock.json | 6 +++--- packages/branch-utilities/package.json | 2 +- packages/publish-helper/package.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index e5924ce..e328f03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14836,7 +14836,7 @@ }, "packages/branch-utilities": { "name": "@shiftcode/branch-utilities", - "version": "4.0.0", + "version": "5.0.0-pr58.0", "license": "MIT", "engines": { "node": "^20.0.0 || ^22.0.0" @@ -14921,7 +14921,7 @@ }, "packages/publish-helper": { "name": "@shiftcode/publish-helper", - "version": "4.0.0", + "version": "4.0.1-pr58.0", "license": "MIT", "dependencies": { "conventional-changelog-angular": "^8.0.0", @@ -14932,7 +14932,7 @@ "publish-lib": "dist/publish-lib.js" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.0.0", + "@shiftcode/branch-utilities": "^5.0.0-pr58.0", "@types/yargs": "^17.0.32" }, "engines": { diff --git a/packages/branch-utilities/package.json b/packages/branch-utilities/package.json index 9074363..cd58ef0 100644 --- a/packages/branch-utilities/package.json +++ b/packages/branch-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/branch-utilities", - "version": "4.0.0", + "version": "5.0.0-pr58.0", "description": "Utilities for local and ci to get branch name and stage", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index b846663..630dafa 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/publish-helper", - "version": "4.0.0", + "version": "4.0.1-pr58.0", "description": "scripts for conventional (pre)releases", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", @@ -30,7 +30,7 @@ "yargs": "^17.7.2" }, "devDependencies": { - "@shiftcode/branch-utilities": "^4.0.0", + "@shiftcode/branch-utilities": "^5.0.0-pr58.0", "@types/yargs": "^17.0.32" }, "peerDependencies": { From 67772138cc2070ed5f5cd8ce8630dbd9aadfbbfc Mon Sep 17 00:00:00 2001 From: Simon Mumenthaler Date: Thu, 4 Sep 2025 09:02:05 +0200 Subject: [PATCH 3/9] feat(publish-helper): support latest branch-utilities to allow github copilot branch names --- packages/publish-helper/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index 630dafa..dd88599 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -34,7 +34,7 @@ "@types/yargs": "^17.0.32" }, "peerDependencies": { - "@shiftcode/branch-utilities": "^4.0.0 || ^4.0.0-pr45", + "@shiftcode/branch-utilities": "^4.0.0 || ^5.0.0-pr58.0", "lerna": "^8.1.6", "tslib": "^2.3.0" }, From 43e8b00f71b94a5ba17480251e20bcf571fe50ea Mon Sep 17 00:00:00 2001 From: Github Actions Date: Thu, 4 Sep 2025 07:05:21 +0000 Subject: [PATCH 4/9] build(release): next version [skip_build] - @shiftcode/branch-utilities@5.0.0-pr58.1 - @shiftcode/publish-helper@4.1.0-pr58.0 --- package-lock.json | 8 ++++---- packages/branch-utilities/package.json | 2 +- packages/publish-helper/package.json | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index e328f03..79d8634 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14836,7 +14836,7 @@ }, "packages/branch-utilities": { "name": "@shiftcode/branch-utilities", - "version": "5.0.0-pr58.0", + "version": "5.0.0-pr58.1", "license": "MIT", "engines": { "node": "^20.0.0 || ^22.0.0" @@ -14921,7 +14921,7 @@ }, "packages/publish-helper": { "name": "@shiftcode/publish-helper", - "version": "4.0.1-pr58.0", + "version": "4.1.0-pr58.0", "license": "MIT", "dependencies": { "conventional-changelog-angular": "^8.0.0", @@ -14932,14 +14932,14 @@ "publish-lib": "dist/publish-lib.js" }, "devDependencies": { - "@shiftcode/branch-utilities": "^5.0.0-pr58.0", + "@shiftcode/branch-utilities": "^5.0.0-pr58.1", "@types/yargs": "^17.0.32" }, "engines": { "node": "^20.0.0 || ^22.0.0" }, "peerDependencies": { - "@shiftcode/branch-utilities": "^4.0.0 || ^4.0.0-pr45", + "@shiftcode/branch-utilities": "^4.0.0 || ^5.0.0-pr58.0", "lerna": "^8.1.6", "tslib": "^2.3.0" } diff --git a/packages/branch-utilities/package.json b/packages/branch-utilities/package.json index cd58ef0..500604b 100644 --- a/packages/branch-utilities/package.json +++ b/packages/branch-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/branch-utilities", - "version": "5.0.0-pr58.0", + "version": "5.0.0-pr58.1", "description": "Utilities for local and ci to get branch name and stage", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index dd88599..bb20d2e 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/publish-helper", - "version": "4.0.1-pr58.0", + "version": "4.1.0-pr58.0", "description": "scripts for conventional (pre)releases", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", @@ -30,7 +30,7 @@ "yargs": "^17.7.2" }, "devDependencies": { - "@shiftcode/branch-utilities": "^5.0.0-pr58.0", + "@shiftcode/branch-utilities": "^5.0.0-pr58.1", "@types/yargs": "^17.0.32" }, "peerDependencies": { From d9328e5ef5fd6509556b77a676d3cc7235568eec Mon Sep 17 00:00:00 2001 From: Simon Mumenthaler Date: Thu, 4 Sep 2025 10:01:39 +0200 Subject: [PATCH 5/9] refactor(publish-helper): prepare for @shiftcode/branch-utilities@5.0.0 --- packages/publish-helper/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index bb20d2e..2e2fb9f 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -34,7 +34,7 @@ "@types/yargs": "^17.0.32" }, "peerDependencies": { - "@shiftcode/branch-utilities": "^4.0.0 || ^5.0.0-pr58.0", + "@shiftcode/branch-utilities": "^4.0.0 || ^5.0.0-pr58 || ^5.0.0", "lerna": "^8.1.6", "tslib": "^2.3.0" }, From 93cf51a36cf8b398ac76e18024b1a78039cbbc55 Mon Sep 17 00:00:00 2001 From: Simon Mumenthaler Date: Thu, 4 Sep 2025 10:02:47 +0200 Subject: [PATCH 6/9] refactor(branch-utilities): use null coalescing and optional chaining --- packages/branch-utilities/src/lib/base.utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/branch-utilities/src/lib/base.utils.ts b/packages/branch-utilities/src/lib/base.utils.ts index 3bb9853..c76762d 100644 --- a/packages/branch-utilities/src/lib/base.utils.ts +++ b/packages/branch-utilities/src/lib/base.utils.ts @@ -143,8 +143,8 @@ export function isMainBranch(branchName: string): boolean { * @throws Throws an error if given branchName does not match our convention */ export function parseBranchName(branchName: string): { branchId: number; branchName: string } { - const matches = REGEX_BRANCH_NAME_DEFAULT.exec(branchName) || REGEX_BRANCH_NAME_COPILOT.exec(branchName) - if (matches && matches.groups) { + const matches = REGEX_BRANCH_NAME_DEFAULT.exec(branchName) ?? REGEX_BRANCH_NAME_COPILOT.exec(branchName) + if (matches?.groups) { return { branchId: parseInt(matches.groups['id'], 10), branchName: matches.groups['name'], @@ -163,7 +163,7 @@ export function parseBranchName(branchName: string): { branchId: number; branchN * @return returns true if the stage is 'master' or 'main', false if not */ export function isProduction(stageName: string): boolean { - return REGEX_MASTER.test(stageName) || REGEX_MAIN.test(stageName) + return REGEX_MASTER.test(stageName) ?? REGEX_MAIN.test(stageName) } /** From 9166e1c1805c6dd9e16437f5496b9f196fc65d46 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Thu, 4 Sep 2025 08:04:58 +0000 Subject: [PATCH 7/9] build(release): next version [skip_build] - @shiftcode/branch-utilities@5.0.0-pr58.2 - @shiftcode/publish-helper@4.1.0-pr58.1 --- package-lock.json | 8 ++++---- packages/branch-utilities/package.json | 2 +- packages/publish-helper/package.json | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 79d8634..3c557a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14836,7 +14836,7 @@ }, "packages/branch-utilities": { "name": "@shiftcode/branch-utilities", - "version": "5.0.0-pr58.1", + "version": "5.0.0-pr58.2", "license": "MIT", "engines": { "node": "^20.0.0 || ^22.0.0" @@ -14921,7 +14921,7 @@ }, "packages/publish-helper": { "name": "@shiftcode/publish-helper", - "version": "4.1.0-pr58.0", + "version": "4.1.0-pr58.1", "license": "MIT", "dependencies": { "conventional-changelog-angular": "^8.0.0", @@ -14932,14 +14932,14 @@ "publish-lib": "dist/publish-lib.js" }, "devDependencies": { - "@shiftcode/branch-utilities": "^5.0.0-pr58.1", + "@shiftcode/branch-utilities": "^5.0.0-pr58.2", "@types/yargs": "^17.0.32" }, "engines": { "node": "^20.0.0 || ^22.0.0" }, "peerDependencies": { - "@shiftcode/branch-utilities": "^4.0.0 || ^5.0.0-pr58.0", + "@shiftcode/branch-utilities": "^4.0.0 || ^5.0.0-pr58 || ^5.0.0", "lerna": "^8.1.6", "tslib": "^2.3.0" } diff --git a/packages/branch-utilities/package.json b/packages/branch-utilities/package.json index 500604b..f22e227 100644 --- a/packages/branch-utilities/package.json +++ b/packages/branch-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/branch-utilities", - "version": "5.0.0-pr58.1", + "version": "5.0.0-pr58.2", "description": "Utilities for local and ci to get branch name and stage", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index 2e2fb9f..73b9483 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/publish-helper", - "version": "4.1.0-pr58.0", + "version": "4.1.0-pr58.1", "description": "scripts for conventional (pre)releases", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", @@ -30,7 +30,7 @@ "yargs": "^17.7.2" }, "devDependencies": { - "@shiftcode/branch-utilities": "^5.0.0-pr58.1", + "@shiftcode/branch-utilities": "^5.0.0-pr58.2", "@types/yargs": "^17.0.32" }, "peerDependencies": { From 97caf8f989ddb88cd40190bbbf679acc756d0a9c Mon Sep 17 00:00:00 2001 From: Simon Mumenthaler Date: Thu, 4 Sep 2025 10:16:49 +0200 Subject: [PATCH 8/9] refactor(branch-utilities): improve copilot branch regex --- packages/branch-utilities/src/lib/base.utils.spec.ts | 4 ++++ packages/branch-utilities/src/lib/base.utils.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/branch-utilities/src/lib/base.utils.spec.ts b/packages/branch-utilities/src/lib/base.utils.spec.ts index 24be4d9..e57ca14 100644 --- a/packages/branch-utilities/src/lib/base.utils.spec.ts +++ b/packages/branch-utilities/src/lib/base.utils.spec.ts @@ -95,9 +95,13 @@ describe('base utils', () => { test('works for github copilot created branches', () => { expect(parseBranchName('copilot/fix-123')).toEqual({ branchId: 123, branchName: 'fix' } satisfies ReturnType) + expect(parseBranchName('copilot/feat-123')).toEqual({ branchId: 123, branchName: 'feat' } satisfies ReturnType) }) + test('throws when invalid pattern', () => { expect(() => parseBranchName('whrjwe')).toThrow() + expect(() => parseBranchName('copilot/123-fix')).toThrow() + expect(() => parseBranchName('feat/copilot/fix-123')).toThrow() }) }) }) diff --git a/packages/branch-utilities/src/lib/base.utils.ts b/packages/branch-utilities/src/lib/base.utils.ts index c76762d..5f39748 100644 --- a/packages/branch-utilities/src/lib/base.utils.ts +++ b/packages/branch-utilities/src/lib/base.utils.ts @@ -18,7 +18,7 @@ const REGEX_BRANCH_NAME_DEFAULT = /^[a-z]*\/?#(?\d+)-(?.*)$/ * regex to match the branch convention github copilot uses with the following named capture groups: id, name * @example copilot/fix-789 -> { id: '789', name: 'fix' } */ -const REGEX_BRANCH_NAME_COPILOT = /copilot\/(?fix)-(?\d+)/ +const REGEX_BRANCH_NAME_COPILOT = /^copilot\/(?.*)-(?\d+)$/ export interface StageInfo { isProd: boolean From c0791957f14f2033907b9a78b7715c3092e60b7a Mon Sep 17 00:00:00 2001 From: Github Actions Date: Thu, 4 Sep 2025 08:19:09 +0000 Subject: [PATCH 9/9] build(release): next version [skip_build] - @shiftcode/branch-utilities@5.0.0-pr58.3 - @shiftcode/publish-helper@4.1.0-pr58.2 --- package-lock.json | 6 +++--- packages/branch-utilities/package.json | 2 +- packages/publish-helper/package.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3c557a2..974aa77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14836,7 +14836,7 @@ }, "packages/branch-utilities": { "name": "@shiftcode/branch-utilities", - "version": "5.0.0-pr58.2", + "version": "5.0.0-pr58.3", "license": "MIT", "engines": { "node": "^20.0.0 || ^22.0.0" @@ -14921,7 +14921,7 @@ }, "packages/publish-helper": { "name": "@shiftcode/publish-helper", - "version": "4.1.0-pr58.1", + "version": "4.1.0-pr58.2", "license": "MIT", "dependencies": { "conventional-changelog-angular": "^8.0.0", @@ -14932,7 +14932,7 @@ "publish-lib": "dist/publish-lib.js" }, "devDependencies": { - "@shiftcode/branch-utilities": "^5.0.0-pr58.2", + "@shiftcode/branch-utilities": "^5.0.0-pr58.3", "@types/yargs": "^17.0.32" }, "engines": { diff --git a/packages/branch-utilities/package.json b/packages/branch-utilities/package.json index f22e227..fefc5bd 100644 --- a/packages/branch-utilities/package.json +++ b/packages/branch-utilities/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/branch-utilities", - "version": "5.0.0-pr58.2", + "version": "5.0.0-pr58.3", "description": "Utilities for local and ci to get branch name and stage", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", diff --git a/packages/publish-helper/package.json b/packages/publish-helper/package.json index 73b9483..2f45e6b 100644 --- a/packages/publish-helper/package.json +++ b/packages/publish-helper/package.json @@ -1,6 +1,6 @@ { "name": "@shiftcode/publish-helper", - "version": "4.1.0-pr58.1", + "version": "4.1.0-pr58.2", "description": "scripts for conventional (pre)releases", "repository": "https://github.com/shiftcode/sc-commons-public", "license": "MIT", @@ -30,7 +30,7 @@ "yargs": "^17.7.2" }, "devDependencies": { - "@shiftcode/branch-utilities": "^5.0.0-pr58.2", + "@shiftcode/branch-utilities": "^5.0.0-pr58.3", "@types/yargs": "^17.0.32" }, "peerDependencies": {