Skip to content

Commit 8c1d1ca

Browse files
committed
fix(is-production): crucial fix to detect main correctly as production
add some tests to prevent future fails..
1 parent 4602438 commit 8c1d1ca

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BranchInfo, getBranchInfo, parseBranchName } from './base.utils.js'
1+
import { BranchInfo, getBranchInfo, isProduction, isPullRequest, parseBranchName } from './base.utils.js'
22
import { CustomGitHubContext, GithubActionEnv, GitHubContext } from './types/index.js'
33
import { CustomScOverrideEnv } from './types/sc-override-env-var.type.js'
44

@@ -109,4 +109,31 @@ describe('base utils', () => {
109109
expect(() => parseBranchName('feat/copilot/fix-123')).toThrow()
110110
})
111111
})
112+
113+
describe('isProduction', () => {
114+
test.each([
115+
['main', true],
116+
['master', true],
117+
['prod', false],
118+
['xx1', false],
119+
['pr1', false],
120+
['pr1-main', false],
121+
['xx1-master', false],
122+
])("when '%s' it returns %s", (stageName, expected) => {
123+
expect(isProduction(stageName)).toBe(expected)
124+
})
125+
})
126+
127+
describe('isPullRequest', () => {
128+
test.each([
129+
['pr1', true],
130+
['pr123456', true],
131+
['xx1', false],
132+
['xx123', false],
133+
['main', false],
134+
['master', false],
135+
])("when '%s' it returns %s", (stageName, expected) => {
136+
expect(isPullRequest(stageName)).toBe(expected)
137+
})
138+
})
112139
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export function parseBranchName(branchName: string): { branchId: number; branchN
165165
* @return returns true if the stage is 'master' or 'main', false if not
166166
*/
167167
export function isProduction(stageName: string): boolean {
168-
return REGEX_MASTER.test(stageName) ?? REGEX_MAIN.test(stageName)
168+
return REGEX_MASTER.test(stageName) || REGEX_MAIN.test(stageName)
169169
}
170170

171171
/**

0 commit comments

Comments
 (0)