mirror of https://github.com/msgbyte/tailchat
feat: github app 错误处理与配置获取
parent
2ebaeacd61
commit
41af493228
@ -0,0 +1,82 @@
|
||||
import { Probot } from 'probot';
|
||||
|
||||
// const tailchatApiUrl = process.env.TAILCHAT_API_URL;
|
||||
const configPath = '.tailchat/topic.json';
|
||||
|
||||
export function app(app: Probot) {
|
||||
app.on('issues.opened', async (ctx) => {
|
||||
if (ctx.isBot) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { data } = await ctx.octokit.repos.getContent(
|
||||
ctx.repo({
|
||||
path: configPath,
|
||||
})
|
||||
);
|
||||
|
||||
try {
|
||||
if (!(!Array.isArray(data) && 'content' in data)) {
|
||||
throw new Error('config file type error');
|
||||
}
|
||||
|
||||
// 是配置文件
|
||||
|
||||
const content = Buffer.from(data.content, 'base64').toString();
|
||||
const json = await JSON.parse(content);
|
||||
const groupId = json['groupId'];
|
||||
const panelId = json['panelId'];
|
||||
|
||||
if (!groupId || !panelId) {
|
||||
throw new Error('config format error');
|
||||
}
|
||||
|
||||
console.log(json);
|
||||
|
||||
// TODO: 发送到tailchat
|
||||
|
||||
await Promise.all([
|
||||
ctx.octokit.issues.createComment(
|
||||
ctx.issue({
|
||||
body: 'Thanks for opening this issue! Tailchat topic is created!',
|
||||
})
|
||||
),
|
||||
ctx.octokit.issues.addLabels(
|
||||
ctx.repo({
|
||||
issue_number: ctx.payload.issue.number,
|
||||
labels: ['tailchat-topic'],
|
||||
})
|
||||
),
|
||||
]);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
await ctx.octokit.issues.createComment(
|
||||
ctx.issue({
|
||||
body: `Tailchat topic create error, please checkout your config in \`${configPath}\`!`,
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
app.on('issue_comment.created', async () => {
|
||||
// 发送到tailchat
|
||||
});
|
||||
|
||||
app.on('installation.created', async (ctx) => {
|
||||
const installationId = ctx.payload.installation.id;
|
||||
const installationTargetName = ctx.payload.installation.account.login;
|
||||
const installationTargetRepositories = ctx.payload.repositories;
|
||||
|
||||
console.log('installation.created', {
|
||||
installationId,
|
||||
installationTargetName,
|
||||
installationTargetRepositories,
|
||||
});
|
||||
});
|
||||
|
||||
// For more information on building apps:
|
||||
// https://probot.github.io/docs/
|
||||
|
||||
// To get your app running against GitHub, see:
|
||||
// https://probot.github.io/docs/development/
|
||||
}
|
@ -1,15 +1,4 @@
|
||||
import { Probot } from 'probot';
|
||||
import { run } from 'probot';
|
||||
import { app } from './app';
|
||||
|
||||
export = (app: Probot) => {
|
||||
app.on('issues.opened', async (context) => {
|
||||
const issueComment = context.issue({
|
||||
body: 'Thanks for opening this issue!',
|
||||
});
|
||||
await context.octokit.issues.createComment(issueComment);
|
||||
});
|
||||
// For more information on building apps:
|
||||
// https://probot.github.io/docs/
|
||||
|
||||
// To get your app running against GitHub, see:
|
||||
// https://probot.github.io/docs/development/
|
||||
};
|
||||
run(app);
|
||||
|
Loading…
Reference in New Issue