Skip to content

Commit

Permalink
add settings to control notification types
Browse files Browse the repository at this point in the history
  • Loading branch information
Serghei Paduret committed Aug 10, 2021
1 parent ce5c146 commit 9660ddf
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/app/components/options/options.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h2>Extension settings</h2>
<h3>General</h3>
<div class="options-item">
<span>Refresh interval:</span>
<input type="number" min="1" max="120" style="width: 40px;" [(ngModel)]="settings.refreshIntervalInMinutes">
<input type="number" min="1" max="90" style="width: 30px;" [(ngModel)]="settings.refreshIntervalInMinutes">
<span>, in minutes</span>
</div>
</div>
Expand Down Expand Up @@ -53,6 +53,21 @@ <h3>Notifications</h3>
<input type="button" style="margin-left: 20px;" value="test" (click)="onSlackTest()">
</div>
</div>
<div class="options-sub-item-list">
<span class="title">Send notifications for events:</span>
<div class="options-item">
<input type="checkbox" [(ngModel)]="settings.notifications.events.pullRequestCreated">
New pull request created
</div>
<div class="options-item">
<input type="checkbox" [(ngModel)]="settings.notifications.events.pullRequestStateChanged">
Pull request state has changed (approved / needs work / conflicted / merged / declined / removed)
</div>
<div class="options-item">
<input type="checkbox" [(ngModel)]="settings.notifications.events.commentAdded">
New comments added
</div>
</div>
</div>

<div class="options-list">
Expand Down
10 changes: 10 additions & 0 deletions src/app/components/options/options.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
}
}

.options-sub-item-list {
margin-top: 8px;

.title {
font-size: 1.1em;
font-weight: bold;
padding: 5px 0;
}
}

.options-item {
display: flex;
padding: 2px 0;
Expand Down
21 changes: 18 additions & 3 deletions src/app/services/background.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class BackgroundService {
this.reviewCommentsCount(before, values);
switch (role) {
case PullRequestRole.Author:
this.reviewPullRequestApprovals(before, values);
this.reviewPullRequestStateChanged(before, values);
this.reviewMissingPullRequests(before, values);
break;
case PullRequestRole.Reviewer:
Expand All @@ -152,6 +152,9 @@ export class BackgroundService {
* @tutorial Make sense to run it for PRs with any role
*/
reviewCommentsCount(before: PullRequest[], now: PullRequest[]) {
if (!this.settings.notifications.events.commentAdded) {
return;
}
now
.filter(n => before.some(b => b.id === n.id && b.properties.commentCount !== n.properties.commentCount))
.forEach(n => {
Expand Down Expand Up @@ -179,6 +182,10 @@ export class BackgroundService {
* @tutorial Make sense to run it only for PRs with REVIEWER or PARTICIPANT role
*/
reviewNewPullRequests(before: PullRequest[], now: PullRequest[]) {
if (!this.settings.notifications.events.pullRequestCreated) {
return;
}

now
.filter(b => !before.some(n => n.id === b.id))
.forEach(n => {
Expand All @@ -204,6 +211,10 @@ export class BackgroundService {
* @tutorial Make sense to run it for PRs with AUTHOR or REVIEWER role
*/
reviewMissingPullRequests(before: PullRequest[], now: PullRequest[]) {
if (!this.settings.notifications.events.pullRequestStateChanged) {
return;
}

before
.filter(b => !now.some(n => n.id === b.id))
.forEach(b => {
Expand Down Expand Up @@ -241,10 +252,14 @@ export class BackgroundService {
}

/**
* Check if pull request was approved or flagged as needs-work.
* Check if pull request was approved or flagged as needs-work or got code conflicts.
* @tutorial Make sense to run it only for PRs with AUTHOR role
*/
reviewPullRequestApprovals(before: PullRequest[], now: PullRequest[]) {
reviewPullRequestStateChanged(before: PullRequest[], now: PullRequest[]) {
if (!this.settings.notifications.events.pullRequestStateChanged) {
return;
}

now
.map(n => {
const b = before.find(i => i.id === n.id);
Expand Down

0 comments on commit 9660ddf

Please sign in to comment.