mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Fix Github API URLs (#366)
* Fix Github API URLs * Add changelog entry * Fixes * Tidyup Co-authored-by: Will Hunt <will@half-shot.uk> Co-authored-by: Tadeusz Sośnierz <tadeusz@sosnierz.com>
This commit is contained in:
parent
21b6d79c3f
commit
5c899f045d
1
changelog.d/366.bugfix
Normal file
1
changelog.d/366.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Fix Github API URLs
|
@ -9,6 +9,7 @@ import { BridgeConfigActorPermission, BridgePermissions } from "../libRs";
|
||||
import LogWrapper from "../LogWrapper";
|
||||
import { ConfigError } from "../errors";
|
||||
import { ApiError, ErrCode } from "../api";
|
||||
import { GITHUB_CLOUD_URL } from "../Github/GithubInstance";
|
||||
|
||||
const log = new LogWrapper("Config");
|
||||
|
||||
@ -77,6 +78,7 @@ export class BridgeConfigGitHub {
|
||||
|
||||
@configKey("URL for enterprise deployments. Does not include /api/v3", true)
|
||||
private enterpriseUrl?: string;
|
||||
|
||||
@hideKey()
|
||||
public readonly baseUrl: URL;
|
||||
|
||||
@ -86,7 +88,7 @@ export class BridgeConfigGitHub {
|
||||
this.oauth = yaml.oauth;
|
||||
this.defaultOptions = yaml.defaultOptions;
|
||||
this.userIdPrefix = yaml.userIdPrefix || "_github_";
|
||||
this.baseUrl = new URL(yaml.enterpriseUrl ?? "https://github.com");
|
||||
this.baseUrl = yaml.enterpriseUrl ? new URL(yaml.enterpriseUrl) : GITHUB_CLOUD_URL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,8 @@ import UserAgent from "../UserAgent";
|
||||
|
||||
const log = new LogWrapper("GithubInstance");
|
||||
|
||||
export const GITHUB_CLOUD_URL = new URL("https://api.github.com");
|
||||
|
||||
interface Installation {
|
||||
account: {
|
||||
login?: string;
|
||||
@ -42,7 +44,9 @@ export class GithubInstance {
|
||||
public static baseOctokitConfig(baseUrl: URL) {
|
||||
return {
|
||||
userAgent: UserAgent,
|
||||
baseUrl: baseUrl && new URL("/api/v3", baseUrl).toString(),
|
||||
// Enterprise GitHub uses a /api/v3 basepath (https://github.com/octokit/octokit.js#constructor-options)
|
||||
// Cloud uses api.github.com
|
||||
baseUrl: baseUrl.hostname === GITHUB_CLOUD_URL.hostname ? baseUrl.toString() : new URL("/api/v3", baseUrl).toString(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,11 +159,11 @@ export class GithubInstance {
|
||||
}
|
||||
|
||||
public get newInstallationUrl() {
|
||||
if (this.baseUrl.hostname === "github.com") {
|
||||
if (this.baseUrl.hostname === GITHUB_CLOUD_URL.hostname) {
|
||||
// Cloud
|
||||
return new URL(`/apps/${this.appSlug}/installations/new`, this.baseUrl);
|
||||
}
|
||||
// Enterprise
|
||||
// Enterprise (yes, i know right)
|
||||
return new URL(`/github-apps/${this.appSlug}/installations/new`, this.baseUrl);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user