From aa7bb45eb9805802a5aff62b3e002aef01809e6c Mon Sep 17 00:00:00 2001 From: Ritik Kapoor Date: Mon, 11 Nov 2024 12:00:57 +0000 Subject: [PATCH] feat: [CODE-2467]: add pullreq_label_assigned as a webhook trigger event (#2945) * fix: [code-2505] lint checks * feat: [code-2467] add pullreq_label_assigned as a webhook trigger event --- web/src/framework/strings/stringTypes.ts | 1 + web/src/i18n/strings.en.yaml | 1 + web/src/pages/WebhookNew/WehookForm.tsx | 10 ++++++++++ web/src/utils/GitUtils.ts | 9 ++++++--- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/web/src/framework/strings/stringTypes.ts b/web/src/framework/strings/stringTypes.ts index 70ab898e7..0574669f0 100644 --- a/web/src/framework/strings/stringTypes.ts +++ b/web/src/framework/strings/stringTypes.ts @@ -1185,6 +1185,7 @@ export interface StringsMap { webhookPRClosed: string webhookPRCommentCreated: string webhookPRCreated: string + webhookPRLabelAssigned: string webhookPRMerged: string webhookPRReopened: string webhookPRUpdated: string diff --git a/web/src/i18n/strings.en.yaml b/web/src/i18n/strings.en.yaml index 58509335e..52869491c 100644 --- a/web/src/i18n/strings.en.yaml +++ b/web/src/i18n/strings.en.yaml @@ -432,6 +432,7 @@ webhookPRReopened: PR reopened webhookPRClosed: PR closed webhookPRCommentCreated: PR comment created webhookPRMerged: PR merged +webhookPRLabelAssigned: PR label assigned nameYourWebhook: Name your webhook noExecutionsFound: No Executions found noExecutionsFoundForWebhook: No executions found for the given webhook diff --git a/web/src/pages/WebhookNew/WehookForm.tsx b/web/src/pages/WebhookNew/WehookForm.tsx index db4a44599..7feeb3813 100644 --- a/web/src/pages/WebhookNew/WehookForm.tsx +++ b/web/src/pages/WebhookNew/WehookForm.tsx @@ -63,6 +63,7 @@ interface FormData { prClosed: boolean prCommentCreated: boolean prMerged: boolean + prLabelAssigned: boolean } interface WebHookFormProps extends Pick { @@ -115,6 +116,7 @@ export function WehookForm({ repoMetadata, isEdit, webhook }: WebHookFormProps) prClosed: webhook?.triggers?.includes(WebhookIndividualEvent.PR_CLOSED) || false, prCommentCreated: webhook?.triggers?.includes(WebhookIndividualEvent.PR_COMMENT_CREATED) || false, prMerged: webhook?.triggers?.includes(WebhookIndividualEvent.PR_MERGED) || false, + prLabelAssigned: webhook?.triggers?.includes(WebhookIndividualEvent.PR_LABEL_ASSIGNED) || false, events: (webhook?.triggers?.length || 0) > 0 ? WebhookEventType.INDIVIDUAL : WebhookEventType.ALL }} formName="create-webhook-form" @@ -170,6 +172,9 @@ export function WehookForm({ repoMetadata, isEdit, webhook }: WebHookFormProps) if (formData.prMerged) { triggers.push(WebhookIndividualEvent.PR_MERGED) } + if (formData.prLabelAssigned) { + triggers.push(WebhookIndividualEvent.PR_LABEL_ASSIGNED) + } if (!triggers.length) { return showError(getString('oneMustBeSelected')) } @@ -318,6 +323,11 @@ export function WehookForm({ repoMetadata, isEdit, webhook }: WebHookFormProps) name="prMerged" className={css.checkbox} /> + ) : null} diff --git a/web/src/utils/GitUtils.ts b/web/src/utils/GitUtils.ts index 91f2af467..2c972743d 100644 --- a/web/src/utils/GitUtils.ts +++ b/web/src/utils/GitUtils.ts @@ -610,7 +610,8 @@ export enum WebhookIndividualEvent { PR_BRANCH_UPDATED = 'pullreq_branch_updated', PR_CLOSED = 'pullreq_closed', PR_COMMENT_CREATED = 'pullreq_comment_created', - PR_MERGED = 'pullreq_merged' + PR_MERGED = 'pullreq_merged', + PR_LABEL_ASSIGNED = 'pullreq_label_assigned' } export enum WebhookEventMap { @@ -626,7 +627,8 @@ export enum WebhookEventMap { PR_BRANCH_UPDATED = 'PR branch updated', PR_CLOSED = 'PR closed', PR_COMMENT_CREATED = 'PR comment created', - PR_MERGED = 'PR merged' + PR_MERGED = 'PR merged', + PR_LABEL_ASSIGNED = 'PR label assigned' } export const eventMapping: Record = { @@ -642,7 +644,8 @@ export const eventMapping: Record = { [WebhookIndividualEvent.PR_BRANCH_UPDATED]: WebhookEventMap.PR_BRANCH_UPDATED, [WebhookIndividualEvent.PR_CLOSED]: WebhookEventMap.PR_CLOSED, [WebhookIndividualEvent.PR_COMMENT_CREATED]: WebhookEventMap.PR_COMMENT_CREATED, - [WebhookIndividualEvent.PR_MERGED]: WebhookEventMap.PR_MERGED + [WebhookIndividualEvent.PR_MERGED]: WebhookEventMap.PR_MERGED, + [WebhookIndividualEvent.PR_LABEL_ASSIGNED]: WebhookEventMap.PR_LABEL_ASSIGNED } export function getEventDescription(event: WebhookIndividualEvent): string {