feat: 优化github app issue创建与回复逻辑

并增加相关调试信息
pull/56/head
moonrailgun 2 years ago
parent 79557a7399
commit 6c2cb25584

@ -44,17 +44,19 @@ export function app(app: Probot) {
const { tailchatClient, groupId, panelId } = const { tailchatClient, groupId, panelId } =
createTailchatContextWithConfig(data.content); createTailchatContextWithConfig(data.content);
console.log('配置信息', { tailchatClient, groupId, panelId });
// 发送到tailchat // 发送到tailchat
const topic = await tailchatClient.call( const { data: topic } = await tailchatClient.call(
'plugin:com.msgbyte.topic.create', 'plugin:com.msgbyte.topic.create',
{ {
groupId, groupId,
panelId, panelId,
content: `${ctx.payload.issue.user.login} create Issue\n\ntitle: ${ content: `[b]${
ctx.payload.issue.title ctx.payload.issue.user.login
}\ncontent: ${ctx.payload.issue.body ?? ''}\n\nwebsite: ${ }[/b] create Issue:\n\nTitle: ${ctx.payload.issue.title}\nContent: ${
ctx.payload.issue.html_url ctx.payload.issue.body ?? ''
}`, }\n\nWebsite: ${ctx.payload.issue.html_url}`,
meta: { meta: {
githubRepoOwner: ctx.payload.repository.owner, githubRepoOwner: ctx.payload.repository.owner,
githubRepoName: ctx.payload.repository.name, githubRepoName: ctx.payload.repository.name,
@ -63,6 +65,8 @@ export function app(app: Probot) {
} }
); );
console.log('Tailchat Topic 创建成功', topic);
await Promise.all([ await Promise.all([
ctx.octokit.issues.createComment( ctx.octokit.issues.createComment(
ctx.issue({ ctx.issue({
@ -77,6 +81,8 @@ export function app(app: Probot) {
), ),
metadata(ctx).set(TOPIC_KEY, topic._id), metadata(ctx).set(TOPIC_KEY, topic._id),
]); ]);
console.log('发送相关信息到 Github 完毕');
} catch (err) { } catch (err) {
console.error(err); console.error(err);
@ -90,6 +96,7 @@ export function app(app: Probot) {
app.on('issue_comment.created', async (ctx) => { app.on('issue_comment.created', async (ctx) => {
if (ctx.isBot) { if (ctx.isBot) {
console.error('This comment created by Bot, Skip!');
return; return;
} }
// 发送到tailchat // 发送到tailchat
@ -97,6 +104,7 @@ export function app(app: Probot) {
try { try {
const topicId = await metadata(ctx).get(TOPIC_KEY); const topicId = await metadata(ctx).get(TOPIC_KEY);
if (!topicId) { if (!topicId) {
console.error('Not found topic id, Skip!');
return; return;
} }
@ -107,7 +115,7 @@ export function app(app: Probot) {
); );
if (!(!Array.isArray(data) && 'content' in data)) { 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, groupId,
panelId, panelId,
topicId, topicId,
content: `${ctx.payload.comment.user.login} reply Issue\n\ncontent: ${ content: `[b]${
ctx.payload.issue.body ?? '' ctx.payload.comment.user.login
}[/b] reply Issue:\n\nContent: ${
ctx.payload.comment.body ?? ''
}\n\nWebsite: ${ctx.payload.comment.html_url}`, }\n\nWebsite: ${ctx.payload.comment.html_url}`,
}); });
} catch (err) { } catch (err) {

@ -49,7 +49,7 @@ export class TailchatClient {
console.log('tailchat openapp login success!'); console.log('tailchat openapp login success!');
// 尝试调用函数 // 尝试调用函数
console.log(await this.whoami()); this.whoami().then(console.log);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
throw err; throw err;
@ -58,7 +58,8 @@ export class TailchatClient {
async call(action: string, params = {}) { async call(action: string, params = {}) {
try { try {
await Promise.resolve(this.loginP); // 等待loigin完毕. 用于serverless服务 await Promise.resolve(this.loginP);
console.log('正在调用服务:', action);
const { data } = await this.request.post( const { data } = await this.request.post(
'/api/' + action.replace(/\./g, '/'), '/api/' + action.replace(/\./g, '/'),
params params
@ -66,6 +67,7 @@ export class TailchatClient {
return data; return data;
} catch (err: any) { } catch (err: any) {
console.error('服务调用失败');
const data: string = err?.response?.data; const data: string = err?.response?.data;
if (data) { if (data) {
throw new Error( throw new Error(

@ -2,7 +2,7 @@ import { run } from 'probot';
import { app } from './app'; import { app } from './app';
run(app).then((server) => { run(app).then((server) => {
server.router('/').get('/', (req, res) => { server.router('/').get('/', (_req, res) => {
res.send('Hello World! Github app server is working!'); res.send('Hello World! Github app server is working!');
}); });
}); });

@ -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 React from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import type { GroupTopicComment } from '../types'; import type { GroupTopicComment } from '../types';
@ -13,8 +14,20 @@ const Root = styled.div`
background-color: rgba(0, 0, 0, 0.25); background-color: rgba(0, 0, 0, 0.25);
} }
> div { .comment-item {
display: flex; 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 ( return (
<Root> <Root>
{props.comments.map((comment) => ( {props.comments.map((comment) => (
<div key={comment.id}> <div key={comment.id} className="comment-item">
<UserName userId={comment.author} />: <div>{comment.content}</div> <div className="left">
<UserAvatar userId={comment.author} size={24} />
</div>
<div className="right">
<div className="username">
<UserName userId={comment.author} />
</div>
<div>{getMessageRender(comment.content)}</div>
</div>
</div> </div>
))} ))}
</Root> </Root>

@ -41,7 +41,7 @@ class OpenBotService extends TcService {
}); });
if (!valid) { 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 botId = 'open_' + appInfo._id;
const nickname = appInfo.appName; const nickname = appInfo.appName;
const avatar = appInfo.appIcon; const avatar = appInfo.appIcon;
console.log('da', {
botId,
nickname,
avatar,
appInfo,
});
const { _id: botUserId, email } = await ctx.call< const { _id: botUserId, email } = await ctx.call<
{ {
_id: string; _id: string;

Loading…
Cancel
Save