From 6c2cb2558416fc5653384cbac8956ff62267d287 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 5 Nov 2022 16:28:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96github=20app=20issue?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=B8=8E=E5=9B=9E=E5=A4=8D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 并增加相关调试信息 --- apps/github-app/src/app.ts | 28 +++++++++++------ apps/github-app/src/client.ts | 6 ++-- apps/github-app/src/index.ts | 2 +- .../src/components/TopicComments.tsx | 30 ++++++++++++++++--- server/services/openapi/bot.service.ts | 8 +---- 5 files changed, 51 insertions(+), 23 deletions(-) diff --git a/apps/github-app/src/app.ts b/apps/github-app/src/app.ts index 55e23387..1e79b0c8 100644 --- a/apps/github-app/src/app.ts +++ b/apps/github-app/src/app.ts @@ -44,17 +44,19 @@ export function app(app: Probot) { const { tailchatClient, groupId, panelId } = createTailchatContextWithConfig(data.content); + console.log('配置信息', { tailchatClient, groupId, panelId }); + // 发送到tailchat - const topic = await tailchatClient.call( + const { data: topic } = await tailchatClient.call( 'plugin:com.msgbyte.topic.create', { groupId, panelId, - content: `${ctx.payload.issue.user.login} create Issue\n\ntitle: ${ - ctx.payload.issue.title - }\ncontent: ${ctx.payload.issue.body ?? ''}\n\nwebsite: ${ - ctx.payload.issue.html_url - }`, + content: `[b]${ + ctx.payload.issue.user.login + }[/b] create Issue:\n\nTitle: ${ctx.payload.issue.title}\nContent: ${ + ctx.payload.issue.body ?? '' + }\n\nWebsite: ${ctx.payload.issue.html_url}`, meta: { githubRepoOwner: ctx.payload.repository.owner, githubRepoName: ctx.payload.repository.name, @@ -63,6 +65,8 @@ export function app(app: Probot) { } ); + console.log('Tailchat Topic 创建成功', topic); + await Promise.all([ ctx.octokit.issues.createComment( ctx.issue({ @@ -77,6 +81,8 @@ export function app(app: Probot) { ), metadata(ctx).set(TOPIC_KEY, topic._id), ]); + + console.log('发送相关信息到 Github 完毕'); } catch (err) { console.error(err); @@ -90,6 +96,7 @@ export function app(app: Probot) { app.on('issue_comment.created', async (ctx) => { if (ctx.isBot) { + console.error('This comment created by Bot, Skip!'); return; } // 发送到tailchat @@ -97,6 +104,7 @@ export function app(app: Probot) { try { const topicId = await metadata(ctx).get(TOPIC_KEY); if (!topicId) { + console.error('Not found topic id, Skip!'); return; } @@ -107,7 +115,7 @@ export function app(app: Probot) { ); if (!(!Array.isArray(data) && 'content' in data)) { - throw new Error('config file type error'); + throw new Error('Config file type error'); } // 是配置文件 @@ -120,8 +128,10 @@ export function app(app: Probot) { groupId, panelId, topicId, - content: `${ctx.payload.comment.user.login} reply Issue\n\ncontent: ${ - ctx.payload.issue.body ?? '' + content: `[b]${ + ctx.payload.comment.user.login + }[/b] reply Issue:\n\nContent: ${ + ctx.payload.comment.body ?? '' }\n\nWebsite: ${ctx.payload.comment.html_url}`, }); } catch (err) { diff --git a/apps/github-app/src/client.ts b/apps/github-app/src/client.ts index 9bde59e8..f613fa61 100644 --- a/apps/github-app/src/client.ts +++ b/apps/github-app/src/client.ts @@ -49,7 +49,7 @@ export class TailchatClient { console.log('tailchat openapp login success!'); // 尝试调用函数 - console.log(await this.whoami()); + this.whoami().then(console.log); } catch (err) { console.error(err); throw err; @@ -58,7 +58,8 @@ export class TailchatClient { async call(action: string, params = {}) { try { - await Promise.resolve(this.loginP); // 等待loigin完毕. 用于serverless服务 + await Promise.resolve(this.loginP); + console.log('正在调用服务:', action); const { data } = await this.request.post( '/api/' + action.replace(/\./g, '/'), params @@ -66,6 +67,7 @@ export class TailchatClient { return data; } catch (err: any) { + console.error('服务调用失败'); const data: string = err?.response?.data; if (data) { throw new Error( diff --git a/apps/github-app/src/index.ts b/apps/github-app/src/index.ts index 3cfdfff8..6b816a95 100644 --- a/apps/github-app/src/index.ts +++ b/apps/github-app/src/index.ts @@ -2,7 +2,7 @@ import { run } from 'probot'; import { app } from './app'; run(app).then((server) => { - server.router('/').get('/', (req, res) => { + server.router('/').get('/', (_req, res) => { res.send('Hello World! Github app server is working!'); }); }); diff --git a/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/src/components/TopicComments.tsx b/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/src/components/TopicComments.tsx index 21ba0910..ee3d788e 100644 --- a/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/src/components/TopicComments.tsx +++ b/server/plugins/com.msgbyte.topic/web/plugins/com.msgbyte.topic/src/components/TopicComments.tsx @@ -1,4 +1,5 @@ -import { UserName } from '@capital/component'; +import { getMessageRender } from '@capital/common'; +import { UserAvatar, UserName } from '@capital/component'; import React from 'react'; import styled from 'styled-components'; import type { GroupTopicComment } from '../types'; @@ -13,8 +14,20 @@ const Root = styled.div` background-color: rgba(0, 0, 0, 0.25); } - > div { + .comment-item { display: flex; + margin-bottom: 10px; + + .left { + margin-right: 4px; + } + + .right { + .username { + font-weight: bold; + line-height: 24px; + } + } } `; @@ -27,8 +40,17 @@ export const TopicComments: React.FC<{ return ( {props.comments.map((comment) => ( -
- :
{comment.content}
+
+
+ +
+ +
+
+ +
+
{getMessageRender(comment.content)}
+
))} diff --git a/server/services/openapi/bot.service.ts b/server/services/openapi/bot.service.ts index 10fae1df..69321821 100644 --- a/server/services/openapi/bot.service.ts +++ b/server/services/openapi/bot.service.ts @@ -41,7 +41,7 @@ class OpenBotService extends TcService { }); if (!valid) { - throw new Error('auth failed.'); + throw new Error('Auth failed.'); } // 校验通过, 获取机器人账号存在 @@ -82,12 +82,6 @@ class OpenBotService extends TcService { const botId = 'open_' + appInfo._id; const nickname = appInfo.appName; const avatar = appInfo.appIcon; - console.log('da', { - botId, - nickname, - avatar, - appInfo, - }); const { _id: botUserId, email } = await ctx.call< { _id: string;