mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-06-28 21:53:47 +00:00
feat: integrate tool with gitlab service (#39)
* feat: integrate tool with gitlab service Fix https://github.com/lampajr/backporting/issues/30
This commit is contained in:
parent
8a007941d1
commit
107f5e52d6
35 changed files with 17821 additions and 1553 deletions
39
src/service/git/git-util.ts
Normal file
39
src/service/git/git-util.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { GitClientType } from "@bp/service/git/git.types";
|
||||
|
||||
const PUBLIC_GITHUB_URL = "https://github.com";
|
||||
const PUBLIC_GITHUB_API = "https://api.github.com";
|
||||
|
||||
/**
|
||||
* Infer the remote GIT service to interact with based on the provided
|
||||
* pull request URL
|
||||
* @param prUrl provided pull request URL
|
||||
* @returns {GitClientType}
|
||||
*/
|
||||
export const inferGitClient = (prUrl: string): GitClientType => {
|
||||
const stdPrUrl = prUrl.toLowerCase().trim();
|
||||
|
||||
if (stdPrUrl.includes(GitClientType.GITHUB.toString())) {
|
||||
return GitClientType.GITHUB;
|
||||
} else if (stdPrUrl.includes(GitClientType.GITLAB.toString())) {
|
||||
return GitClientType.GITLAB;
|
||||
}
|
||||
|
||||
throw new Error(`Remote git service not recognized from pr url: ${prUrl}`);
|
||||
};
|
||||
|
||||
/**
|
||||
* Infer the host git service from the pull request url
|
||||
* @param prUrl pull/merge request url
|
||||
* @param apiVersion the api version, ignored in case of public github
|
||||
* @returns api URL like https://api.github.com or https://gitlab.com/api/v4
|
||||
*/
|
||||
export const inferGitApiUrl = (prUrl: string, apiVersion = "v4"): string => {
|
||||
const url = new URL(prUrl);
|
||||
const baseUrl = `${url.protocol}//${url.host}`;
|
||||
|
||||
if (baseUrl.includes(PUBLIC_GITHUB_URL)) {
|
||||
return PUBLIC_GITHUB_API;
|
||||
}
|
||||
|
||||
return `${baseUrl}/api/${apiVersion}`;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue