Skip to content

Commit

Permalink
Migrate ReleasePublishedIntegration
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Dec 18, 2024
1 parent 127cb57 commit 7ef5c8c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/github.bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
)
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -67,14 +66,12 @@ export async function handleRequest(request: Request): Promise<Response> {

async function handleWebhookEvent(event: EmitterWebhookEvent): Promise<void> {
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)])
}
}
2 changes: 2 additions & 0 deletions src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,5 +20,6 @@ export const plugins: Record<string, Plugin[]> = {
'pull_request.labeled': [PullRequestLabeledNewDefaultRepository],
'pull_request.opened': [PullRequestOpenedDefault],
'pull_request.synchronize': [PullRequestOpenedDefault],
'release.published': [ReleasePublishedIntegration],
'workflow_run.completed': [WorkflowRunCompeted],
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
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<void> => {
export default async (
bot: GitHubBot,
payload: ReleasePayload,
): Promise<void> => {
if (
payload.action !== 'published' ||
payload.repository.name !== RepositoryName.INTEGRATION
) {
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,
Expand All @@ -24,7 +27,7 @@ export default async (app: App, payload: ReleasePayload): Promise<void> => {
})
}

await app.octokit.rest.issues.createMilestone({
await bot.github.octokit.rest.issues.createMilestone({
owner: payload.repository.owner.login,
repo: payload.repository.name,
title: 'next',
Expand Down

0 comments on commit 7ef5c8c

Please sign in to comment.