diff --git a/services/bots/src/github-webhook/github-webhook.module.ts b/services/bots/src/github-webhook/github-webhook.module.ts index d8fe66f..5a0825f 100644 --- a/services/bots/src/github-webhook/github-webhook.module.ts +++ b/services/bots/src/github-webhook/github-webhook.module.ts @@ -18,12 +18,13 @@ import { IssueLinks } from './handlers/issue_links'; import { LabelBot } from './handlers/label_bot/handler'; import { LabelCleaner } from './handlers/label_cleaner'; import { MonthOfWTH } from './handlers/month_of_wth'; +import { NewIntegrationsHandler } from './handlers/new_integrations'; import { PlatinumReview } from './handlers/platinum_review'; import { QualityScaleLabeler } from './handlers/quality_scale'; +import { ReviewDrafter } from './handlers/review_drafter'; import { SetDocumentationSection } from './handlers/set_documentation_section'; import { SetIntegration } from './handlers/set_integration'; import { ValidateCla } from './handlers/validate-cla'; -import { ReviewDrafter } from './handlers/review_drafter'; @Module({ providers: [ @@ -40,6 +41,7 @@ import { ReviewDrafter } from './handlers/review_drafter'; LabelBot, LabelCleaner, MonthOfWTH, + NewIntegrationsHandler, PlatinumReview, QualityScaleLabeler, ReviewDrafter, diff --git a/services/bots/src/github-webhook/handlers/new_integrations.ts b/services/bots/src/github-webhook/handlers/new_integrations.ts new file mode 100644 index 0000000..2ba8a3b --- /dev/null +++ b/services/bots/src/github-webhook/handlers/new_integrations.ts @@ -0,0 +1,36 @@ +import { PullRequestLabeledEvent } from '@octokit/webhooks-types'; +import { EventType, HomeAssistantRepository } from '../github-webhook.const'; +import { WebhookContext } from '../github-webhook.model'; +import { BaseWebhookHandler } from './base'; + +import { fetchPullRequestFilesFromContext } from '../utils/pull_request'; +import { ParsedPath } from '../utils/parse_path'; + +export class NewIntegrationsHandler extends BaseWebhookHandler { + public allowedEventTypes = [EventType.PULL_REQUEST_LABELED]; + public allowedRepositories = [HomeAssistantRepository.CORE]; + + /** + * When a new-integration label is added, check if the PR contains multiple platforms. + * If so, request changes. The ReviewDrafter will handle the rest. + */ + async handle(context: WebhookContext) { + if (context.payload.label?.name !== 'new-integration') { + return; + } + + const pullRequestFiles = await fetchPullRequestFilesFromContext(context); + const parsed = pullRequestFiles.map((file) => new ParsedPath(file)); + + const integrationPlatforms = parsed.filter((path) => path.type === 'platform'); + + if (integrationPlatforms.length > 1) { + await context.github.pulls.createReview( + context.pullRequest({ + body: '[When adding new integrations, limit included platforms to a single platform. Please reduce this PR to a single platform](https://developers.home-assistant.io/docs/review-process/#home-assistant-core)', + event: 'REQUEST_CHANGES', + }), + ); + } + } +}