Refactor GitHub Integration (#6713)
* fix: refactor * fix: tests * fix: apply octokit plugin pattern
This commit is contained in:
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user