Skip to content

Commit 10f6976

Browse files
authored
feat(manage-merge-queue): require email on profile to enter the queue (#668)
1 parent 69739be commit 10f6976

File tree

9 files changed

+156
-131
lines changed

9 files changed

+156
-131
lines changed

dist/284.index.js

Lines changed: 47 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/284.index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/946.index.js

Lines changed: 35 additions & 99 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/946.index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helpers/manage-merge-queue.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { approvalsSatisfied } from './approvals-satisfied';
3333
import { createPrComment } from './create-pr-comment';
3434
import { isUserInTeam } from './is-user-in-team';
3535
import { join } from 'path';
36+
import { getEmailOnUserProfile } from '../utils/get-email-on-user-profile';
3637

3738
export class ManageMergeQueue extends HelperInputs {
3839
max_queue_size?: string;
@@ -62,6 +63,16 @@ export const manageMergeQueue = async ({
6263
if (!prMeetsRequiredApprovals) {
6364
return removePrFromQueue(pullRequest);
6465
}
66+
if (slack_webhook_url && login) {
67+
const email = await getEmailOnUserProfile(login);
68+
if (!email) {
69+
await createPrComment({
70+
body: `@${login} Your PR cannot be added to the queue because your email must be set on your GitHub profile. Here are the steps to take:\n\n1. Go to ${join(context.serverUrl, login)}\n2. Click "Edit profile"\n3. Update your email address\n4. Click "Save"`
71+
});
72+
return removePrFromQueue(pullRequest);
73+
}
74+
}
75+
6576
const queuedPrs = await getQueuedPullRequests();
6677
const queuePosition = queuedPrs.length + 1;
6778

@@ -108,9 +119,7 @@ export const manageMergeQueue = async ({
108119
await notifyUser({
109120
login,
110121
pull_number: context.issue.number,
111-
slack_webhook_url,
112-
comment_body: `@${login} Your PR is first in the queue!
113-
Email not found for user ${login}. Please add an email to your Github profile!\n\n1. Go to ${join(context.serverUrl, login)}\n2. Click "Edit profile"\n3. Update your email address\n4. Click "Save"`
122+
slack_webhook_url
114123
});
115124
}
116125
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright 2021 Expedia, Inc.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
https://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
import { octokit } from '../octokit';
15+
16+
export async function getEmailOnUserProfile(login: string) {
17+
const {
18+
data: { email }
19+
} = await octokit.users.getByUsername({ username: login });
20+
21+
return email;
22+
}

src/utils/notify-user.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,20 @@ import * as core from '@actions/core';
1515
import axios from 'axios';
1616
import { context } from '@actions/github';
1717
import { octokit } from '../octokit';
18-
import { createPrComment } from '../helpers/create-pr-comment';
18+
import { getEmailOnUserProfile } from './get-email-on-user-profile';
1919

2020
interface NotifyUser {
2121
login: string;
2222
pull_number: number;
2323
slack_webhook_url: string;
24-
comment_body?: string;
2524
}
2625

27-
export const notifyUser = async ({ login, pull_number, slack_webhook_url, comment_body }: NotifyUser) => {
28-
core.info(`Notifying user ${login}...`);
29-
const {
30-
data: { email }
31-
} = await octokit.users.getByUsername({ username: login });
32-
if (!email && comment_body) {
33-
return await createPrComment({
34-
body: comment_body
35-
});
26+
export const notifyUser = async ({ login, pull_number, slack_webhook_url }: NotifyUser) => {
27+
const email = await getEmailOnUserProfile(login);
28+
if (!email) {
29+
return;
3630
}
31+
core.info(`Notifying user ${login}...`);
3732
const {
3833
data: { title, html_url }
3934
} = await octokit.pulls.get({ pull_number, ...context.repo });

0 commit comments

Comments
 (0)