-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: push to git with GITHUB_TOKEN (#234)
* fix: push to git with GITHUB_TOKEN * fix: validate hub with token
- Loading branch information
Eunjae Lee
authored
Sep 6, 2019
1 parent
bd3d6c9
commit a39e7ee
Showing
12 changed files
with
61 additions
and
19 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import getRepoURL from './getRepoURL'; | ||
|
||
export default function getCommitUrl(hash, dir = '.') { | ||
const repoURL = getRepoURL(dir); | ||
export default function getCommitUrl(remote, hash, dir = '.') { | ||
const repoURL = getRepoURL(remote, dir); | ||
return `${repoURL}/commit/${hash}`; | ||
} |
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 silentExec from '../shell/silentExec'; | ||
|
||
export default function getRemoteOriginUrl(remote, dir) { | ||
const url = silentExec(`git remote get-url ${remote}`, { dir }) | ||
.toString() | ||
.trim(); | ||
return url; | ||
} |
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,10 +1,8 @@ | ||
import silentExec from '../shell/silentExec'; | ||
import getRemoteOriginUrl from './getRemoteOriginUrl'; | ||
import gh from 'parse-github-url'; | ||
|
||
export default function getRepoURL(dir) { | ||
const url = silentExec('git config --get remote.origin.url', { dir }) | ||
.toString() | ||
.trim(); | ||
export default function getRepoURL(remote, dir) { | ||
const url = getRemoteOriginUrl(remote, dir); | ||
const { repo } = gh(url); | ||
return `https://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
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 getRepoURLWithToken(token, remote, dir) { | ||
const url = getRemoteOriginUrl(remote, dir); | ||
const { repo } = gh(url); | ||
return `https://${token}@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
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
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,7 +1,16 @@ | ||
import { getRepoURLWithToken } from 'shipjs-lib'; // eslint-disable-line import/no-unresolved | ||
import runStep from '../runStep'; | ||
|
||
export default ({ config, currentBranch, dir, dryRun }) => | ||
runStep({ title: 'Pushing to remote.' }, ({ run }) => { | ||
const { remote } = config; | ||
run(`git push ${remote} ${currentBranch}`, dir, dryRun); | ||
|
||
const token = process.env.GITHUB_TOKEN; | ||
if (token) { | ||
const url = getRepoURLWithToken(token, remote, dir); | ||
run(`git remote add origin-with-token ${url}`, dir, dryRun); | ||
run(`git push origin-with-token ${currentBranch}`, dir, dryRun); | ||
} else { | ||
run(`git push ${remote} ${currentBranch}`, dir, dryRun); | ||
} | ||
}); |
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