Skip to content

Commit 0ede928

Browse files
committed
Fix git repo matching by using the git-url-parse library in the Bitbucket, Gitea, GitHub, and GitLab API files.
1 parent 3308ebc commit 0ede928

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

src/git/bitbucket.ts

Lines changed: 4 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:bitbucket:api')
67

78
//const { Octokit } = require("@octokit/core");
@@ -40,9 +41,9 @@ export class BitbucketApi extends Repo {
4041
}
4142
}
4243

43-
// TODO : Improve matching here
44-
let owner = gitrepo.match(/^git@bitbucket.org:(.*)\/.*$/)?.[1] as string;
45-
let repo = gitrepo.match(/^git@bitbucket.org:.*\/(.*).git$/)?.[1] as string;
44+
let parsed = gitUrlParse(gitrepo)
45+
let repo = parsed.name
46+
let owner = parsed.owner
4647

4748
console.log(owner, repo);
4849
try {

src/git/gitea.ts

Lines changed: 4 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:gitea:api')
67

78
//https://www.npmjs.com/package/gitea-js
@@ -31,9 +32,9 @@ export class GiteaApi 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
3738

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

src/git/github.ts

Lines changed: 4 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:github:api')
67

78
//const { Octokit } = require("@octokit/core");
@@ -30,9 +31,9 @@ export class GithubApi extends Repo {
3031
}
3132
}
3233

33-
// TODO : Improve matching here or use default function in Superclass
34-
let owner = gitrepo.match(/^git@github.com:(.*)\/.*$/)?.[1] as string;
35-
let repo = gitrepo.match(/^git@github.com:.*\/(.*).git$/)?.[1] as string;
34+
let parsed = gitUrlParse(gitrepo)
35+
let repo = parsed.name
36+
let owner = parsed.owner
3637

3738
try {
3839
let res = await this.octokit.request('GET /repos/{owner}/{repo}', {

src/git/gitlab.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IWebhook, IRepository, IWebhookR, IDeploykeyR} from './types';
55
import { Repo } from './repo';
66
import {Client as GitlabClient} from '@nerdvision/gitlab-js';
77
import {Options} from 'got';
8+
import gitUrlParse = require("git-url-parse");
89

910

1011
export class GitlabApi extends Repo {
@@ -40,9 +41,9 @@ export class GitlabApi extends Repo {
4041
}
4142
}
4243

43-
// TODO : Improve matching here
44-
let owner = gitrepo.match(/^git@.*:(.*)\/.*$/)?.[1] as string;
45-
let repo = gitrepo.match(/^git@.*:.*\/(.*)\.git$/)?.[1] as string;
44+
let parsed = gitUrlParse(gitrepo)
45+
let repo = parsed.name
46+
let owner = parsed.owner
4647

4748
let res: any = await this.gitlab.get(`projects/${owner}%2F${repo}`)
4849
.catch((error: any) => {

0 commit comments

Comments
 (0)