diff --git a/apps/github-app/src/app.ts b/apps/github-app/src/app.ts index d268b32d..0d789d08 100644 --- a/apps/github-app/src/app.ts +++ b/apps/github-app/src/app.ts @@ -21,6 +21,8 @@ if ( const defaultTailchatApiUrl = process.env.TAILCHAT_API_URL; const tailchatAppId = process.env.TAILCHAT_APP_ID; const tailchatAppSecret = process.env.TAILCHAT_APP_SECRET; +const tailchatWebUrl = + process.env.TAILCHAT_WEB_URL || process.env.TAILCHAT_API_URL; export function app(app: Probot) { app.on('issues.opened', async (ctx) => { @@ -70,7 +72,7 @@ export function app(app: Probot) { await Promise.all([ ctx.octokit.issues.createComment( ctx.issue({ - body: 'Thanks for opening this issue! Tailchat topic is created!', + body: `Thanks for opening this issue! Tailchat topic is created in ${tailchatWebUrl}/main/group/${groupId}/${panelId}!`, }) ), ctx.octokit.issues.addLabels( @@ -160,6 +162,8 @@ export function app(app: Probot) { /** * 从配置文件中创建上下文 + * + * 因为考虑serverless服务因此不能全局管理 */ function createTailchatContextWithConfig(githubRaw: string) { const content = Buffer.from(githubRaw, 'base64').toString(); diff --git a/apps/github-app/src/client.ts b/apps/github-app/src/client.ts index f613fa61..638d7010 100644 --- a/apps/github-app/src/client.ts +++ b/apps/github-app/src/client.ts @@ -4,6 +4,7 @@ import crypto from 'crypto'; export class TailchatClient { request: AxiosInstance; jwt: string | null = null; + userId: string | null = null; loginP: Promise; constructor( @@ -37,6 +38,7 @@ export class TailchatClient { async login() { try { + console.log('正在登录...'); const { data } = await this.request.post('/api/openapi/bot/login', { appId: this.appId, token: this.getBotToken(), @@ -52,7 +54,7 @@ export class TailchatClient { this.whoami().then(console.log); } catch (err) { console.error(err); - throw err; + throw new Error('登录失败, 请检查应用凭证'); } } @@ -67,7 +69,7 @@ export class TailchatClient { return data; } catch (err: any) { - console.error('服务调用失败'); + console.error('服务调用失败:', err); const data: string = err?.response?.data; if (data) { throw new Error( diff --git a/server/lib/utils.ts b/server/lib/utils.ts index 3fef5530..cd334fea 100644 --- a/server/lib/utils.ts +++ b/server/lib/utils.ts @@ -64,5 +64,9 @@ export function sleep(ms: number): Promise { * 检查url地址是否匹配 */ export function checkPathMatch(urlList: string[], url: string): boolean { - return urlList.includes(url.split('?')[0]); + const fuzzList = urlList.map((url) => url.replaceAll('/', '.')); + const fuzzUrl = url.split('?')[0].replaceAll('/', '.'); + + // 考虑到serviceName中间可能会有. 且注册的时候不可能把所有情况都列出来,因此进行模糊处理 + return fuzzList.includes(fuzzUrl); } diff --git a/server/services/openapi/bot.service.ts b/server/services/openapi/bot.service.ts index 36f40275..e4e2ff40 100644 --- a/server/services/openapi/bot.service.ts +++ b/server/services/openapi/bot.service.ts @@ -24,7 +24,7 @@ class OpenBotService extends TcService { visibility: 'public', }); - this.registerAuthWhitelist(['/bot/login']); + this.registerAuthWhitelist(['/login']); } /** @@ -59,7 +59,7 @@ class OpenBotService extends TcService { avatar, }); - return { jwt }; + return { jwt, userId, email, nickname, avatar }; } /**