diff --git a/src/github/app.ts b/src/github/app.ts index bd218d1..02b2676 100644 --- a/src/github/app.ts +++ b/src/github/app.ts @@ -6,7 +6,6 @@ import { PrivilegeEvent } from '@/constants'; import { ActionsRepo, VERSION_SYNC_KEYWORD } from '@/constants/opensumi'; import Environment from '@/env'; import { AppSetting } from '@/kv/types'; -import { GitHubService } from '@opensumi/octo-service'; import { CommandContext, issueCc } from './commands'; import { parseCommandInMarkdownComments } from './commands/parse'; @@ -15,16 +14,13 @@ import { setupWebhooksTemplate } from './handler'; import { OpenSumiOctoService } from './service/opensumi'; export class App { - ctx: { - setting: AppSetting; - }; - octoService: GitHubService; - opensumiOctoService: OpenSumiOctoService; + octoService: OpenSumiOctoService; octoApp: OctoApp<{ Octokit: typeof Octokit }>; - constructor(setting: AppSetting) { + constructor(public setting: AppSetting) { const { appSettings, githubSecret } = setting; + this.octoService = new OpenSumiOctoService(); this.octoApp = new OctoApp({ appId: appSettings.appId, @@ -34,12 +30,6 @@ export class App { }, Octokit: Octokit, }); - this.ctx = { - setting, - }; - - this.octoService = new GitHubService(); - this.opensumiOctoService = new OpenSumiOctoService(); this.octoApp.webhooks.on( 'issue_comment.created', @@ -60,12 +50,12 @@ export class App { case 'opensumi/core': file = ActionsRepo.SYNC_FILE; name = 'opensumi'; - await this.opensumiOctoService.syncOpenSumiVersion(version); + await this.octoService.syncOpenSumiVersion(version); break; case 'opensumi/codeblitz': file = ActionsRepo.SYNC_CODEBLITZ_FILE; name = 'codeblitz'; - await this.opensumiOctoService.syncCodeblitzVersion(version); + await this.octoService.syncCodeblitzVersion(version); break; default: throw new Error('unknown repo'); @@ -77,7 +67,7 @@ export class App { text: `[${fullname}] ${tag} has published. [starts synchronizing ${name} packages@${version} to npmmirror](https://github.com/opensumi/actions/actions/workflows/${file})`, }, PrivilegeEvent, - this.ctx.setting, + this.setting, ); }; @@ -179,17 +169,17 @@ export class App { } async init() { - const octo = await this.getOcto(); - this.octoService.octo = octo; - this.opensumiOctoService.octo = octo; + this.octoService.octo = await this.getOcto(); } listenWebhooks() { setupWebhooksTemplate( this.octoApp.webhooks, - this.ctx, + { + setting: this.setting, + }, async ({ markdown, eventName }) => { - await sendToDing(markdown, eventName, this.ctx.setting); + await sendToDing(markdown, eventName, this.setting); }, ); } diff --git a/src/github/commands/pullRequests/index.ts b/src/github/commands/pullRequests/index.ts index d259b6a..b75fe2e 100644 --- a/src/github/commands/pullRequests/index.ts +++ b/src/github/commands/pullRequests/index.ts @@ -113,7 +113,7 @@ export function registerPullRequestCommand(it: GitHubCommandCenter) { return; } - await app.opensumiOctoService.backportPr({ + await app.octoService.backportPr({ pull_number: issue.number, target_branch: targetBranch, }); @@ -143,8 +143,8 @@ Please see: <${getActionsUrl(ActionsRepo.BACKPORT_PR_WORKFLOW)}>`, ); if (!userHaveWritePerm) { if ( - app.ctx.setting.userWhoCanRelease && - app.ctx.setting.userWhoCanRelease.includes(user) + app.setting.userWhoCanRelease && + app.setting.userWhoCanRelease.includes(user) ) { userHaveWritePerm = true; } @@ -175,7 +175,7 @@ Please see: <${getActionsUrl(ActionsRepo.BACKPORT_PR_WORKFLOW)}>`, return; } - await app.opensumiOctoService.prNextRelease({ + await app.octoService.prNextRelease({ pull_number: issue.number, fullname, }); @@ -189,7 +189,7 @@ Please see: <${getActionsUrl(ActionsRepo.BACKPORT_PR_WORKFLOW)}>`, constraintRepo(fullname, updateLockfileAllowedRepo); await checkIsPullRequestAndUserHasPermission(ctx, 'write'); - await app.opensumiOctoService.updateLockfileForPr({ + await app.octoService.updateLockfileForPr({ pull_number: issue.number, }); await app.createReactionForIssueComment(ctx, 'rocket'); @@ -201,7 +201,7 @@ Please see: <${getActionsUrl(ActionsRepo.BACKPORT_PR_WORKFLOW)}>`, constraintRepo(fullname, updateLockfileAllowedRepo); await checkIsPullRequestAndUserHasPermission(ctx, 'admin'); - await app.opensumiOctoService.createMergeCommitForPr({ + await app.octoService.createMergeCommitForPr({ pull_number: issue.number, }); await app.createReactionForIssueComment(ctx, 'rocket'); diff --git a/src/im/commands/opensumi.ts b/src/im/commands/opensumi.ts index bb55fa7..9b9337f 100644 --- a/src/im/commands/opensumi.ts +++ b/src/im/commands/opensumi.ts @@ -51,7 +51,7 @@ export function registerOpenSumiCommand(it: IMCommandCenter) { try { text = '\n\n' + - (await app.opensumiOctoService.getLastNCommitsText({ + (await app.octoService.getLastNCommitsText({ owner: 'opensumi', repo: 'github-bot', })); @@ -61,8 +61,8 @@ export function registerOpenSumiCommand(it: IMCommandCenter) { ); } - await app.opensumiOctoService.deployBot(); - await app.opensumiOctoService.deployBotPre(); + await app.octoService.deployBot(); + await app.octoService.deployBotPre(); await bot.reply( convertToDingMarkdown( '开始部署机器人', @@ -86,7 +86,7 @@ export function registerOpenSumiCommand(it: IMCommandCenter) { try { text = '\n\n' + - (await app.opensumiOctoService.getLastNCommitsText({ + (await app.octoService.getLastNCommitsText({ owner: 'opensumi', repo: 'github-bot', })); @@ -96,7 +96,7 @@ export function registerOpenSumiCommand(it: IMCommandCenter) { ); } - await app.opensumiOctoService.deployBotPre(workflowRef); + await app.octoService.deployBotPre(workflowRef); await bot.reply( convertToDingMarkdown( '开始部署预发机器人', @@ -148,7 +148,7 @@ export function registerOpenSumiCommand(it: IMCommandCenter) { params.time = command.args.t || command.args.time; } - await app.opensumiOctoService.monthlyReport(params); + await app.octoService.monthlyReport(params); await bot.replyText('Starts generating monthly report.'); }, [], @@ -183,7 +183,7 @@ async function publishNextVersion( `找不到 ref: ${ref}, 错误信息: ${(error as Error).message}`, ); } - const text = await app.opensumiOctoService.getLastNCommitsText({ + const text = await app.octoService.getLastNCommitsText({ owner: 'opensumi', repo, ref, @@ -199,7 +199,7 @@ async function publishNextVersion( workflowInfo.ref = workflowRef; } - await app.opensumiOctoService.releaseNextVersion(workflowInfo, ref); + await app.octoService.releaseNextVersion(workflowInfo, ref); await bot.reply( convertToDingMarkdown( `Releasing a next version of ${name}`, @@ -241,7 +241,7 @@ async function syncVersion( workflow_id: ActionsRepo.SYNC_FILE, }); - await app.opensumiOctoService.syncOpenSumiVersion(version, workflowRef); + await app.octoService.syncOpenSumiVersion(version, workflowRef); await bot.reply( convertToDingMarkdown( 'Synchronizing OpenSumi packages', @@ -256,7 +256,7 @@ async function syncVersion( workflow_id: ActionsRepo.SYNC_CODEBLITZ_FILE, }); - await app.opensumiOctoService.syncCodeblitzVersion(version, workflowRef); + await app.octoService.syncCodeblitzVersion(version, workflowRef); await bot.reply( convertToDingMarkdown( 'Synchronizing CodeBlitz packages',