diff --git a/src/github.bot.ts b/src/github.bot.ts index 0b5c61f..44afa8f 100644 --- a/src/github.bot.ts +++ b/src/github.bot.ts @@ -2,7 +2,7 @@ import { EmitterWebhookEvent } from '@octokit/webhooks' import * as Sentry from '@sentry/browser' import { App } from 'octokit' import { plugins } from './plugins' -import { IssuePullPayload } from './types' +import { IssuePullPayload, ReleasePayload, WorkflowRunPayload } from './types' import { issuePull, release, workflowRun } from './utils/eventPayloads' import { initSentry } from './utils/sentry' import { verifyWebhookSignature } from './utils/verify' @@ -104,7 +104,10 @@ export class GitHubBot { console.log( `Processing "${eventName}.${payload.action}" with ${handler.name}`, ) - await handler(this, payload as IssuePullPayload) + await handler( + this, + payload as IssuePullPayload | ReleasePayload | WorkflowRunPayload, + ) } } diff --git a/src/handler.ts b/src/handler.ts index a37c0ee..4645557 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -5,9 +5,8 @@ import * as Sentry from '@sentry/browser' import integrationRepoIssueClosedPlugin from './plugins/integrationRepoIssueClosed' import integrationRepoPullClosedPlugin from './plugins/integrationRepoPullClosed' -import integrationReleaseCreatedPlugin from './plugins/integrationReleaseCreated' -import { issuePull, release } from './utils/eventPayloads' +import { issuePull } from './utils/eventPayloads' import { GitHubBot } from './github.bot' import { initSentry } from './utils/sentry' @@ -67,14 +66,12 @@ export async function handleRequest(request: Request): Promise { async function handleWebhookEvent(event: EmitterWebhookEvent): Promise { const app = await getApp() - const payload = issuePull(event) || release(event) + const payload = issuePull(event) if (!payload) return if ('pull_request' in payload) { await Promise.all([integrationRepoPullClosedPlugin(app, payload)]) } else if ('issue' in payload && payload.action === 'closed') { await Promise.all([integrationRepoIssueClosedPlugin(app, payload)]) - } else if ('release' in payload) { - await Promise.all([integrationReleaseCreatedPlugin(app, payload)]) } } diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 41686d6..f68a6ef 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -6,6 +6,7 @@ import IssuesOpenedGreeter from './issues.opened.greeter' import PullRequestClosedDefault from './pull_request.closed.default' import PullRequestLabeledNewDefaultRepository from './pull_request.labeled.new_default_repository' import PullRequestOpenedDefault from './pull_request.opened.default' +import ReleasePublishedIntegration from './release.published.integration' import WorkflowRunCompeted from './workflow_run.completed' // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -19,5 +20,6 @@ export const plugins: Record = { 'pull_request.labeled': [PullRequestLabeledNewDefaultRepository], 'pull_request.opened': [PullRequestOpenedDefault], 'pull_request.synchronize': [PullRequestOpenedDefault], + 'release.published': [ReleasePublishedIntegration], 'workflow_run.completed': [WorkflowRunCompeted], } diff --git a/src/plugins/integrationReleaseCreated.ts b/src/plugins/release.published.integration.ts similarity index 72% rename from src/plugins/integrationReleaseCreated.ts rename to src/plugins/release.published.integration.ts index b2e8c9f..ddf0ef8 100644 --- a/src/plugins/integrationReleaseCreated.ts +++ b/src/plugins/release.published.integration.ts @@ -1,10 +1,13 @@ -import { App } from 'octokit' -import { RepositoryName } from '../const' import { ReleasePayload } from '../types' +import { GitHubBot } from '../github.bot' +import { RepositoryName } from '../const' import { getNextMilestone } from '../utils/nextMilestone' -export default async (app: App, payload: ReleasePayload): Promise => { +export default async ( + bot: GitHubBot, + payload: ReleasePayload, +): Promise => { if ( payload.action !== 'published' || payload.repository.name !== RepositoryName.INTEGRATION @@ -12,9 +15,9 @@ export default async (app: App, payload: ReleasePayload): Promise => { return } - const nextMilestone = await getNextMilestone(app) + const nextMilestone = await getNextMilestone(bot.github) if (nextMilestone) { - await app.octokit.rest.issues.updateMilestone({ + await bot.github.octokit.rest.issues.updateMilestone({ owner: payload.repository.owner.login, repo: payload.repository.name, milestone_number: nextMilestone.number, @@ -24,7 +27,7 @@ export default async (app: App, payload: ReleasePayload): Promise => { }) } - await app.octokit.rest.issues.createMilestone({ + await bot.github.octokit.rest.issues.createMilestone({ owner: payload.repository.owner.login, repo: payload.repository.name, title: 'next',