Skip to content

Commit

Permalink
fix: isProhibitedBranch detection (#394)
Browse files Browse the repository at this point in the history
Co-authored-by: peaceiris <[email protected]>
  • Loading branch information
zachbryant and peaceiris committed Jul 14, 2020
1 parent 6b76e36 commit f53ab0c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions __tests__/set-tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ describe('setGithubToken()', () => {
expect(test).toMatch(expected);
});

test('return remote url with GITHUB_TOKEN gh-pages (RegExp)', () => {
const expected = 'https://x-access-token:[email protected]/owner/repo.git';
const test = setGithubToken(
'GITHUB_TOKEN',
'owner/repo',
'gh-pages',
'',
'refs/heads/gh-pages-base',
'push'
);
expect(test).toMatch(expected);
});

test('throw error gh-pages-base to gh-pages-base (RegExp)', () => {
expect(() => {
setGithubToken(
'GITHUB_TOKEN',
'owner/repo',
'gh-pages-base',
'',
'refs/heads/gh-pages-base',
'push'
);
}).toThrowError('You deploy from gh-pages-base to gh-pages-base');
});

test('throw error master to master', () => {
expect(() => {
setGithubToken('GITHUB_TOKEN', 'owner/repo', 'master', '', 'refs/heads/master', 'push');
Expand Down
2 changes: 1 addition & 1 deletion src/set-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Use deploy_key or personal_token.
}

if (eventName === 'push') {
isProhibitedBranch = ref.includes(`refs/heads/${publishBranch}`);
isProhibitedBranch = ref.match(new RegExp(`^refs/heads/${publishBranch}$`)) !== null;
if (isProhibitedBranch) {
throw new Error(`You deploy from ${publishBranch} to ${publishBranch}`);
}
Expand Down

0 comments on commit f53ab0c

Please sign in to comment.