fix: isProhibitedBranch detection (#394)

Co-authored-by: peaceiris <30958501+peaceiris@users.noreply.github.com>
This commit is contained in:
Zachandpeaceiris authored and GitHub committed 2020-07-14 09:05:55 +09:00
1 parent 6b76e36ab3
commit f53ab0c2a5
2 files changed
+27 -1

No files matched your search

+26
View File
@@ -47,6 +47,32 @@ describe('setGithubToken()', () => {
expect(test).toMatch(expected); 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', () => { test('throw error master to master', () => {
expect(() => { expect(() => {
setGithubToken('GITHUB_TOKEN', 'owner/repo', 'master', '', 'refs/heads/master', 'push'); setGithubToken('GITHUB_TOKEN', 'owner/repo', 'master', '', 'refs/heads/master', 'push');
+1 -1
View File
@@ -83,7 +83,7 @@ Use deploy_key or personal_token.
} }
if (eventName === 'push') { if (eventName === 'push') {
isProhibitedBranch = ref.includes(`refs/heads/${publishBranch}`); isProhibitedBranch = ref.match(new RegExp(`^refs/heads/${publishBranch}$`)) !== null;
if (isProhibitedBranch) { if (isProhibitedBranch) {
throw new Error(`You deploy from ${publishBranch} to ${publishBranch}`); throw new Error(`You deploy from ${publishBranch} to ${publishBranch}`);
} }