Skip to content

Commit 537a63e

Browse files
authored
Merge pull request #192 from m1m1x/fix/gogs-git-url-parsing
fix(api/gogs): better git uri parsing
2 parents b17c00c + a181fb7 commit 537a63e

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"dotenv": "^16.0.1",
2929
"express": "^4.18.1",
3030
"express-session": "^1.17.3",
31+
"git-url-parse": "^13.1.0",
3132
"gitea-js": "^1.2.0",
3233
"kubernetes-client": "^9.0.0",
3334
"lodash.get": "^4.4.2",

src/git/gogs.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export class GogsApi extends Repo {
2020
}
2121

2222
protected async getRepository(gitrepo: string): Promise<IRepository> {
23+
const GitUrlParse = require("git-url-parse");
24+
2325
let ret: IRepository = {
2426
status: 500,
2527
statusText: 'error',
@@ -31,9 +33,18 @@ export class GogsApi extends Repo {
3133
}
3234
}
3335

34-
// TODO : Improve matching here
35-
let owner = gitrepo.match(/^git@.*:(.*)\/.*$/)?.[1] as string;
36-
let repo = gitrepo.match(/^git@.*:.*\/(.*)\.git$/)?.[1] as string;
36+
let parsed = GitUrlParse(gitrepo)
37+
let repo = parsed.name
38+
let owner = parsed.owner
39+
40+
if ( owner == undefined ){
41+
debug.log("git owner extraction failed");
42+
throw new Error("git owner extraction failed");
43+
}
44+
if ( repo == undefined ){
45+
debug.log("git owner extraction failed");
46+
throw new Error("git repo extraction failed");
47+
}
3748

3849
let res = await this.gitea.repos.repoGet(owner, repo)
3950
.catch((error: any) => {

yarn.lock

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,21 @@ getpass@^0.1.1:
23542354
dependencies:
23552355
assert-plus "^1.0.0"
23562356

2357+
git-up@^7.0.0:
2358+
version "7.0.0"
2359+
resolved "https://registry.yarnpkg.com/git-up/-/git-up-7.0.0.tgz#bace30786e36f56ea341b6f69adfd83286337467"
2360+
integrity sha512-ONdIrbBCFusq1Oy0sC71F5azx8bVkvtZtMJAsv+a6lz5YAmbNnLD6HAB4gptHZVLPR8S2/kVN6Gab7lryq5+lQ==
2361+
dependencies:
2362+
is-ssh "^1.4.0"
2363+
parse-url "^8.1.0"
2364+
2365+
git-url-parse@^13.1.0:
2366+
version "13.1.0"
2367+
resolved "https://registry.yarnpkg.com/git-url-parse/-/git-url-parse-13.1.0.tgz#07e136b5baa08d59fabdf0e33170de425adf07b4"
2368+
integrity sha512-5FvPJP/70WkIprlUZ33bm4UAaFdjcLkJLpWft1BeZKqwR0uhhNGoKwlUaPtVb4LxCSQ++erHapRak9kWGj+FCA==
2369+
dependencies:
2370+
git-up "^7.0.0"
2371+
23572372
gitea-js@^1.2.0:
23582373
version "1.20.1"
23592374
resolved "https://registry.yarnpkg.com/gitea-js/-/gitea-js-1.20.1.tgz#a382c8c56a869fedb11bc7889a5effea1bbbfede"
@@ -2614,6 +2629,13 @@ is-plain-object@^5.0.0:
26142629
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-5.0.0.tgz#4427f50ab3429e9025ea7d52e9043a9ef4159344"
26152630
integrity sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==
26162631

2632+
is-ssh@^1.4.0:
2633+
version "1.4.0"
2634+
resolved "https://registry.yarnpkg.com/is-ssh/-/is-ssh-1.4.0.tgz#4f8220601d2839d8fa624b3106f8e8884f01b8b2"
2635+
integrity sha512-x7+VxdxOdlV3CYpjvRLBv5Lo9OJerlYanjwFrPR9fuGPjCiNiCzFgAWpiLAohSbsnH4ZAys3SBh+hq5rJosxUQ==
2636+
dependencies:
2637+
protocols "^2.0.1"
2638+
26172639
is-stream@^2.0.0:
26182640
version "2.0.1"
26192641
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077"
@@ -3586,6 +3608,20 @@ parse-json@^5.2.0:
35863608
json-parse-even-better-errors "^2.3.0"
35873609
lines-and-columns "^1.1.6"
35883610

3611+
parse-path@^7.0.0:
3612+
version "7.0.0"
3613+
resolved "https://registry.yarnpkg.com/parse-path/-/parse-path-7.0.0.tgz#605a2d58d0a749c8594405d8cc3a2bf76d16099b"
3614+
integrity sha512-Euf9GG8WT9CdqwuWJGdf3RkUcTBArppHABkO7Lm8IzRQp0e2r/kkFnmhu4TSK30Wcu5rVAZLmfPKSBBi9tWFog==
3615+
dependencies:
3616+
protocols "^2.0.0"
3617+
3618+
parse-url@^8.1.0:
3619+
version "8.1.0"
3620+
resolved "https://registry.yarnpkg.com/parse-url/-/parse-url-8.1.0.tgz#972e0827ed4b57fc85f0ea6b0d839f0d8a57a57d"
3621+
integrity sha512-xDvOoLU5XRrcOZvnI6b8zA6n9O9ejNk/GExuz1yBuWUGn9KA97GI6HTs6u02wKara1CeVmZhH+0TZFdWScR89w==
3622+
dependencies:
3623+
parse-path "^7.0.0"
3624+
35893625
parseurl@~1.3.3:
35903626
version "1.3.3"
35913627
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4"
@@ -3715,6 +3751,11 @@ prompts@^2.0.1:
37153751
kleur "^3.0.3"
37163752
sisteransi "^1.0.5"
37173753

3754+
protocols@^2.0.0, protocols@^2.0.1:
3755+
version "2.0.1"
3756+
resolved "https://registry.yarnpkg.com/protocols/-/protocols-2.0.1.tgz#8f155da3fc0f32644e83c5782c8e8212ccf70a86"
3757+
integrity sha512-/XJ368cyBJ7fzLMwLKv1e4vLxOju2MNAIokcr7meSaNcVbWz/CPcW22cP04mwxOErdA5mwjA8Q6w/cdAQxVn7Q==
3758+
37183759
proxy-addr@~2.0.7:
37193760
version "2.0.7"
37203761
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.7.tgz#f19fe69ceab311eeb94b42e70e8c2070f9ba1025"

0 commit comments

Comments
 (0)