Skip to content

Commit

Permalink
Fix format and ignore bots (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Oct 21, 2022
1 parent 45b41ee commit cdfd2b2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
63 changes: 36 additions & 27 deletions services/bots/src/github-webhook/handlers/code_owners_mention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@ import { BaseWebhookHandler } from './base';
import { CodeOwnersEntry, matchFile } from 'codeowners-utils';
import { ISSUE_COMMENT_COMMANDS } from './issue_comment_commands/commands';

const generateCodeOwnersMentionComment = (
integration: string,
codeOwners: string[],
triggerLabel: string,
codeownersLine: string,
) => `
Hey there ${codeOwners.join(
', ',
)}, mind taking a look at this ${triggerLabel} as it has been labeled with an integration (\`${integration}\`) you are listed as a [code owner](${codeownersLine}) for? Thanks!
<details>
<summary>Code owner commands</summary>
Code owners of \`${integration}\ can trigger bot actions by commenting:
${Object.entries(ISSUE_COMMENT_COMMANDS)
.filter(([command, data]) => data.invokerType === 'code_owner')
.map(
([command, data]) =>
`- \`${['@home-assistant', command, data.exampleAdditional]
.filter((item) => item !== undefined)
.join(' ')
.trim()}\` ${data.description}`,
)
.join('\n')}
</details>
`;

export class CodeOwnersMention extends BaseWebhookHandler {
public allowedEventTypes = [EventType.ISSUES_LABELED, EventType.PULL_REQUEST_LABELED];
public allowedRepositories = [
Expand Down Expand Up @@ -83,33 +113,12 @@ export class CodeOwnersMention extends BaseWebhookHandler {

context.scheduleIssueComment({
handler: 'CodeOwnersMention',
comment: `Hey there ${mentions.join(
', ',
)}, mind taking a look at this ${triggerLabel} as it has been labeled with an integration (\`${integrationName}\`) you are listed as a [code owner](${codeownersLine}) for? Thanks!
<details>
<summary>Code owner commands</summary>
Code owners of \`${integrationName}\` can trigger bot actions by commenting:
${Object.entries(ISSUE_COMMENT_COMMANDS)
.filter(
([command, data]) =>
data.invokerType === 'code_owner' &&
(mentions.length === 1 || command === 'unassign'),
)
.map(
([command, data]) =>
`- \`${['@home-assistant', command, data.exampleAdditional]
.filter((item) => item !== undefined)
.join(' ')
.trim()}\` ${data.description}`,
)
.join('\n')}
</details>
`,
comment: generateCodeOwnersMentionComment(
integrationName,
mentions,
triggerLabel,
codeownersLine,
),
priority: 1,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { BaseWebhookHandler } from '../base';

import { ISSUE_COMMENT_COMMANDS } from './commands';

const commandRegex = /(?<tagged>@home-assistant)\s(?<command>\w*)(\s(?<additional>.*))?/;
const commandRegex = /^(?<tagged>@home-assistant)\s(?<command>\w*)(\s(?<additional>.*))?$/;

export class IssueCommentCommands extends BaseWebhookHandler {
public allowBots = false;
public allowedEventTypes = [EventType.ISSUE_COMMENT_CREATED];
public allowedRepositories = [
HomeAssistantRepository.CORE,
Expand Down

0 comments on commit cdfd2b2

Please sign in to comment.