Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix false partial matches #394

Merged
merged 4 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:GITHUB_TOKEN@github.com/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