Skip to content

Commit

Permalink
chore: fixed knip
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Oct 2, 2024
1 parent 3326c7c commit 86f0268
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/handlers/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface ResultInfo {

function generateGitHubSummary(context: Context, urls: ResultInfo[]): string {
const target = `https://github.com/${context.payload.repository.owner?.login}`;
const output: string[] = ["## Merge report\n\n"];
const output: (string | undefined)[] = ["## Merge report\n\n"];
output.push("<samp>\n");
output.push("| Merged | ID |");
output.push("|---|---|");
Expand All @@ -29,9 +29,9 @@ function generateGitHubSummary(context: Context, urls: ResultInfo[]): string {
output.push("\n</samp>\n");
output.push("## Configuration\n\n");
output.push("### Watching Repositories\n\n");
output.push(context.config.repos.monitor.map((o) => `- [${o}](${target}/${o})`).join("\n"));
output.push(context.config.repos?.monitor.map((o) => `- [${o}](${target}/${o})`).join("\n"));
output.push("### Ignored Repositories\n\n");
output.push(context.config.repos.ignore.map((o) => `- [${o}](${target}/${o})`).join("\n"));
output.push(context.config.repos?.ignore.map((o) => `- [${o}](${target}/${o})`).join("\n"));
return output.join("\n");
}

Expand Down
18 changes: 10 additions & 8 deletions src/helpers/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@ export interface Requirements {
* Gets the merge timeout depending on the status of the assignee. If there are multiple assignees with different
* statuses, the longest timeout is chosen.
*/
export async function getMergeTimeoutAndApprovalRequiredCount(context: Context, authorAssociation: string): Promise<Requirements> {
const { config: { mergeTimeout, approvalsRequired } } = context;
export async function getMergeTimeoutAndApprovalRequiredCount(context: Context, authorAssociation: string) {
const {
config: { mergeTimeout, approvalsRequired },
} = context;
const timeoutCollaborator = {
mergeTimeout: mergeTimeout.collaborator,
requiredApprovalCount: approvalsRequired.collaborator,
mergeTimeout: mergeTimeout?.collaborator,
requiredApprovalCount: approvalsRequired?.collaborator,
};
const timeoutContributor = {
mergeTimeout: mergeTimeout.contributor,
requiredApprovalCount: approvalsRequired.contributor,
mergeTimeout: mergeTimeout?.contributor,
requiredApprovalCount: approvalsRequired?.contributor,
};

/**
* Hardcoded roles here because we need to determine the timeouts
* separate from `allowedReviewerRoles` which introduces
* separate from `allowedReviewerRoles` which introduces
* potential unintended user errors and logic issues.
*/
return ["COLLABORATOR", "MEMBER", "OWNER"].includes(authorAssociation) ? timeoutCollaborator : timeoutContributor;
Expand All @@ -49,7 +51,7 @@ export async function getApprovalCount({ octokit, logger, config: { allowedRevie
repo,
pull_number: pullNumber,
});
return reviews.filter((review) => allowedReviewerRoles.includes(review.author_association)).filter((review) => review.state === "APPROVED").length;
return reviews.filter((review) => allowedReviewerRoles?.includes(review.author_association)).filter((review) => review.state === "APPROVED").length;
} catch (e) {
logger.error(`Error fetching reviews' approvals: ${e}`);
return 0;
Expand Down
16 changes: 11 additions & 5 deletions src/helpers/update-pull-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RestEndpointMethodTypes } from "@octokit/rest";
import ms from "ms";
import { getAllTimelineEvents } from "../handlers/github-events";
import { generateSummary, ResultInfo } from "../handlers/summary";
import { Context } from "../types";
import { Context, ReposWatchSettings } from "../types";
import {
getApprovalCount,
getMergeTimeoutAndApprovalRequiredCount,
Expand Down Expand Up @@ -30,7 +30,7 @@ export async function updatePullRequests(context: Context) {
const { logger } = context;
const results: ResultInfo[] = [];

if (!context.config.repos.monitor.length) {
if (!context.config.repos?.monitor.length) {
const owner = context.payload.repository.owner;
if (owner) {
logger.info(`No organizations or repo have been specified, will default to the organization owner: ${owner.login}.`);
Expand All @@ -39,7 +39,7 @@ export async function updatePullRequests(context: Context) {
}
}

const pullRequests = await getOpenPullRequests(context, context.config.repos);
const pullRequests = await getOpenPullRequests(context, context.config.repos as ReposWatchSettings);

if (!pullRequests?.length) {
return logger.info("Nothing to do.");
Expand Down Expand Up @@ -74,8 +74,14 @@ export async function updatePullRequests(context: Context) {
);
if (isNaN(lastActivityDate.getTime())) {
logger.info(`PR ${html_url} does not seem to have any activity, nothing to do.`);
} else if (isPastOffset(lastActivityDate, requirements.mergeTimeout)) {
isMerged = await attemptMerging(context, { gitHubUrl, htmlUrl: html_url, requirements, lastActivityDate, pullRequestDetails });
} else if (requirements?.mergeTimeout && isPastOffset(lastActivityDate, requirements?.mergeTimeout)) {
isMerged = await attemptMerging(context, {
gitHubUrl,
htmlUrl: html_url,
requirements: requirements as Requirements,
lastActivityDate,
pullRequestDetails,
});
} else {
logger.info(`PR ${html_url} has activity up until (${lastActivityDate}), nothing to do.`);
}
Expand Down
9 changes: 0 additions & 9 deletions src/update-configuration.ts

This file was deleted.

0 comments on commit 86f0268

Please sign in to comment.