Skip to content

Commit

Permalink
fix: do not print github token (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjae Lee authored Oct 10, 2019
1 parent 1c3b532 commit 82527cf
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
3 changes: 3 additions & 0 deletions packages/shipjs-lib/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 8 additions & 0 deletions packages/shipjs-lib/src/lib/git/getRepoURLWithTokenMasked.js
Original file line number Diff line number Diff line change
@@ -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}`;
}
13 changes: 10 additions & 3 deletions packages/shipjs/src/step/prepare/push.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
41 changes: 29 additions & 12 deletions packages/shipjs/src/step/release/gitPush.js
Original file line number Diff line number Diff line change
@@ -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 });
}
});

0 comments on commit 82527cf

Please sign in to comment.