From 8c8e905dbe67eb4fae817f80991bf179ec0a49c3 Mon Sep 17 00:00:00 2001 From: ChrisFichman Date: Wed, 2 Apr 2025 14:59:25 -0400 Subject: [PATCH 1/3] Updated githubInfo function to work for non github.com urls The original code has github.com hardcoded. This does not work for github enterprise servers where the hostname is different. Also had to fix the owner/repo extraction to account for extra slashes in a remote host with weird pathing, and to check for the ":" which is required in an SSH url. --- local.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/local.js b/local.js index 6d7d6c2..8857c8a 100644 --- a/local.js +++ b/local.js @@ -7,6 +7,7 @@ const cp = require("child_process"); const cb = require("./code-build"); const assert = require("assert"); const yargs = require("yargs"); +const { log } = require("console"); const { projectName, @@ -117,10 +118,10 @@ function deleteBranch(remote, branchName) { } function githubInfo(remote) { - const gitHubSSH = "git@github.com:"; - const gitHubHTTPS = "https://github.com/"; + const repoSSH = "git@"; + const repoHTTPS = "https://"; /* Expecting to match something like: - * 'fork git@github.com:seebees/aws-codebuild-run-build.git (push)' + * 'fork git@:seebees/aws-codebuild-run-build.git (push)' * Which is the output of `git remote -v` */ const remoteMatch = new RegExp(`^${remote}.*\\(push\\)$`); @@ -137,11 +138,13 @@ function githubInfo(remote) { .filter((line) => line.trim().match(remoteMatch)); assert(gitRemote, `No remote found named ${remote}`); const [, url] = gitRemote.split(/[\t ]/); - if (url.startsWith(gitHubHTTPS)) { - const [owner, repo] = url.slice(gitHubHTTPS.length, -4).split("/"); + if (url.startsWith(repoHTTPS)) { + const [owner, repo] = url.slice(repoHTTPS.length, -4).split("/").slice(-2); + console.log(`owner: ${owner}, repo: ${repo}`); return { owner, repo }; - } else if (url.startsWith(gitHubSSH)) { - const [owner, repo] = url.slice(gitHubSSH.length, -4).split("/"); + } else if (url.startsWith(repoSSH)) { + const [owner, repo] = url.slice(repoSSH.length, -4).split(':').pop().split("/"); + console.log(`owner: ${owner}, repo: ${repo}`); return { owner, repo }; } else { throw new Error(`Unsupported format: ${url}`); From d2ded8280cd62e3ed7283cae8789729cd2625044 Mon Sep 17 00:00:00 2001 From: ChrisFichman Date: Wed, 2 Apr 2025 15:18:48 -0400 Subject: [PATCH 2/3] Pre-PR cleanup and more detailed errors --- local.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/local.js b/local.js index 8857c8a..0bf33b7 100644 --- a/local.js +++ b/local.js @@ -138,15 +138,21 @@ function githubInfo(remote) { .filter((line) => line.trim().match(remoteMatch)); assert(gitRemote, `No remote found named ${remote}`); const [, url] = gitRemote.split(/[\t ]/); + const url_path_elements = []; + if (url.startsWith(repoHTTPS)) { - const [owner, repo] = url.slice(repoHTTPS.length, -4).split("/").slice(-2); - console.log(`owner: ${owner}, repo: ${repo}`); - return { owner, repo }; + url_path_elements.push(...url.slice(repoHTTPS.length, -4).split("/")); } else if (url.startsWith(repoSSH)) { - const [owner, repo] = url.slice(repoSSH.length, -4).split(':').pop().split("/"); - console.log(`owner: ${owner}, repo: ${repo}`); - return { owner, repo }; + url_path_elements.push(...url.slice(repoSSH.length, -4).split(':').pop().split("/")); } else { - throw new Error(`Unsupported format: ${url}`); + throw new Error(`Unsupported format - not a valid HTTPS or SSH URL: ${url}`); } + + if (url_path_elements.length < 2) { + throw new Error(`Unsupported format - could not find owner and repo in path: ${url}`); + } + + // The last two elements of any valid git remote URL path should be the owner and repo. + const {owner, repo} = url_path_elements.slice(-2); + return { owner, repo }; } From fe3ed3e9412ed9c84fef27e70bd14adde77d7891 Mon Sep 17 00:00:00 2001 From: ChrisFichman Date: Wed, 2 Apr 2025 15:36:52 -0400 Subject: [PATCH 3/3] Removed unused console require --- local.js | 1 - 1 file changed, 1 deletion(-) diff --git a/local.js b/local.js index 0bf33b7..047ebff 100644 --- a/local.js +++ b/local.js @@ -7,7 +7,6 @@ const cp = require("child_process"); const cb = require("./code-build"); const assert = require("assert"); const yargs = require("yargs"); -const { log } = require("console"); const { projectName,