Skip to content

Commit ec6b426

Browse files
authored
Merge branch 'main' into #56-copilot-setup-steps
2 parents 3555e8b + 9d49159 commit ec6b426

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+452
-70
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ jobs:
9393
# build lint plugins before linting
9494
- name: Build lint plugins
9595
run: npm run build:lint:ci
96+
# check formatting
97+
- name: Check Formatting
98+
run: npm run format:ci
9699
# lint
97100
- name: Lint
98101
run: npm run lint:ci

package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
"scripts": {
1212
"build:ci": "lerna run build",
1313
"build:lint:ci": "lerna run build:lint:ci",
14+
"format": "lerna run format",
15+
"format:ci": "lerna run format:ci",
1416
"lint:ci": "lerna run lint:ci",
1517
"prepare": "husky",
16-
"prettier": "lerna run prettier",
1718
"publish-libs": "node packages/publish-helper/dist/publish-lib",
1819
"test:ci": "lerna run test:ci"
1920
},

packages/branch-utilities/.lintstagedrc.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# we use eslint instead of ng lint, because we can't use --project (tsconfig specifying files with include, exclude)
2-
# and --files argument pointing to other files
3-
src/{**/,}*.ts,test/{**/,}*.ts:
4-
- npm run prettier:staged
1+
# Reformat all .ts / .js
2+
"**/*.(t|j)s":
3+
- npm run format:staged
54
- npm run lint:staged
65

76
# sort package.json keys

