Skip to content

Commit 97caf8f

Browse files
committed
refactor(branch-utilities): improve copilot branch regex
1 parent 9166e1c commit 97caf8f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

packages/branch-utilities/src/lib/base.utils.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@ describe('base utils', () => {
9595

9696
test('works for github copilot created branches', () => {
9797
expect(parseBranchName('copilot/fix-123')).toEqual({ branchId: 123, branchName: 'fix' } satisfies ReturnType<typeof parseBranchName>)
98+
expect(parseBranchName('copilot/feat-123')).toEqual({ branchId: 123, branchName: 'feat' } satisfies ReturnType<typeof parseBranchName>)
9899
})
100+
99101
test('throws when invalid pattern', () => {
100102
expect(() => parseBranchName('whrjwe')).toThrow()
103+
expect(() => parseBranchName('copilot/123-fix')).toThrow()
104+
expect(() => parseBranchName('feat/copilot/fix-123')).toThrow()
101105
})
102106
})
103107
})

packages/branch-utilities/src/lib/base.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const REGEX_BRANCH_NAME_DEFAULT = /^[a-z]*\/?#(?<id>\d+)-(?<name>.*)$/
1818
* regex to match the branch convention github copilot uses with the following named capture groups: id, name
1919
* @example copilot/fix-789 -> { id: '789', name: 'fix' }
2020
*/
21-
const REGEX_BRANCH_NAME_COPILOT = /copilot\/(?<name>fix)-(?<id>\d+)/
21+
const REGEX_BRANCH_NAME_COPILOT = /^copilot\/(?<name>.*)-(?<id>\d+)$/
2222

2323
export interface StageInfo {
2424
isProd: boolean

0 commit comments

Comments
 (0)