From 849f45cf6ebe6ee4f309d5841a40f355d331d678 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Mon, 16 Dec 2024 09:02:39 +0000 Subject: [PATCH] Move comment to new label handler --- src/plugins/index.ts | 7 +++- .../issues.labeled.new_default_repository.ts | 38 +++++++++++++++++++ src/plugins/newDefaultOpened.ts | 24 ++---------- 3 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 src/plugins/issues.labeled.new_default_repository.ts diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 53e40f6..d894b6d 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -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' @@ -10,7 +11,11 @@ type Plugin = (bot: GitHubBot, payload: any) => Promise export const plugins: Record = { base: [BaseMetrics], - 'issues.labeled': [IssuesLabeledDuplicate, IssuesLabeledInvalid], + 'issues.labeled': [ + IssuesLabeledDuplicate, + IssuesLabeledInvalid, + IssuesLabeledNewDefaultRepository, + ], 'issues.opened': [IssuesOpenedGreeter], 'workflow_run.completed': [WorkflowRunCompeted], } diff --git a/src/plugins/issues.labeled.new_default_repository.ts b/src/plugins/issues.labeled.new_default_repository.ts new file mode 100644 index 0000000..2af0257 --- /dev/null +++ b/src/plugins/issues.labeled.new_default_repository.ts @@ -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 => { + 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, + }) +} diff --git a/src/plugins/newDefaultOpened.ts b/src/plugins/newDefaultOpened.ts index 2d683a7..a51eb7f 100644 --- a/src/plugins/newDefaultOpened.ts +++ b/src/plugins/newDefaultOpened.ts @@ -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 => { if ( senderIsBot(payload) || @@ -119,18 +108,11 @@ export default async (app: App, payload: PullPayload): Promise => { 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, }) } }