-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not print github token (#322)
- Loading branch information
Eunjae Lee
authored
Oct 10, 2019
1 parent
1c3b532
commit 82527cf
Showing
4 changed files
with
50 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
}); |