From 61bae5d1cb9a5be80392c2f0a3a523f8a2e72acf Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 3 Dec 2021 14:49:31 -0700 Subject: [PATCH] Update auth URL handling --- .../DimensionHookshotGithubService.ts | 13 ++++++++---- src/bridges/HookshotGithubBridge.ts | 12 ++++++++--- src/bridges/models/hookshot.ts | 5 +++++ .../hookshot-github.bridge.component.html | 10 ++++++++- .../hookshot-github.bridge.component.ts | 21 ++++++++++++++++--- .../hookshot-jira.bridge.component.ts | 1 + web/app/shared/models/hookshot_github.ts | 5 +++++ .../hookshot-github-api.service.ts | 11 +++++++--- 8 files changed, 64 insertions(+), 14 deletions(-) diff --git a/src/api/dimension/DimensionHookshotGithubService.ts b/src/api/dimension/DimensionHookshotGithubService.ts index 18f84be..eddf94c 100644 --- a/src/api/dimension/DimensionHookshotGithubService.ts +++ b/src/api/dimension/DimensionHookshotGithubService.ts @@ -2,7 +2,12 @@ import { Context, DELETE, GET, Path, PathParam, POST, Security, ServiceContext } import { ApiError } from "../ApiError"; import { LogService } from "matrix-bot-sdk"; import { ROLE_USER } from "../security/MatrixSecurity"; -import { HookshotGithubOrg, HookshotGithubRepo, HookshotGithubRoomConfig } from "../../bridges/models/hookshot"; +import { + HookshotGithubAuthUrls, + HookshotGithubOrg, + HookshotGithubRepo, + HookshotGithubRoomConfig +} from "../../bridges/models/hookshot"; import { HookshotGithubBridge } from "../../bridges/HookshotGithubBridge"; interface BridgeRoomRequest { @@ -22,13 +27,13 @@ export class DimensionHookshotGithubService { @GET @Path("auth") @Security(ROLE_USER) - public async getAuthUrl(): Promise<{ authUrl: string }> { + public async getAuthUrl(): Promise { const userId = this.context.request.user.userId; try { const hookshot = new HookshotGithubBridge(userId); - const authUrl = await hookshot.getAuthUrl(); - return {authUrl}; + const authUrls = await hookshot.getAuthUrls(); + return authUrls; } catch (e) { LogService.error("DimensionHookshotGithubService", e); throw new ApiError(400, "Error getting auth info"); diff --git a/src/bridges/HookshotGithubBridge.ts b/src/bridges/HookshotGithubBridge.ts index 244164b..2c159e9 100644 --- a/src/bridges/HookshotGithubBridge.ts +++ b/src/bridges/HookshotGithubBridge.ts @@ -1,5 +1,11 @@ import HookshotGithubBridgeRecord from "../db/models/HookshotGithubBridgeRecord"; -import { HookshotGithubRepo, HookshotGithubRoomConfig, HookshotGithubUserInfo, HookshotTypes } from "./models/hookshot"; +import { + HookshotGithubAuthUrls, + HookshotGithubRepo, + HookshotGithubRoomConfig, + HookshotGithubUserInfo, + HookshotTypes +} from "./models/hookshot"; import { HookshotBridge } from "./HookshotBridge"; export class HookshotGithubBridge extends HookshotBridge { @@ -16,9 +22,9 @@ export class HookshotGithubBridge extends HookshotBridge { return bridges[0]; } - public async getAuthUrl(): Promise { + public async getAuthUrls(): Promise { const bridge = await this.getDefaultBridge(); - return this.doProvisionRequest(bridge, "GET", `/v1/github/oauth`).then(r => r['url']); + return this.doProvisionRequest(bridge, "GET", `/v1/github/oauth`).then(r => ({userUrl: r['user_url'], orgUrl: r['org_url']})); } public async getBotUserId(): Promise { diff --git a/src/bridges/models/hookshot.ts b/src/bridges/models/hookshot.ts index 55ebcbe..6aeae2d 100644 --- a/src/bridges/models/hookshot.ts +++ b/src/bridges/models/hookshot.ts @@ -49,6 +49,11 @@ export interface HookshotGithubUserInfo { organisations?: HookshotGithubOrg[]; } +export interface HookshotGithubAuthUrls { + userUrl: string; + orgUrl: string; +} + export enum SupportedGithubRepoEventType { IssueCreated = "issue.created", IssueChanged = "issue.changed", diff --git a/web/app/configs/bridge/hookshot-github/hookshot-github.bridge.component.html b/web/app/configs/bridge/hookshot-github/hookshot-github.bridge.component.html index d61f010..7282e96 100644 --- a/web/app/configs/bridge/hookshot-github/hookshot-github.bridge.component.html +++ b/web/app/configs/bridge/hookshot-github/hookshot-github.bridge.component.html @@ -22,7 +22,15 @@ {{'Sign in with GitHub' | translate}} -
+
+

+ {{'Almost there! Just need to add the bot to your organizations now.' | translate}} +

+ + {{'Add to GitHub' | translate}} + +
+