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: check if origin-with-token already exists on prepare command #455

Merged
merged 1 commit into from
Nov 27, 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
1 change: 1 addition & 0 deletions packages/shipjs-lib/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { default as hasLocalBranch } from './lib/git/hasLocalBranch';
export { default as hasRemoteBranch } from './lib/git/hasRemoteBranch';
export { default as getCurrentBranch } from './lib/git/getCurrentBranch';
export { default as getLatestCommitMessage } from './lib/git/getLatestCommitMessage';
export { default as hasRemote } from './lib/git/hasRemote';
export { default as getRepoURL } from './lib/git/getRepoURL';
export { default as getRepoURLWithToken } from './lib/git/getRepoURLWithToken';
export { default as getRepoURLWithTokenMasked } from './lib/git/getRepoURLWithTokenMasked';
Expand Down
10 changes: 10 additions & 0 deletions packages/shipjs-lib/src/lib/git/hasRemote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import silentExec from '../shell/silentExec';

export default function hasRemote(remote, dir = '.') {
return (
silentExec(`git remote get-url ${remote}`, {
dir,
ignoreError: true,
}).code === 0
);
}
3 changes: 2 additions & 1 deletion packages/shipjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"chalk": "3.0.0",
"change-case": "3.1.0",
"conventional-changelog-cli": "2.0.28",
"dotenv": "^8.2.0",
"ejs": "^3.0.0",
"esm": "3.2.25",
"globby": "^10.0.1",
Expand All @@ -65,4 +66,4 @@
"jest": "24.9.0",
"jest-watch-typeahead": "0.4.2"
}
}
}
3 changes: 3 additions & 0 deletions packages/shipjs/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from 'path';
import dotenv from 'dotenv';
import setup from './flow/setup';
import prepare from './flow/prepare';
import release from './flow/release';
Expand Down Expand Up @@ -54,6 +56,7 @@ export async function cli(argv) {
const opts = removeDoubleDash(
parseArgs(argSpec, { permissive: false, argv })
);
dotenv.config({ path: path.resolve(opts.dir || '.', '.env') });
await fn(opts);
} catch (error) {
if (error.code === 'ARG_UNKNOWN_OPTION') {
Expand Down
26 changes: 16 additions & 10 deletions packages/shipjs/src/helper/gitPush.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { getRepoURLWithToken, getRepoURLWithTokenMasked } from 'shipjs-lib';
import {
getRepoURLWithToken,
getRepoURLWithTokenMasked,
hasRemote,
} from 'shipjs-lib';
import { print, run } from '../util';

export default function gitPush({ remote, refs, dir, dryRun }) {
const token = process.env.GITHUB_TOKEN;
if (token) {
const url = getRepoURLWithToken(token, remote, dir);
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,
});
if (!hasRemote('origin-with-token', dir)) {
const url = getRepoURLWithToken(token, remote, dir);
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,
});
}
refs.forEach(ref => {
run({ command: `git push origin-with-token ${ref}`, dir, dryRun });
});
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3418,6 +3418,11 @@ dotenv@^8.1.0:
resolved "https://registry.npmjs.org/dotenv/-/dotenv-8.1.0.tgz#d811e178652bfb8a1e593c6dd704ec7e90d85ea2"
integrity sha512-GUE3gqcDCaMltj2++g6bRQ5rBJWtkWTmqmD0fo1RnnMuUqHNCt2oTPeDnS9n6fKYvlhn7AeBkb38lymBtWBQdA==

dotenv@^8.2.0:
version "8.2.0"
resolved "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==

duplexer@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"
Expand Down