Refactor GitHub Integration (#6713)

* fix: refactor

* fix: tests

* fix: apply octokit plugin pattern
This commit is contained in:
Apoorv Mishra
2024-03-27 17:22:06 +05:30
committed by GitHub
parent 6703ea801f
commit bea36f87a6
7 changed files with 297 additions and 165 deletions

View File

@@ -5,8 +5,6 @@ import { integrationSettingsPath } from "@shared/utils/routeHelpers";
export class GitHubUtils {
public static clientId = env.GITHUB_CLIENT_ID;
public static allowedResources = ["pull", "issues"];
static get url() {
return integrationSettingsPath("github");
}
@@ -47,27 +45,6 @@ export class GitHubUtils {
return `${this.url}?install_request=true`;
}
/**
* Parses a GitHub like URL to obtain info like repo name, owner, resource type(issue or PR).
*
* @param url URL to parse
* @returns An object containing repository, owner, resource type(issue or pull request) and resource id
*/
public static parseUrl(url: string) {
const { hostname, pathname } = new URL(url);
if (hostname !== "github.com") {
return {};
}
const [, owner, repo, resourceType, resourceId] = pathname.split("/");
if (!this.allowedResources.includes(resourceType)) {
return {};
}
return { owner, repo, resourceType, resourceId };
}
public static getColorForStatus(status: string) {
switch (status) {
case "open":