Skip to content

Commit

Permalink
fix: assignment and reviewer funcitonality
Browse files Browse the repository at this point in the history
  • Loading branch information
nejdetkadir committed Oct 11, 2023
1 parent ce5acdb commit 36a98c4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 56 deletions.
54 changes: 29 additions & 25 deletions dist/index.js

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

21 changes: 19 additions & 2 deletions src/lib/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as github from '@actions/github';
import * as core from '@actions/core';

import { useOctokit } from '@app/hooks';
import { checklist } from '@app/lib';
import { checklist, pullRequest } from '@app/lib';

async function removeOldPRComments() {
const octokit = useOctokit();
Expand All @@ -25,6 +25,13 @@ async function removeOldPRComments() {
}

async function commentErrors(errors: string[]) {
const { isDraft, PROwner } = await pullRequest.getPRInfo();

if (isDraft) {
commentDraftPR();
return;
}

await removeOldPRComments();

const octokit = useOctokit();
Expand All @@ -45,7 +52,7 @@ async function commentErrors(errors: string[]) {
}

const messageBody = hasErrors
? `BOT MESSAGE :robot:\n\n\n${errorsBody}\n${checklistErrorsBody}`
? `BOT MESSAGE :robot:\n\n\n${errorsBody}\n${checklistErrorsBody}\n\n\n@${PROwner}`
: 'BOT MESSAGE :robot:\n\n\nAll good for checklist :green_circle:';

await octokit.rest.issues.createComment({
Expand All @@ -55,4 +62,14 @@ async function commentErrors(errors: string[]) {
});
}

async function commentDraftPR() {
const octokit = useOctokit();

await octokit.rest.issues.createComment({
...github.context.repo,
issue_number: github.context.issue.number,
body: `BOT MESSAGE :robot:\n\n\nPullMate skips the checklist for draft PRs :construction:`
});
}

export default { commentErrors };
45 changes: 16 additions & 29 deletions src/lib/pullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,24 @@ import { COMMIT_KEYS } from '@app/constants';
async function getPRInfo() {
const octokit = useOctokit();

const PR = await octokit.rest.issues.get({
const issue = await octokit.rest.issues.get({
...github.context.repo,
issue_number: github.context.issue.number
});

return {
title: PR?.data?.title ?? ''
};
}

async function getAssigneesCount() {
const octokit = useOctokit();

const assignees = await octokit.rest.issues.listAssignees({
const PR = await octokit.rest.pulls.get({
...github.context.repo,
issue_number: github.context.issue.number
pull_number: github.context.issue.number
});

core.debug(`getAssigneesCount: ${assignees.data.length}`);
core.debug(`getAssigneesCount: ${JSON.stringify(assignees.data)}`);

return assignees.data.length;
return {
title: issue?.data?.title ?? '',
isDraft: issue?.data?.draft ?? false,
isClosed: issue?.data?.state === 'closed',
isAssigned: !!issue?.data?.assignee,
hasReviewers: !!PR?.data?.requested_reviewers?.length,
PROwner: PR?.data?.user?.login ?? ''
};
}

async function hasSemanticTitle() {
Expand All @@ -53,23 +49,16 @@ async function hasTaskNumber() {
return true;
}

async function hasAssignees() {
const count = await getAssigneesCount();
core.debug(`hasAssignees count: ${count}`);

return count > 0;
}

async function missingAssignees() {
const { isAsigneeRequired } = useInputs();

core.debug(`isAsigneeRequired: ${isAsigneeRequired}`);

if (!isAsigneeRequired) {
return false;
}

return !(await hasAssignees());
const { isAssigned } = await getPRInfo();

return !isAssigned;
}

async function missingSemanticTitle() {
Expand All @@ -84,21 +73,19 @@ async function missingSemanticTitle() {

async function missingReviewers() {
const { isReviewerRequired } = useInputs();
const reviewers = github.context.payload.pull_request?.requested_reviewers;
const { hasReviewers } = await getPRInfo();

if (!isReviewerRequired) {
return false;
}

return !reviewers;
return !hasReviewers;
}

export default {
getPRInfo,
hasSemanticTitle,
hasTaskNumber,
getAssigneesCount,
hasAssignees,
missingAssignees,
missingSemanticTitle,
missingReviewers
Expand Down

0 comments on commit 36a98c4

Please sign in to comment.