(app, { getRouter })
| 32 | process.env.TAILCHAT_WEB_URL || process.env.TAILCHAT_API_URL; |
| 33 | |
| 34 | export const appFn: ApplicationFunction = (app, { getRouter }) => { |
| 35 | app.on('issues.opened', async (ctx) => { |
| 36 | if (ctx.isBot) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | try { |
| 41 | const { data } = await ctx.octokit.repos.getContent( |
| 42 | ctx.repo({ |
| 43 | path: configPath, |
| 44 | }) |
| 45 | ); |
| 46 | |
| 47 | if (!(!Array.isArray(data) && 'content' in data)) { |
| 48 | throw new Error('config file type error'); |
| 49 | } |
| 50 | |
| 51 | // 是配置文件 |
| 52 | |
| 53 | const { tailchatClient, groupId, panelId } = |
| 54 | createTailchatContextWithConfig(data.content); |
| 55 | |
| 56 | console.log('配置信息', { tailchatClient, groupId, panelId }); |
| 57 | |
| 58 | // 发送到tailchat |
| 59 | const { data: topic } = await tailchatClient.call( |
| 60 | 'plugin:com.msgbyte.topic.create', |
| 61 | { |
| 62 | groupId, |
| 63 | panelId, |
| 64 | content: generateTopicCreateContent( |
| 65 | ctx.payload.issue.user.login, |
| 66 | ctx.payload.issue.title, |
| 67 | ctx.payload.issue.body ?? '', |
| 68 | ctx.payload.issue.html_url |
| 69 | ), |
| 70 | meta: { |
| 71 | tailchatHost: tailchatClient.url, |
| 72 | installationId: ctx.payload.installation?.id, |
| 73 | githubRepoOwner: ctx.payload.repository.owner.login, |
| 74 | githubRepoName: ctx.payload.repository.name, |
| 75 | githubIssueNumber: ctx.payload.issue.number, |
| 76 | }, |
| 77 | } |
| 78 | ); |
| 79 | |
| 80 | console.log('Tailchat Topic 创建成功', topic); |
| 81 | |
| 82 | await Promise.all([ |
| 83 | ctx.octokit.issues.createComment( |
| 84 | ctx.issue({ |
| 85 | body: `Thanks for opening this issue! Tailchat topic is created in ${tailchatWebUrl}/main/group/${groupId}/${panelId}!`, |
| 86 | }) |
| 87 | ), |
| 88 | ctx.octokit.issues.addLabels( |
| 89 | ctx.repo({ |
| 90 | issue_number: ctx.payload.issue.number, |
| 91 | labels: [LABEL], |
nothing calls this directly
no test coverage detected