mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00
Fetch the app name on startup
This commit is contained in:
parent
4604268df1
commit
49ef4cf970
@ -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;
|
||||
};
|
||||
|
@ -36,7 +36,6 @@ export const DefaultConfig = new BridgeConfig({
|
||||
},
|
||||
github: {
|
||||
auth: {
|
||||
name: 'my-app-name',
|
||||
id: 123,
|
||||
privateKeyFile: "github-key.pem",
|
||||
},
|
||||
|
@ -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`,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user