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 } =
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) {

@ -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(

@ -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!');
});
});

@ -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 (
<Root>
{props.comments.map((comment) => (
<div key={comment.id}>
<UserName userId={comment.author} />: <div>{comment.content}</div>
<div key={comment.id} className="comment-item">
<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>
))}
</Root>

@ -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;

Loading…
Cancel
Save