diff --git a/src/Config/Config.ts b/src/Config/Config.ts index 9e7f1e1a..b5400e31 100644 --- a/src/Config/Config.ts +++ b/src/Config/Config.ts @@ -4,15 +4,15 @@ import { IAppserviceRegistration } from "matrix-bot-sdk"; import * as assert from "assert"; import { configKey } from "./Decorators"; -export interface BridgeConfigGitHub { +interface BridgeConfigGitHubYAML { auth: { id: number|string; privateKeyFile: string; }; webhook: { secret: string; - }, - oauth: { + }; + oauth?: { // eslint-disable-next-line camelcase client_id: string; // eslint-disable-next-line camelcase @@ -20,6 +20,41 @@ export interface BridgeConfigGitHub { // eslint-disable-next-line camelcase redirect_uri: string; }; + defaultOptions?: { + showIssueRoomLink: false; + } +} + +export class BridgeConfigGitHub { + @configKey("Authentication for the GitHub App.", false) + auth: { + id: number|string; + privateKeyFile: string; + }; + @configKey("Webhook settings for the GitHub app.", false) + webhook: { + secret: string; + }; + @configKey("Settings for allowing users to sign in via OAuth.", true) + oauth?: { + // eslint-disable-next-line camelcase + client_id: string; + // eslint-disable-next-line camelcase + client_secret: string; + // eslint-disable-next-line camelcase + redirect_uri: string; + }; + @configKey("Default options for GitHub connections.", true) + defaultOptions?: { + showIssueRoomLink: false; + }; + + constructor(yaml: BridgeConfigGitHubYAML) { + this.auth = yaml.auth; + this.webhook = yaml.webhook; + this.oauth = yaml.oauth; + this.defaultOptions = yaml.defaultOptions; + } } export interface GitLabInstance { @@ -140,7 +175,7 @@ export class BridgeConfig { constructor(configData: BridgeConfigRoot, env: {[key: string]: string|undefined}) { this.bridge = configData.bridge; assert.ok(this.bridge); - this.github = configData.github; + this.github = configData.github && new BridgeConfigGitHub(configData.github); if (this.github?.auth && env["GITHUB_PRIVATE_KEY_FILE"]) { this.github.auth.privateKeyFile = env["GITHUB_PRIVATE_KEY_FILE"]; } diff --git a/src/Config/Defaults.ts b/src/Config/Defaults.ts index 6122faa9..f07f618a 100644 --- a/src/Config/Defaults.ts +++ b/src/Config/Defaults.ts @@ -47,6 +47,9 @@ export const DefaultConfig = new BridgeConfig({ webhook: { secret: "secrettoken", }, + defaultOptions: { + showIssueRoomLink: false, + } }, gitlab: { instances: { diff --git a/src/Connections/GithubRepo.ts b/src/Connections/GithubRepo.ts index aedfe085..b18ef799 100644 --- a/src/Connections/GithubRepo.ts +++ b/src/Connections/GithubRepo.ts @@ -17,6 +17,7 @@ import markdown from "markdown-it"; import { CommandConnection } from "./CommandConnection"; import { GithubInstance } from "../Github/GithubInstance"; import { GitHubIssueConnection } from "."; +import { BridgeConfigGitHub } from "../Config/Config"; const log = new LogWrapper("GitHubRepoConnection"); const md = new markdown(); @@ -154,7 +155,9 @@ export class GitHubRepoConnection extends CommandConnection implements IConnecti private state: GitHubRepoConnectionState, private readonly tokenStore: UserTokenStore, private readonly stateKey: string, - private readonly githubInstance: GithubInstance) { + private readonly githubInstance: GithubInstance, + private readonly config: BridgeConfigGitHub, + ) { super( roomId, as.botClient, @@ -169,7 +172,7 @@ export class GitHubRepoConnection extends CommandConnection implements IConnecti } private get showIssueRoomLink() { - return this.state.showIssueRoomLink === false ? false : true; + return this.state.showIssueRoomLink === undefined ? (this.config.defaultOptions?.showIssueRoomLink || false) : this.state.showIssueRoomLink; } public get repo() {