Skip to content

Commit 406f1e1

Browse files
authored
Merge pull request #26 from seebees/http-urls
fix: update local script remote support
2 parents 5814ba0 + aeaa64b commit 406f1e1

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

local.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ function deleteBranch(remote, branchName) {
6363

6464
function githubInfo(remote) {
6565
const gitHubSSH = "git@github.com:";
66+
const gitHubHTTPS = "https://github.com/";
6667
/* Expecting to match something like:
6768
* 'fork git@github.com:seebees/aws-codebuild-run-build.git (push)'
6869
* Which is the output of `git remote -v`
6970
*/
70-
const remoteMatch = /^fork.*\(push\)$/;
71+
const remoteMatch = new RegExp(`^${remote}.*\\(push\\)$`);
7172
/* Not doing a grep because then I have to pass user input to the shell.
7273
* This way I don't have to worry about sanitizing and injection and all that jazz.
7374
* Further, when I _do_ pass the remote into the shell to push to it,
@@ -81,7 +82,13 @@ function githubInfo(remote) {
8182
.filter(line => line.trim().match(remoteMatch));
8283
assert(gitRemote, `No remote found named ${remote}`);
8384
const [, url] = gitRemote.split(/[\t ]/);
84-
assert(url.startsWith(gitHubSSH), `Unsupported format: ${url}`);
85-
const [owner, repo] = url.slice(gitHubSSH.length, -4).split("/");
86-
return { owner, repo };
85+
if (url.startsWith(gitHubHTTPS)) {
86+
const [owner, repo] = url.slice(gitHubHTTPS.length, -4).split("/");
87+
return { owner, repo };
88+
} else if (url.startsWith(gitHubSSH)) {
89+
const [owner, repo] = url.slice(gitHubSSH.length, -4).split("/");
90+
return { owner, repo };
91+
} else {
92+
throw new Error(`Unsupported format: ${url}`);
93+
}
8794
}

0 commit comments

Comments
 (0)