-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
services/bots/src/github-webhook/handlers/new_integrations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PullRequestLabeledEvent>) { | ||
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', | ||
}), | ||
); | ||
} | ||
} | ||
} |