Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add option to run not to print command (#321) #322

Merged
merged 2 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 });
}
});