From 04e74e894835bfcd82fa0c50a21134a666c81b94 Mon Sep 17 00:00:00 2001 From: Serghei Paduret Date: Thu, 8 Jul 2021 05:29:20 -0400 Subject: [PATCH] replace pr action with pr activity action type --- src/app/models/enums.ts | 4 +++- src/app/models/models.ts | 5 +++-- src/app/services/background.service.ts | 8 ++++---- src/app/services/notification.service.ts | 25 +++++++++++++++--------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/app/models/enums.ts b/src/app/models/enums.ts index 3aecec6..fe84d50 100644 --- a/src/app/models/enums.ts +++ b/src/app/models/enums.ts @@ -25,7 +25,9 @@ export enum PullRequestActivityAction { Approved = 'APPROVED', Updated = 'UPDATED', Rescoped = 'RESCOPED', - Commented = 'COMMENTED' + Commented = 'COMMENTED', + Merged = 'MERGED', + Declined = 'DECLINED' } diff --git a/src/app/models/models.ts b/src/app/models/models.ts index 1cb917c..eb5eef9 100644 --- a/src/app/models/models.ts +++ b/src/app/models/models.ts @@ -1,4 +1,4 @@ -import {BitbucketCommentAction, PullRequestAction, PullRequestActivityAction, PullRequestRole, PullRequestState, PullRequestStatus} from './enums'; +import {BitbucketCommentAction, PullRequestActivityAction, PullRequestRole, PullRequestState, PullRequestStatus} from './enums'; export class ExtensionSettings { bitbucket?: BitbucketSettings = new BitbucketSettings(undefined); @@ -149,7 +149,8 @@ export class PullRequestIssue { } export class NotificationOptions { - action!: PullRequestAction; + action!: PullRequestActivityAction; pullRequest!: PullRequest; comment?: BitbucketComment; + activity?: PullRequestActivity; } diff --git a/src/app/services/background.service.ts b/src/app/services/background.service.ts index 112e88a..15d2e47 100644 --- a/src/app/services/background.service.ts +++ b/src/app/services/background.service.ts @@ -1,6 +1,6 @@ import {EventEmitter, Injectable} from '@angular/core'; import {BitbucketService} from './bitbucket.service'; -import {BitbucketCommentAction, PullRequestAction, PullRequestActivityAction, PullRequestRole, PullRequestState} from '../models/enums'; +import {BitbucketCommentAction, PullRequestActivityAction, PullRequestRole, PullRequestState} from '../models/enums'; import {ExtensionSettings, PullRequest} from '../models/models'; import {DataService} from './data.service'; import {NotificationService} from './notification.service'; @@ -167,7 +167,7 @@ export class BackgroundService { if (comments.length > 0) { this.notificationService.sendNotification( { - action: PullRequestAction.Comment, + action: PullRequestActivityAction.Commented, pullRequest: n, comment: comments[0].comment }); @@ -196,7 +196,7 @@ export class BackgroundService { if (isTrueReviewer) { this.notificationService.sendNotification( { - action: PullRequestAction.Created, + action: PullRequestActivityAction.Opened, pullRequest: n }); } @@ -223,7 +223,7 @@ export class BackgroundService { .forEach(n => { this.notificationService.sendNotification( { - action: PullRequestAction.Approved, + action: PullRequestActivityAction.Approved, pullRequest: n }); }); diff --git a/src/app/services/notification.service.ts b/src/app/services/notification.service.ts index 658243f..26c685c 100644 --- a/src/app/services/notification.service.ts +++ b/src/app/services/notification.service.ts @@ -4,8 +4,8 @@ import {SlackClient, SlackMessageOptions} from './slackClient'; import {catchError} from 'rxjs/operators'; import {of, throwError} from 'rxjs'; import {NotificationOptions, PullRequestIssue} from '../models/models'; -import {PullRequestAction} from '../models/enums'; import {BitbucketService} from './bitbucket.service'; +import {PullRequestActivityAction} from '../models/enums'; @Injectable() export class NotificationService { @@ -37,13 +37,13 @@ export class NotificationService { if (permission === 'granted') { let body = ''; switch (options.action) { - case PullRequestAction.Comment: + case PullRequestActivityAction.Commented: body = 'comment(s) added'; break; - case PullRequestAction.Created: + case PullRequestActivityAction.Opened: body = 'new pull request created'; break; - case PullRequestAction.Approved: + case PullRequestActivityAction.Approved: body = 'pull request approved'; break; } @@ -108,16 +108,23 @@ export class NotificationService { let title: string; let data = options.pullRequest; + // todo: move :reaction: names to settings switch (options.action) { - case PullRequestAction.Comment: + case PullRequestActivityAction.Commented: title = `:memo: @${options.comment?.author.name} added new comment`; break; - case PullRequestAction.Created: + case PullRequestActivityAction.Opened: title = `:pull_request: @${options.pullRequest.author.user.name} assigned a new pull request`; break; - case PullRequestAction.Approved: + case PullRequestActivityAction.Approved: title = ':white_check_mark: Your pull request approved'; break; + case PullRequestActivityAction.Merged: + title = `:merged: @${options.activity?.user.name} merged pull request`; + break; + case PullRequestActivityAction.Declined: + title = `:_: @${options.activity?.user.name} declined pull request`; + break; default: title = `something happened: ${options.action}`; break; @@ -139,7 +146,7 @@ export class NotificationService { }); // add comment - if (options.action == PullRequestAction.Comment) { + if (options.action == PullRequestActivityAction.Commented) { message.blocks?.push({ 'type': 'section', 'text': { @@ -152,7 +159,7 @@ export class NotificationService { // add description if (data.description?.length) { let prDescription: string; - if (options.action === PullRequestAction.Created) { + if (options.action === PullRequestActivityAction.Opened) { // use full description for just created PR prDescription = data.description; } else {