Skip to content

Commit

Permalink
Migrate new default closed
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Dec 17, 2024
1 parent 1485d09 commit 62fb1d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -75,7 +74,6 @@ async function handleWebhookEvent(event: EmitterWebhookEvent): Promise<void> {
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') {
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,5 +18,6 @@ export const plugins: Record<string, Plugin[]> = {
IssuesLabeledNewDefaultRepository,
],
'issues.opened': [IssuesOpenedGreeter],
'pull_request.closed': [PullRequestClosedDefault],
'workflow_run.completed': [WorkflowRunCompeted],
}
Original file line number Diff line number Diff line change
@@ -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 = `
Expand All @@ -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<void> => {
export default async (
bot: GitHubBot,
payload: IssuePullPayload,
): Promise<void> => {
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,
})
Expand All @@ -53,7 +58,7 @@ export default async (app: App, payload: PullPayload): Promise<void> => {
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],
})
Expand Down Expand Up @@ -87,7 +92,7 @@ export default async (app: App, payload: PullPayload): Promise<void> => {
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,
Expand Down

0 comments on commit 62fb1d8

Please sign in to comment.