Skip to content

Commit 8f76be4

Browse files
committed
Update package.json with the new devDependency "@types/git-url-parse" version "^9.0.1", and import the module "git-url-parse" in gogs.ts to improve git owner and repo extraction from the gitrepo string.
1 parent b17c00c commit 8f76be4

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"yaml": "^2.1.1"
4747
},
4848
"devDependencies": {
49+
"@types/git-url-parse": "^9.0.1",
4950
"@types/connect-history-api-fallback": "^1.3.5",
5051
"@types/cookie-session": "^2.0.44",
5152
"@types/cors": "^2.8.12",

src/git/gogs.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import debug from 'debug';
22
import * as crypto from "crypto"
33
import { IWebhook, IRepository, IWebhookR, IDeploykeyR} from './types';
44
import { Repo } from './repo';
5+
import gitUrlParse = require("git-url-parse");
56
debug('app:kubero:gogs:api')
67

78
//https://www.npmjs.com/package/gitea-js
@@ -31,9 +32,18 @@ export class GogsApi extends Repo {
3132
}
3233
}
3334

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

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

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,11 @@
946946
"@types/qs" "*"
947947
"@types/serve-static" "*"
948948

949+
"@types/git-url-parse@^9.0.1":
950+
version "9.0.1"
951+
resolved "https://registry.yarnpkg.com/@types/git-url-parse/-/git-url-parse-9.0.1.tgz#1c7cc89527ca8b5afcf260ead3b0e4e373c43938"
952+
integrity sha512-Zf9mY4Mz7N3Nyi341nUkOtgVUQn4j6NS4ndqEha/lOgEbTkHzpD7wZuRagYKzrXNtvawWfsrojoC1nhsQexvNA==
953+
949954
"@types/got@^9.6.9":
950955
version "9.6.12"
951956
resolved "https://registry.yarnpkg.com/@types/got/-/got-9.6.12.tgz#fd42a6e1f5f64cd6bb422279b08c30bb5a15a56f"

0 commit comments

Comments
 (0)