@@ -8,8 +8,17 @@ export const REGEX_MASTER = /^master$/
88/** regex to match the main branch */
99export const REGEX_MAIN = / ^ m a i n $ /
1010
11- /** regex to match our branch conventions with the following capture groups: fullMatch / branch id / branch name */
12- export const REGEX_BRANCH_NAME = / ^ [ a - z ] * \/ ? # ( \d + ) - ( .* ) /
11+ /**
12+ * regex to match our branch conventions with the following named capture groups: id, name
13+ * @example #123-my-feature -> { id: '123', name: 'my-feature' }
14+ * @example feature/#456-yanr -> { id: '456', name: 'yanr' }
15+ */
16+ const REGEX_BRANCH_NAME_DEFAULT = / ^ [ a - z ] * \/ ? # (?< id > \d + ) - (?< name > .* ) $ /
17+ /**
18+ * regex to match the branch convention github copilot uses with the following named capture groups: id, name
19+ * @example copilot/fix-789 -> { id: '789', name: 'fix' }
20+ */
21+ const REGEX_BRANCH_NAME_COPILOT = / c o p i l o t \/ (?< name > f i x ) - (?< id > \d + ) /
1322
1423export interface StageInfo {
1524 isProd : boolean
@@ -134,13 +143,11 @@ export function isMainBranch(branchName: string): boolean {
134143 * @throws Throws an error if given branchName does not match our convention
135144 */
136145export function parseBranchName ( branchName : string ) : { branchId : number ; branchName : string } {
137- const matches = branchName . match ( REGEX_BRANCH_NAME )
138- if ( matches ) {
139- // [0] full match / [1] branch id / [2] branch name
140- const [ , branchId , branchN ] = matches
146+ const matches = REGEX_BRANCH_NAME_DEFAULT . exec ( branchName ) || REGEX_BRANCH_NAME_COPILOT . exec ( branchName )
147+ if ( matches && matches . groups ) {
141148 return {
142- branchId : parseInt ( branchId , 10 ) ,
143- branchName : branchN ,
149+ branchId : parseInt ( matches . groups [ 'id' ] , 10 ) ,
150+ branchName : matches . groups [ 'name' ] ,
144151 }
145152 } else {
146153 throw new Error (
0 commit comments