packages/branch-utilities/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [5.0.1](https://github.com/shiftcode/sc-commons-public/compare/@shiftcode/[email protected]...@shiftcode/[email protected]) (2025-09-09)
7+
8+
**Note:** Version bump only for package @shiftcode/branch-utilities
9+
10+
# [5.0.0](https://github.com/shiftcode/sc-commons-public/compare/@shiftcode/[email protected]...@shiftcode/[email protected]) (2025-09-04)
11+
12+
### Features
13+
14+
- **branch-utilities:** support naming convention for github copilot branch names ([56dbb58](https://github.com/shiftcode/sc-commons-public/commit/56dbb5846397601a6dc2c238d4b4a828604cb7f1))
15+
16+
### BREAKING CHANGES
17+
18+
- **branch-utilities:** REGEX_BRANCH_NAME is no longer exported. use the utility function `parseBranchName` instead
19+
620
# [4.0.0](https://github.com/shiftcode/sc-commons-public/compare/@shiftcode/[email protected]...@shiftcode/[email protected]) (2025-05-15)
721

822
### Features

packages/branch-utilities/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shiftcode/branch-utilities",
3-
"version": "4.0.0",
3+
"version": "5.0.1",
44
"description": "Utilities for local and ci to get branch name and stage",
55
"repository": "https://github.com/shiftcode/sc-commons-public",
66
"license": "MIT",
@@ -16,13 +16,15 @@
1616
"scripts": {
1717
"prebuild": "rm -rf ./dist",
1818
"build": "tsc",
19+
"format": "npm run format:base -- --write",
20+
"format:base": "prettier --config ../../.prettierrc.yml '{src,e2e,test}/**/*.ts'",
21+
"format:ci": "npm run format:base -- --check",
22+
"format:staged": "prettier --write --config ../../.prettierrc.yml",
1923
"lint": "npm run lint:src:fix",
2024
"lint:ci": "npm run lint:src",
2125
"lint:src": "eslint ./src",
2226
"lint:src:fix": "eslint ./src --cache --fix",
2327
"lint:staged": "eslint --fix --cache",
24-
"prettier": "prettier --write --config ../../.prettierrc.yml '{src,e2e,test}/**/*.ts'",
25-
"prettier:staged": "prettier --write --config ../../.prettierrc.yml",
2628
"prepublish": "node ../publish-helper/dist/prepare-dist.js",
2729
"test": "NODE_OPTIONS=\"--experimental-vm-modules --trace-warnings\" npx jest --config jest.config.js",
2830
"test:ci": "npm run test",

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,31 @@ describe('base utils', () => {
8282

8383
describe('parseBranchName', () => {
8484
test('works when valid pattern', () => {
85-
expect(parseBranchName('#7-abc').branchId).toBe(7)
85+
expect(parseBranchName('#7-abc')).toEqual({ branchId: 7, branchName: 'abc' } satisfies ReturnType<
86+
typeof parseBranchName
87+
>)
88+
8689
expect(parseBranchName('#72-abc').branchId).toBe(72)
90+
expect(parseBranchName('#000-int').branchId).toBe(0)
91+
expect(parseBranchName('#001-test').branchId).toBe(1)
92+
8793
expect(parseBranchName('#72- whatever').branchId).toBe(72)
8894
expect(parseBranchName('feature/#72-ok').branchId).toBe(72)
8995
})
96+
97+
test('works for github copilot created branches', () => {
98+
expect(parseBranchName('copilot/fix-123')).toEqual({ branchId: 123, branchName: 'fix' } satisfies ReturnType<
99+
typeof parseBranchName
100+
>)
101+
expect(parseBranchName('copilot/feat-123')).toEqual({ branchId: 123, branchName: 'feat' } satisfies ReturnType<
102+
typeof parseBranchName
103+
>)
104+
})
105+
90106
test('throws when invalid pattern', () => {
91107
expect(() => parseBranchName('whrjwe')).toThrow()
108+
expect(() => parseBranchName('copilot/123-fix')).toThrow()
109+
expect(() => parseBranchName('feat/copilot/fix-123')).toThrow()
92110
})
93111
})
94112
})

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ export const REGEX_MASTER = /^master$/
88
/** regex to match the main branch */
99
export const REGEX_MAIN = /^main$/
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 = /^copilot\/(?<name>.*)-(?<id>\d+)$/
1322

1423
export interface StageInfo {
1524
isProd: boolean
@@ -81,9 +90,11 @@ export function getBranchInfo(env: unknown, branchName?: string): BranchInfo {
8190
}
8291

8392
export function isFullBranchOverrideDefined(envVars: unknown): envVars is CustomScOverrideEnv {
84-
return envVars !== null
85-
&& typeof (envVars as CustomScOverrideEnv).SC_OVERRIDE_BRANCH_NAME ==='string'
86-
&& typeof (envVars as CustomScOverrideEnv).SC_OVERRIDE_IS_PR ==='string'
93+
return (
94+
envVars !== null &&
95+
typeof (envVars as CustomScOverrideEnv).SC_OVERRIDE_BRANCH_NAME === 'string' &&
96+
typeof (envVars as CustomScOverrideEnv).SC_OVERRIDE_IS_PR === 'string'
97+
)
8798
}
8899

89100
export function getBranchNameOverride(env: CustomScOverrideEnv): string {
@@ -134,13 +145,11 @@ export function isMainBranch(branchName: string): boolean {
134145
* @throws Throws an error if given branchName does not match our convention
135146
*/
136147
export 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
148+
const matches = REGEX_BRANCH_NAME_DEFAULT.exec(branchName) ?? REGEX_BRANCH_NAME_COPILOT.exec(branchName)
149+
if (matches?.groups) {
141150
return {
142-
branchId: parseInt(branchId, 10),
143-
branchName: branchN,
151+
branchId: parseInt(matches.groups['id'], 10),
152+
branchName: matches.groups['name'],
144153
}
145154
} else {
146155
throw new Error(
@@ -156,7 +165,7 @@ export function parseBranchName(branchName: string): { branchId: number; branchN
156165
* @return returns true if the stage is 'master' or 'main', false if not
157166
*/
158167
export function isProduction(stageName: string): boolean {
159-
return REGEX_MASTER.test(stageName) || REGEX_MAIN.test(stageName)
168+
return REGEX_MASTER.test(stageName) ?? REGEX_MAIN.test(stageName)
160169
}
161170

162171
/**

packages/eslint-config-recommended/.lintstagedrc.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# we use eslint instead of ng lint, because we can't use --project (tsconfig specifying files with include, exclude)
2-
# and --files argument pointing to other files
3-
src/{**/,}*.ts,test/{**/,}*.ts:
4-
- npm run prettier:staged
1+
# Reformat all .ts / .js
2+
"**/*.(t|j)s":
3+
- npm run format:staged
54
- npm run lint:staged
65

76
# sort package.json keys

packages/eslint-config-recommended/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [5.0.1](https://github.com/shiftcode/sc-commons-public/compare/@shiftcode/[email protected]...@shiftcode/[email protected]) (2025-09-09)
7+
8+
**Note:** Version bump only for package @shiftcode/eslint-config-recommended
9+
610
# [5.0.0](https://github.com/shiftcode/sc-commons-public/compare/@shiftcode/[email protected]...@shiftcode/[email protected]) (2025-06-30)
711

812
### Features

0 commit comments

Comments
 (0)