Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit 39247a9

Browse files
committed
Some minor leftover tweaks
Remove some unused code & imports, use a new `sameUser` utility to compare usernames, fix a big.
1 parent e63d3df commit 39247a9

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/compute-pr-actions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as Comments from "./comments";
22
import { PrInfo, BotError, BotEnsureRemovedFromProject, BotNoPackages } from "./pr-info";
33
import { CIResult } from "./util/CIResult";
4-
import { PackageInfo, ReviewInfo } from "./pr-info";
5-
import { noNulls, flatten, unique } from "./util/util";
4+
import { ReviewInfo } from "./pr-info";
5+
import { noNulls, flatten, unique, sameUser } from "./util/util";
66

77
type ColumnName =
88
| "Needs Maintainer Action"
@@ -142,12 +142,12 @@ interface ExtendedPrInfo extends PrInfo {
142142
}
143143
function extendPrInfo(info: PrInfo): ExtendedPrInfo {
144144
const reviewLink = uriForReview.replace(/{}/, ""+info.pr_number);
145-
const authorIsOwner = info.pkgInfo.every(p => p.owners && p.owners.map(o => o.toLowerCase()).includes(info.author.toLowerCase()));
145+
const authorIsOwner = info.pkgInfo.every(p => p.owners && p.owners.some(o => sameUser(o, info.author)));
146146
const editsInfra = info.pkgInfo.some(p => p.name === null);
147147
const editsConfig = info.pkgInfo.some(p => p.files.some(f => f.kind === "package-meta"));
148148
const allOwners = unique(flatten(info.pkgInfo.map(p => p.owners || [])));
149-
const otherOwners = allOwners.filter(o => info.author.toLowerCase() !== o.toLowerCase());
150-
const noOtherOwners = !allOwners.some(o => o.toLowerCase() !== info.author.toLowerCase());
149+
const otherOwners = allOwners.filter(o => !sameUser(o, info.author));
150+
const noOtherOwners = !allOwners.some(o => !sameUser(o, info.author));
151151
const tooManyOwners = allOwners.length > 50;
152152
const packages = noNulls(info.pkgInfo.map(p => p.name));
153153
const hasMultiplePackages = packages.length > 1;

src/pr-info.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { getMonthlyDownloadCount } from "./util/npm";
1616
import { client } from "./graphql-client";
1717
import { ApolloQueryResult } from "apollo-boost";
1818
import { fetchFile as defaultFetchFile } from "./util/fetchFile";
19-
import { noNulls, notUndefined, findLast, forEachReverse, daysSince, authorNotBot, latestDate, earliestDate
19+
import { noNulls, notUndefined, findLast, forEachReverse, daysSince, sameUser, authorNotBot, latestDate, earliestDate
2020
} from "./util/util";
2121
import * as HeaderParser from "definitelytyped-header-parser";
2222
import * as jsonDiff from "fast-json-patch";
@@ -211,7 +211,7 @@ export async function deriveStateForPR(
211211
const lastBlessing = getLastMaintainerBlessingDate(prInfo.timelineItems);
212212
const reopenedDate = getReopenedDate(prInfo.timelineItems);
213213
const now = getNow().toISOString();
214-
const reviews = getReviews(prInfo, isOwner);
214+
const reviews = getReviews(prInfo);
215215
const latestReview = latestDate(...reviews.map(r => r.date));
216216
const firstApprovalDate = earliestDate(...reviews.map(r => r.type === "approved" ? r.date : undefined));
217217
const stalenessInDays = daysSince(latestDate(createdDate, lastPushDate, lastCommentDate, lastBlessing, reopenedDate, latestReview) || lastPushDate, now);
@@ -253,10 +253,6 @@ export async function deriveStateForPR(
253253
function botNoPackages(pr_number: number): BotNoPackages {
254254
return { type: "no_packages", pr_number };
255255
}
256-
257-
function isOwner(login: string) {
258-
return pkgInfo.some(p => p.owners?.some(k => k.toLowerCase() === login.toLowerCase()));
259-
}
260256
}
261257

262258
type ReopenedEvent = PR_repository_pullRequest_timelineItems_nodes_ReopenedEvent;
@@ -436,7 +432,7 @@ function usersSayReadyToMerge(comments: PR_repository_pullRequest_comments_nodes
436432
&& (new Date(comment.createdAt)).getTime() > sinceDate.getTime());
437433
}
438434

439-
function getReviews(prInfo: PR_repository_pullRequest, isOwner: (name: string) => boolean) {
435+
function getReviews(prInfo: PR_repository_pullRequest) {
440436
if (!prInfo.reviews?.nodes) return [];
441437
const headCommitOid: string = prInfo.headRefOid;
442438
const reviews: ReviewInfo[] = [];
@@ -448,7 +444,7 @@ function getReviews(prInfo: PR_repository_pullRequest, isOwner: (name: string) =
448444
// Skip self-reviews
449445
if (reviewer === prInfo.author!.login) continue;
450446
// Only look at the most recent review per person (ignoring pending/commented)
451-
if (reviews.find(r => r.reviewer.toLowerCase() === reviewer.toLowerCase())) continue;
447+
if (reviews.find(r => sameUser(r.reviewer, reviewer))) continue;
452448
// collect reviews by type
453449
if (r.commit.oid !== headCommitOid) {
454450
reviews.push({ type: "stale", reviewer, date, abbrOid: r.commit.abbreviatedOid });

src/util/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export function daysSince(date: Date, now: Date | string): number {
6464
return Math.floor(moment(now).diff(moment(date), "days"));
6565
}
6666

67+
export function sameUser(u1: string, u2: string) {
68+
return u1.toLowerCase() === u2.toLowerCase();
69+
}
70+
6771
export function authorNotBot(node: { login: string } | { author?: { login: string } | null} | { actor?: { login: string } | null}): boolean {
6872
return ("author" in node && node.author!.login !== "typescript-bot")
6973
|| ("actor" in node && node.actor!.login !== "typescript-bot")

0 commit comments

Comments
 (0)