diff --git a/packages/shipjs-lib/src/index.js b/packages/shipjs-lib/src/index.js index 851670a5..93c76f72 100644 --- a/packages/shipjs-lib/src/index.js +++ b/packages/shipjs-lib/src/index.js @@ -14,6 +14,9 @@ export { } from './lib/git/getLatestCommitMessage'; export { default as getRepoURL } from './lib/git/getRepoURL'; export { default as getRepoURLWithToken } from './lib/git/getRepoURLWithToken'; +export { + default as getRepoURLWithTokenMasked, +} from './lib/git/getRepoURLWithTokenMasked'; export { default as getLatestCommitHash } from './lib/git/getLatestCommitHash'; export { default as getCommitUrl } from './lib/git/getCommitUrl'; export { default as isWorkingTreeClean } from './lib/git/isWorkingTreeClean'; diff --git a/packages/shipjs-lib/src/lib/git/getRepoURLWithTokenMasked.js b/packages/shipjs-lib/src/lib/git/getRepoURLWithTokenMasked.js new file mode 100644 index 00000000..a38a2b5c --- /dev/null +++ b/packages/shipjs-lib/src/lib/git/getRepoURLWithTokenMasked.js @@ -0,0 +1,8 @@ +import getRemoteOriginUrl from './getRemoteOriginUrl'; +import gh from 'parse-github-url'; + +export default function getRepoURLWithTokenMasked(remote, dir) { + const url = getRemoteOriginUrl(remote, dir); + const { repo } = gh(url); + return `https://xxx@github.com/${repo}`; +} diff --git a/packages/shipjs/src/step/prepare/push.js b/packages/shipjs/src/step/prepare/push.js index e3599828..b3c24d2d 100644 --- a/packages/shipjs/src/step/prepare/push.js +++ b/packages/shipjs/src/step/prepare/push.js @@ -1,14 +1,21 @@ -import { getRepoURLWithToken } from 'shipjs-lib'; +import { getRepoURLWithToken, getRepoURLWithTokenMasked } from 'shipjs-lib'; import runStep from '../runStep'; export default ({ config, currentBranch, dir, dryRun }) => - runStep({ title: 'Pushing to remote.' }, ({ run }) => { + runStep({ title: 'Pushing to remote.' }, ({ run, print }) => { const { remote } = config; const token = process.env.GITHUB_TOKEN; if (token) { const url = getRepoURLWithToken(token, remote, dir); - run({ command: `git remote add origin-with-token ${url}`, dir, dryRun }); + const maskedUrl = getRepoURLWithTokenMasked(remote, dir); + print(` $ git remote add origin-with-token ${maskedUrl}`); + run({ + command: `git remote add origin-with-token ${url}`, + dir, + dryRun, + printCommand: false, + }); run({ command: `git push origin-with-token ${currentBranch}`, dir, diff --git a/packages/shipjs/src/step/release/gitPush.js b/packages/shipjs/src/step/release/gitPush.js index 24668399..87ac8af4 100644 --- a/packages/shipjs/src/step/release/gitPush.js +++ b/packages/shipjs/src/step/release/gitPush.js @@ -1,38 +1,55 @@ -import { getCurrentBranch, getRepoURLWithToken } from 'shipjs-lib'; +import { + getCurrentBranch, + getRepoURLWithToken, + getRepoURLWithTokenMasked, +} from 'shipjs-lib'; import runStep from '../runStep'; import getBranchNameToMergeBack from '../../helper/getBranchNameToMergeBack'; -function getPushCommands({ remote, tagName, dir }) { +function push({ remote, tagName, run, print, dir, dryRun }) { const token = process.env.GITHUB_TOKEN; if (token) { const url = getRepoURLWithToken(token, remote, dir); - return [ - `git remote add origin-with-token ${url}`, - `git push origin-with-token`, - `git push origin-with-token ${tagName}`, - ]; + const maskedUrl = getRepoURLWithTokenMasked(remote, dir); + print(` $ git remote add origin-with-token ${maskedUrl}`); + run({ + command: `git remote add origin-with-token ${url}`, + dir, + dryRun, + printCommand: false, + }); + run({ command: `git push origin-with-token`, dir, dryRun }); + run({ command: `git push origin-with-token ${tagName}`, dir, dryRun }); } else { - return [`git push && git push ${remote} ${tagName}`]; + run({ + command: `git push`, + dir, + dryRun, + }); + run({ + command: `git push ${remote} ${tagName}`, + dir, + dryRun, + }); } } export default ({ tagName, config, dir, dryRun }) => - runStep({ title: 'Pushing to the remote.' }, ({ run }) => { + runStep({ title: 'Pushing to the remote.' }, ({ run, print }) => { const currentBranch = getCurrentBranch(dir); const { mergeStrategy, remote } = config; const destinationBranch = getBranchNameToMergeBack({ currentBranch, mergeStrategy, }); - const pushCommands = getPushCommands({ remote, tagName, dir }); if (currentBranch === destinationBranch) { - pushCommands.forEach(command => run({ command, dir, dryRun })); + push({ remote, tagName, run, print, dir, dryRun }); } else { // currentBranch: 'master' // destinationBranch: 'develop' // flow: develop -> master -> (here) develop run({ command: `git checkout ${destinationBranch}`, dir, dryRun }); run({ command: `git merge ${currentBranch}`, dir, dryRun }); - pushCommands.forEach(command => run({ command, dir, dryRun })); + push({ remote, tagName, run, print, dir, dryRun }); } });