From f53ab0c2a5d3f3b2e6524639bae8ca84e454e049 Mon Sep 17 00:00:00 2001 From: Zach <32501288+zachbryant@users.noreply.github.com> Date: Mon, 13 Jul 2020 17:05:55 -0700 Subject: [PATCH] fix: isProhibitedBranch detection (#394) Co-authored-by: peaceiris <30958501+peaceiris@users.noreply.github.com> --- __tests__/set-tokens.test.ts | 26 ++++++++++++++++++++++++++ src/set-tokens.ts | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/__tests__/set-tokens.test.ts b/__tests__/set-tokens.test.ts index d6c373c..ea8a4a5 100644 --- a/__tests__/set-tokens.test.ts +++ b/__tests__/set-tokens.test.ts @@ -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'); diff --git a/src/set-tokens.ts b/src/set-tokens.ts index ab1e462..abe0997 100644 --- a/src/set-tokens.ts +++ b/src/set-tokens.ts @@ -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}`); }