Skip to content

Commit f53ab0c

Browse files
fix: isProhibitedBranch detection (#394)
Co-authored-by: peaceiris <[email protected]>
1 parent 6b76e36 commit f53ab0c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

__tests__/set-tokens.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,32 @@ describe('setGithubToken()', () => {
4747
expect(test).toMatch(expected);
4848
});
4949

50+
test('return remote url with GITHUB_TOKEN gh-pages (RegExp)', () => {
51+
const expected = 'https://x-access-token:[email protected]/owner/repo.git';
52+
const test = setGithubToken(
53+
'GITHUB_TOKEN',
54+
'owner/repo',
55+
'gh-pages',
56+
'',
57+
'refs/heads/gh-pages-base',
58+
'push'
59+
);
60+
expect(test).toMatch(expected);
61+
});
62+
63+
test('throw error gh-pages-base to gh-pages-base (RegExp)', () => {
64+
expect(() => {
65+
setGithubToken(
66+
'GITHUB_TOKEN',
67+
'owner/repo',
68+
'gh-pages-base',
69+
'',
70+
'refs/heads/gh-pages-base',
71+
'push'
72+
);
73+
}).toThrowError('You deploy from gh-pages-base to gh-pages-base');
74+
});
75+
5076
test('throw error master to master', () => {
5177
expect(() => {
5278
setGithubToken('GITHUB_TOKEN', 'owner/repo', 'master', '', 'refs/heads/master', 'push');

src/set-tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Use deploy_key or personal_token.
8383
}
8484

8585
if (eventName === 'push') {
86-
isProhibitedBranch = ref.includes(`refs/heads/${publishBranch}`);
86+
isProhibitedBranch = ref.match(new RegExp(`^refs/heads/${publishBranch}$`)) !== null;
8787
if (isProhibitedBranch) {
8888
throw new Error(`You deploy from ${publishBranch} to ${publishBranch}`);
8989
}

0 commit comments

Comments
 (0)