From 62fb1d84993dbb222824966a995a13bc38e7effb Mon Sep 17 00:00:00 2001 From: ludeeus Date: Tue, 17 Dec 2024 07:48:10 +0000 Subject: [PATCH] Migrate new default closed --- src/handler.ts | 2 -- src/plugins/index.ts | 2 ++ ...rged.ts => pull_request.closed.default.ts} | 23 +++++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-) rename src/plugins/{newDefaultMerged.ts => pull_request.closed.default.ts} (83%) diff --git a/src/handler.ts b/src/handler.ts index 4bc4ede..d16fbee 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -5,7 +5,6 @@ import * as Sentry from '@sentry/browser' import integrationRepoIssueClosedPlugin from './plugins/integrationRepoIssueClosed' import integrationRepoPullClosedPlugin from './plugins/integrationRepoPullClosed' -import newDefaultMergedPlugin from './plugins/newDefaultMerged' import newDefaultOpenedPlugin from './plugins/newDefaultOpened' import integrationReleaseCreatedPlugin from './plugins/integrationReleaseCreated' @@ -75,7 +74,6 @@ async function handleWebhookEvent(event: EmitterWebhookEvent): Promise { if ('pull_request' in payload) { await Promise.all([ newDefaultOpenedPlugin(app, payload), - newDefaultMergedPlugin(app, payload), integrationRepoPullClosedPlugin(app, payload), ]) } else if ('issue' in payload && payload.action === 'closed') { diff --git a/src/plugins/index.ts b/src/plugins/index.ts index d894b6d..a0e5cd1 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -4,6 +4,7 @@ import IssuesLabeledDuplicate from './issues.labeled.duplicate' import IssuesLabeledInvalid from './issues.labeled.invalid' import IssuesLabeledNewDefaultRepository from './issues.labeled.new_default_repository' import IssuesOpenedGreeter from './issues.opened.greeter' +import PullRequestClosedDefault from './pull_request.closed.default' import WorkflowRunCompeted from './workflow_run.completed' // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -17,5 +18,6 @@ export const plugins: Record = { IssuesLabeledNewDefaultRepository, ], 'issues.opened': [IssuesOpenedGreeter], + 'pull_request.closed': [PullRequestClosedDefault], 'workflow_run.completed': [WorkflowRunCompeted], } diff --git a/src/plugins/newDefaultMerged.ts b/src/plugins/pull_request.closed.default.ts similarity index 83% rename from src/plugins/newDefaultMerged.ts rename to src/plugins/pull_request.closed.default.ts index 0e796b9..99c1945 100644 --- a/src/plugins/newDefaultMerged.ts +++ b/src/plugins/pull_request.closed.default.ts @@ -1,9 +1,9 @@ -import { App } from 'octokit' -import { defaultCategories, RepositoryName } from '../const' -import { PullPayload } from '../types' +import { IssuePullPayload, PayloadIsPull } from '../types' +import { GitHubBot } from '../github.bot' import { extractOwnerRepo } from '../utils/extractOwnerRepo' import { senderIsBot } from '../utils/filter' +import { defaultCategories, RepositoryName } from '../const' import { postDiscordMessage } from '../utils/postDiscordMessage' const messageCommon = ` @@ -26,15 +26,20 @@ const messageLinks = ` [lovelace_custom_card]: https://developers.home-assistant.io/docs/lovelace_custom_card#graphical-card-configuration ` -export default async (app: App, payload: PullPayload): Promise => { +export default async ( + bot: GitHubBot, + payload: IssuePullPayload, +): Promise => { if ( senderIsBot(payload) || + !PayloadIsPull(payload) || extractOwnerRepo(payload).repo !== RepositoryName.DEFAULT || - !['closed'].includes(payload.action) - ) + payload.action !== 'closed' + ) { return + } - const { data: pull } = await app.octokit.rest.pulls.get({ + const { data: pull } = await bot.github.octokit.rest.pulls.get({ ...extractOwnerRepo(payload), pull_number: payload.pull_request.number, }) @@ -53,7 +58,7 @@ export default async (app: App, payload: PullPayload): Promise => { return } - const { data: repoAdded } = await app.octokit.rest.repos.get({ + const { data: repoAdded } = await bot.github.octokit.rest.repos.get({ owner: owner_repo.split('/')[0], repo: owner_repo.split('/')[1], }) @@ -87,7 +92,7 @@ export default async (app: App, payload: PullPayload): Promise => { body += messagePlugins } - await app.octokit.rest.issues.createComment({ + await bot.github.octokit.rest.issues.createComment({ ...extractOwnerRepo(payload), issue_number: payload.pull_request.number, body: body + messageLinks,