Skip to content

Commit

Permalink
feat(manage-merge-queue): require email on profile to enter the queue (
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored Oct 16, 2024
1 parent 69739be commit 10f6976
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 131 deletions.
58 changes: 47 additions & 11 deletions dist/284.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/284.index.js.map

Large diffs are not rendered by default.

134 changes: 35 additions & 99 deletions dist/946.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/946.index.js.map

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions src/helpers/manage-merge-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { approvalsSatisfied } from './approvals-satisfied';
import { createPrComment } from './create-pr-comment';
import { isUserInTeam } from './is-user-in-team';
import { join } from 'path';
import { getEmailOnUserProfile } from '../utils/get-email-on-user-profile';

export class ManageMergeQueue extends HelperInputs {
max_queue_size?: string;
Expand Down Expand Up @@ -62,6 +63,16 @@ export const manageMergeQueue = async ({
if (!prMeetsRequiredApprovals) {
return removePrFromQueue(pullRequest);
}
if (slack_webhook_url && login) {
const email = await getEmailOnUserProfile(login);
if (!email) {
await createPrComment({
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"`
});
return removePrFromQueue(pullRequest);
}
}

const queuedPrs = await getQueuedPullRequests();
const queuePosition = queuedPrs.length + 1;

Expand Down Expand Up @@ -108,9 +119,7 @@ export const manageMergeQueue = async ({
await notifyUser({
login,
pull_number: context.issue.number,
slack_webhook_url,
comment_body: `@${login} Your PR is first in the queue!
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"`
slack_webhook_url
});
}
};
Expand Down
22 changes: 22 additions & 0 deletions src/utils/get-email-on-user-profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Copyright 2021 Expedia, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { octokit } from '../octokit';

export async function getEmailOnUserProfile(login: string) {
const {
data: { email }
} = await octokit.users.getByUsername({ username: login });

return email;
}
17 changes: 6 additions & 11 deletions src/utils/notify-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,20 @@ import * as core from '@actions/core';
import axios from 'axios';
import { context } from '@actions/github';
import { octokit } from '../octokit';
import { createPrComment } from '../helpers/create-pr-comment';
import { getEmailOnUserProfile } from './get-email-on-user-profile';

interface NotifyUser {
login: string;
pull_number: number;
slack_webhook_url: string;
comment_body?: string;
}

export const notifyUser = async ({ login, pull_number, slack_webhook_url, comment_body }: NotifyUser) => {
core.info(`Notifying user ${login}...`);
const {
data: { email }
} = await octokit.users.getByUsername({ username: login });
if (!email && comment_body) {
return await createPrComment({
body: comment_body
});
export const notifyUser = async ({ login, pull_number, slack_webhook_url }: NotifyUser) => {
const email = await getEmailOnUserProfile(login);
if (!email) {
return;
}
core.info(`Notifying user ${login}...`);
const {
data: { title, html_url }
} = await octokit.pulls.get({ pull_number, ...context.repo });
Expand Down
Loading

0 comments on commit 10f6976

Please sign in to comment.