Skip to content

fix: update local script remote support #26

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

Merged
merged 2 commits into from
Feb 27, 2020
Merged
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
15 changes: 11 additions & 4 deletions local.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ function deleteBranch(remote, branchName) {

function githubInfo(remote) {
const gitHubSSH = "[email protected]:";
const gitHubHTTPS = "https://github.com/";
/* Expecting to match something like:
* 'fork [email protected]:seebees/aws-codebuild-run-build.git (push)'
* Which is the output of `git remote -v`
*/
const remoteMatch = /^fork.*\(push\)$/;
const remoteMatch = new RegExp(`^${remote}.*\\(push\\)$`);
/* Not doing a grep because then I have to pass user input to the shell.
* This way I don't have to worry about sanitizing and injection and all that jazz.
* Further, when I _do_ pass the remote into the shell to push to it,
Expand All @@ -81,7 +82,13 @@ function githubInfo(remote) {
.filter(line => line.trim().match(remoteMatch));
assert(gitRemote, `No remote found named ${remote}`);
const [, url] = gitRemote.split(/[\t ]/);
assert(url.startsWith(gitHubSSH), `Unsupported format: ${url}`);
const [owner, repo] = url.slice(gitHubSSH.length, -4).split("/");
return { owner, repo };
if (url.startsWith(gitHubHTTPS)) {
const [owner, repo] = url.slice(gitHubHTTPS.length, -4).split("/");
return { owner, repo };
} else if (url.startsWith(gitHubSSH)) {
const [owner, repo] = url.slice(gitHubSSH.length, -4).split("/");
return { owner, repo };
} else {
throw new Error(`Unsupported format: ${url}`);
}
}