Fetch the app name on startup

This commit is contained in:
Will Hunt 2021-12-01 17:31:12 +00:00
parent 4604268df1
commit 49ef4cf970
4 changed files with 11 additions and 6 deletions

View File

@ -6,7 +6,6 @@ import { configKey } from "./Decorators";
interface BridgeConfigGitHubYAML {
auth: {
name: string;
id: number|string;
privateKeyFile: string;
};
@ -29,7 +28,6 @@ interface BridgeConfigGitHubYAML {
export class BridgeConfigGitHub {
@configKey("Authentication for the GitHub App.", false)
auth: {
name: string;
id: number|string;
privateKeyFile: string;
};

View File

@ -36,7 +36,6 @@ export const DefaultConfig = new BridgeConfig({
},
github: {
auth: {
name: 'my-app-name',
id: 123,
privateKeyFile: "github-key.pem",
},

View File

@ -139,8 +139,6 @@ export class GitHubRepoConnection extends CommandConnection implements IConnecti
throw new ApiError("Could not determine if the user has access to this repository, does the repository exist?", ErrCode.ForbiddenUser);
}
octokit.apps.addRepoToInstallationForAuthenticatedUser()
if (permissionLevel !== "admin" && permissionLevel !== "write") {
throw new ApiError("You must at least have write permissions to bridge this repository", ErrCode.ForbiddenUser);
}
@ -152,7 +150,7 @@ export class GitHubRepoConnection extends CommandConnection implements IConnecti
-1,
{
// E.g. https://github.com/apps/matrix-bridge/installations/new
installUrl: `https://github.com/apps/${config.auth.name}/installations/new`,
installUrl: `https://github.com/apps/${githubInstance.appName}/installations/new`,
}
);
}

View File

@ -23,11 +23,16 @@ export class GithubInstance {
private internalOctokit!: Octokit;
private readonly installationsCache = new Map<number, Installation>();
private internalAppName?: string;
constructor (private readonly appId: number|string, private readonly privateKey: string) {
this.appId = parseInt(appId as string, 10);
}
public get appName() {
return this.internalAppName;
}
public static createUserOctokit(token: string) {
return new Octokit({
// XXX: A recent release of octokit (rest/auth-token?) broke passing in the token
@ -76,12 +81,17 @@ export class GithubInstance {
privateKey: this.privateKey,
};
this.internalOctokit = new Octokit({
authStrategy: createAppAuth,
auth,
userAgent: USER_AGENT,
});
const appDetails = await this.internalOctokit.apps.getAuthenticated();
this.internalAppName = appDetails.data.name;
let installPageSize = 100;
let page = 1;
do {