Skip to content

Commit

Permalink
leave github comment
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian committed Oct 15, 2024
1 parent ceb73db commit bb27509
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 136 deletions.
27 changes: 12 additions & 15 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.

112 changes: 9 additions & 103 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.

7 changes: 4 additions & 3 deletions src/helpers/manage-merge-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export const manageMergeQueue = async ({
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);
}
}
Expand Down Expand Up @@ -116,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
12 changes: 4 additions & 8 deletions src/utils/notify-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +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}...`);
export const notifyUser = async ({ login, pull_number, slack_webhook_url }: NotifyUser) => {
const email = await getEmailOnUserProfile(login);
if (!email && comment_body) {
return await createPrComment({
body: comment_body
});
if (!email) {
return;
}
core.info(`Notifying user ${login}...`);
const {
data: { title, html_url }
} = await octokit.pulls.get({ pull_number, ...context.repo });
Expand Down
1 change: 1 addition & 0 deletions test/helpers/manage-merge-queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ describe('manageMergeQueue', () => {
await manageMergeQueue({ login, slack_webhook_url });

expect(removeLabelIfExists).toHaveBeenCalledWith(READY_FOR_MERGE_PR_LABEL, 123);
expect(createPrComment).toHaveBeenCalled();
});
});

Expand Down
7 changes: 2 additions & 5 deletions test/utils/notify-user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import axios from 'axios';
import { context } from '@actions/github';
import { notifyUser } from '../../src/utils/notify-user';
import { octokit } from '../../src/octokit';
import { createPrComment } from '../../src/helpers/create-pr-comment';

jest.mock('../../src/helpers/create-pr-comment');
jest.mock('@actions/core');
Expand Down Expand Up @@ -73,7 +72,6 @@ describe('notifyUser', () => {
describe('notifyUser with a PR comment', () => {
const pull_number = 123;
const slack_webhook_url = 'https://hooks.slack.com/workflows/1234567890';
const comment_body = 'Your PR is first in the queue';

beforeEach(async () => {
(octokit.users.getByUsername as unknown as Mocktokit).mockImplementation(async () => ({
Expand All @@ -82,12 +80,11 @@ describe('notifyUser with a PR comment', () => {
}
}));

await notifyUser({ login, pull_number, slack_webhook_url, comment_body });
await notifyUser({ login, pull_number, slack_webhook_url });
});

it('should add a PR comment when email is not found', () => {
it('should do nothing when email is not found', () => {
expect(octokit.users.getByUsername).toHaveBeenCalledWith({ username: login });
expect(createPrComment).toHaveBeenCalledWith({ body: comment_body });
expect(axios.post).not.toHaveBeenCalled();
});
});

0 comments on commit bb27509

Please sign in to comment.