Skip to content

Commit

Permalink
replace pr action with pr activity action type
Browse files Browse the repository at this point in the history
  • Loading branch information
Serghei Paduret committed Jul 8, 2021
1 parent 21ad018 commit 04e74e8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/app/models/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export enum PullRequestActivityAction {
Approved = 'APPROVED',
Updated = 'UPDATED',
Rescoped = 'RESCOPED',
Commented = 'COMMENTED'
Commented = 'COMMENTED',
Merged = 'MERGED',
Declined = 'DECLINED'
}


Expand Down
5 changes: 3 additions & 2 deletions src/app/models/models.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -149,7 +149,8 @@ export class PullRequestIssue {
}

export class NotificationOptions {
action!: PullRequestAction;
action!: PullRequestActivityAction;
pullRequest!: PullRequest;
comment?: BitbucketComment;
activity?: PullRequestActivity;
}
8 changes: 4 additions & 4 deletions src/app/services/background.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
});
Expand Down Expand Up @@ -196,7 +196,7 @@ export class BackgroundService {
if (isTrueReviewer) {
this.notificationService.sendNotification(
{
action: PullRequestAction.Created,
action: PullRequestActivityAction.Opened,
pullRequest: n
});
}
Expand All @@ -223,7 +223,7 @@ export class BackgroundService {
.forEach(n => {
this.notificationService.sendNotification(
{
action: PullRequestAction.Approved,
action: PullRequestActivityAction.Approved,
pullRequest: n
});
});
Expand Down
25 changes: 16 additions & 9 deletions src/app/services/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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': {
Expand All @@ -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 {
Expand Down

0 comments on commit 04e74e8

Please sign in to comment.