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

Commit 5517b8c

Browse files
authored
Remove pr_number from BotError and BotEnsureRemovedFromProject (#343)
Update snapshots
1 parent d23a6aa commit 5517b8c

File tree

6 files changed

+10
-18
lines changed

6 files changed

+10
-18
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"type": "remove",
33
"now": "2020-04-30T19:01:56.000Z",
4-
"pr_number": 43960,
54
"message": "PR is not active",
65
"isDraft": false
76
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"type": "remove",
33
"now": "2020-04-28T22:49:39.000Z",
4-
"pr_number": 44105,
5-
"message": "PR is not active",
6-
"isDraft": false
4+
"message": "PR is not active"
75
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"type": "remove",
33
"now": "2020-04-30T19:07:55.000Z",
4-
"pr_number": 44256,
54
"message": "PR is not active",
65
"isDraft": false
76
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"type": "remove",
33
"now": "2020-04-28T16:41:44.000Z",
4-
"pr_number": 44290,
54
"message": "PR is a draft",
65
"isDraft": true
76
}

src/_tests/fixtures/45982/derived.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
"type": "error",
33
"now": "2020-07-11T20:41:49.000Z",
44
"message": "error parsing owners: At 1:1 : Expected /\\/\\/ Type definitions for (non-npm package )?/",
5-
"pr_number": 45982,
65
"author": "dasa"
76
}

src/pr-info.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@ export type PopularityLevel =
3030
interface BotError {
3131
readonly type: "error";
3232
readonly now: Date;
33-
readonly pr_number: number;
3433
readonly message: string;
3534
readonly author: string | undefined;
3635
}
3736

3837
interface BotEnsureRemovedFromProject {
3938
readonly type: "remove";
4039
readonly now: Date;
41-
readonly pr_number: number;
4240
readonly message: string;
4341
readonly isDraft: boolean;
4442
}
@@ -185,13 +183,13 @@ export async function deriveStateForPR(
185183
getDownloads = getMonthlyDownloadCount,
186184
now = new Date(),
187185
): Promise<BotResult> {
188-
if (prInfo.author == null) return botError(prInfo.number, "PR author does not exist");
186+
if (prInfo.author == null) return botError("PR author does not exist");
189187

190-
if (prInfo.isDraft) return botEnsureRemovedFromProject(prInfo.number, "PR is a draft", true);
191-
if (prInfo.state !== PullRequestState.OPEN) return botEnsureRemovedFromProject(prInfo.number, "PR is not active", false);
188+
if (prInfo.isDraft) return botEnsureRemovedFromProject("PR is a draft");
189+
if (prInfo.state !== PullRequestState.OPEN) return botEnsureRemovedFromProject("PR is not active");
192190

193191
const headCommit = getHeadCommit(prInfo);
194-
if (headCommit == null) return botError(prInfo.number, "No head commit found");
192+
if (headCommit == null) return botError("No head commit found");
195193

196194
const author = prInfo.author.login;
197195
const isFirstContribution = prInfo.authorAssociation === CommentAuthorAssociation.FIRST_TIME_CONTRIBUTOR;
@@ -207,7 +205,7 @@ export async function deriveStateForPR(
207205
const pkgInfoEtc = await getPackageInfosEtc(
208206
noNullish(prInfo.files?.nodes).map(f => f.path).sort(),
209207
prInfo.headRefOid, fetchFile, async name => await getDownloads(name, lastPushDate));
210-
if (pkgInfoEtc instanceof Error) return botError(prInfo.number, pkgInfoEtc.message);
208+
if (pkgInfoEtc instanceof Error) return botError(pkgInfoEtc.message);
211209
const { pkgInfo, popularityLevel } = pkgInfoEtc;
212210

213211
const reviews = getReviews(prInfo);
@@ -236,12 +234,12 @@ export async function deriveStateForPR(
236234
...getCIResult(headCommit.checkSuites)
237235
};
238236

239-
function botError(pr_number: number, message: string): BotError {
240-
return { type: "error", now, message, pr_number, author: prInfo.author?.login };
237+
function botError(message: string): BotError {
238+
return { type: "error", now, message, author: prInfo.author?.login };
241239
}
242240

243-
function botEnsureRemovedFromProject(pr_number: number, message: string, isDraft: boolean): BotEnsureRemovedFromProject {
244-
return { type: "remove", now, pr_number, message, isDraft };
241+
function botEnsureRemovedFromProject(message: string): BotEnsureRemovedFromProject {
242+
return { type: "remove", now, message, isDraft: prInfo.isDraft };
245243
}
246244
}
247245

0 commit comments

Comments
 (0)