Skip to content

Commit

Permalink
Move comment to new label handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Dec 16, 2024
1 parent d4ec3a2 commit 849f45c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
7 changes: 6 additions & 1 deletion src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { GitHubBot } from '../github.bot'
import BaseMetrics from './base.metrics'
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 WorkflowRunCompeted from './workflow_run.completed'

Expand All @@ -10,7 +11,11 @@ type Plugin = (bot: GitHubBot, payload: any) => Promise<void>

export const plugins: Record<string, Plugin[]> = {
base: [BaseMetrics],
'issues.labeled': [IssuesLabeledDuplicate, IssuesLabeledInvalid],
'issues.labeled': [
IssuesLabeledDuplicate,
IssuesLabeledInvalid,
IssuesLabeledNewDefaultRepository,
],
'issues.opened': [IssuesOpenedGreeter],
'workflow_run.completed': [WorkflowRunCompeted],
}
38 changes: 38 additions & 0 deletions src/plugins/issues.labeled.new_default_repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { IssuePullPayload, PayloadIsIssue } from '../types'

import { GitHubBot } from '../github.bot'
import { extractOwnerRepo } from '../utils/extractOwnerRepo'
import { senderIsBot } from '../utils/filter'

const label = 'New default repository'
const postedComment = `
Your repository is now waiting to be included in HACS. Please be patient, this will take some time.
[You can see the current queue here](https://github.com/hacs/default/pulls?q=is%3Apr+is%3Aopen+draft%3Afalse+sort%3Acreated-asc) (this is the order that is being used).
There is no need to:
- Comment on the PR, the reviewer will get back to you.
- Open a new PR, this will not speed up the process.
- Ask your folowers to spam the PR, this will not speed up the process.
`

export default async (
bot: GitHubBot,
payload: IssuePullPayload,
): Promise<void> => {
if (
senderIsBot(payload) ||
!PayloadIsIssue(payload) ||
payload.repository.name !== 'default' ||
payload.action !== 'labeled' ||
payload.label?.name !== label
) {
return
}

await bot.github.octokit.rest.issues.createComment({
...extractOwnerRepo(payload),
issue_number: payload.issue.number,
body: postedComment,
})
}
24 changes: 3 additions & 21 deletions src/plugins/newDefaultOpened.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ import { senderIsBot } from '../utils/filter'
import { extractTasks } from '../utils/tasks'
import { convertPullRequestToDraft } from '../utils/convertToDraft'

const postedComment = `
Your repository is now waiting to be included in HACS. Please be patient, this will take some time.
[You can see the current queue here](https://github.com/hacs/default/pulls?q=is%3Apr+is%3Aopen+draft%3Afalse+sort%3Acreated-asc) (this is the order that is being used).
There is no need to:
- Comment on the PR, the reviewer will get back to you.
- Open a new PR, this will not speed up the process.
- Ask your folowers to spam the PR, this will not speed up the process.
`

export default async (app: App, payload: PullPayload): Promise<void> => {
if (
senderIsBot(payload) ||
Expand Down Expand Up @@ -119,18 +108,11 @@ export default async (app: App, payload: PullPayload): Promise<void> => {

const newTitle = `Adds new ${repoCategory} [${owner}/${repo}]`

if (payload.action === 'opened') {
if (newTitle !== payload.pull_request.title) {
await app.octokit.rest.issues.update({
...extractOwnerRepo(payload),
issue_number: payload.pull_request.number,
title: newTitle,
})
}
await app.octokit.rest.issues.createComment({
if (payload.action === 'opened' || newTitle !== payload.pull_request.title) {
await app.octokit.rest.issues.update({
...extractOwnerRepo(payload),
issue_number: payload.pull_request.number,
body: postedComment,
title: newTitle,
})
}
}
Expand Down

0 comments on commit 849f45c

Please sign in to comment.