Repository: DefinitelyTyped/dt-mergebot
Pull request #343 (2021-01-20 16:45:56)

Remove pr_number from BotError and BotEnsureRemovedFromProject
Like #339, not used.


Patch:
diff --git a/package.json b/package.json
index c12ba63..722c2ea 100644
--- a/package.json
+++ b/package.json
@@ -17,26 +17,25 @@
   },
   "dependencies": {
     "@apollo/client": "^3.3.6",
-    "@azure/functions": "^1.2.2",
     "@definitelytyped/header-parser": "^0.0.64",
-    "@octokit/graphql-schema": "^10.11.0",
     "@octokit/webhooks": "^7.21.0",
-    "@types/node": "latest",
-    "@types/node-fetch": "^2.5.7",
-    "@types/prettyjson": "^0.0.29",
     "dayjs": "^1.10.3",
     "fast-json-patch": "^3.0.0-1",
     "fs-extra": "^9.0.1",
     "graphql": "^14.5.8",
     "node-fetch": "^2.6.1",
     "prettyjson": "^1.2.1",
-    "typescript": "^4.1.3",
     "yargs": "^16.2.0"
   },
   "devDependencies": {
+    "@azure/functions": "^1.2.2",
     "@endemolshinegroup/cosmiconfig-typescript-loader": "^3.0.2",
+    "@octokit/graphql-schema": "^10.11.0",
     "@types/fs-extra": "^4.0.11",
     "@types/jest": "^26.0.20",
+    "@types/node": "latest",
+    "@types/node-fetch": "^2.5.7",
+    "@types/prettyjson": "^0.0.29",
     "@typescript-eslint/eslint-plugin": "^4.9.0",
     "@typescript-eslint/parser": "^4.9.0",
     "apollo": "^2.32.0",
@@ -44,7 +43,8 @@
     "eslint-plugin-unicorn": "^26.0.1",
     "jest": "^26.4.4",
     "jest-file-snapshot": "^0.3.8",
-    "ts-jest": "^26.4.4"
+    "ts-jest": "^26.4.4",
+    "typescript": "^4.1.3"
   },
   "scripts": {
     "prepublishOnly": "npm run build",
diff --git a/src/pr-info.ts b/src/pr-info.ts
index 59cd97a..17a27a1 100644
--- a/src/pr-info.ts
+++ b/src/pr-info.ts
@@ -30,7 +30,6 @@ export type PopularityLevel =
 interface BotError {
     readonly type: "error";
     readonly now: Date;
-    readonly pr_number: number;
     readonly message: string;
     readonly author: string | undefined;
 }
@@ -38,7 +37,6 @@ interface BotError {
 interface BotEnsureRemovedFromProject {
     readonly type: "remove";
     readonly now: Date;
-    readonly pr_number: number;
     readonly message: string;
     readonly isDraft: boolean;
 }
@@ -185,13 +183,13 @@ export async function deriveStateForPR(
     getDownloads = getMonthlyDownloadCount,
     now = new Date(),
 ): Promise<BotResult>  {
-    if (prInfo.author == null) return botError(prInfo.number, "PR author does not exist");
+    if (prInfo.author == null) return botError("PR author does not exist");
 
-    if (prInfo.isDraft) return botEnsureRemovedFromProject(prInfo.number, "PR is a draft", true);
-    if (prInfo.state !== PullRequestState.OPEN) return botEnsureRemovedFromProject(prInfo.number, "PR is not active", false);
+    if (prInfo.isDraft) return botEnsureRemovedFromProject("PR is a draft");
+    if (prInfo.state !== PullRequestState.OPEN) return botEnsureRemovedFromProject("PR is not active");
 
     const headCommit = getHeadCommit(prInfo);
-    if (headCommit == null) return botError(prInfo.number, "No head commit found");
+    if (headCommit == null) return botError("No head commit found");
 
     const author = prInfo.author.login;
     const isFirstContribution = prInfo.authorAssociation === CommentAuthorAssociation.FIRST_TIME_CONTRIBUTOR;
@@ -207,7 +205,7 @@ export async function deriveStateForPR(
     const pkgInfoEtc = await getPackageInfosEtc(
         noNullish(prInfo.files?.nodes).map(f => f.path).sort(),
         prInfo.headRefOid, fetchFile, async name => await getDownloads(name, lastPushDate));
-    if (pkgInfoEtc instanceof Error) return botError(prInfo.number, pkgInfoEtc.message);
+    if (pkgInfoEtc instanceof Error) return botError(pkgInfoEtc.message);
     const { pkgInfo, popularityLevel } = pkgInfoEtc;
 
     const reviews = getReviews(prInfo);
@@ -236,12 +234,12 @@ export async function deriveStateForPR(
         ...getCIResult(headCommit.checkSuites)
     };
 
-    function botError(pr_number: number, message: string): BotError {
-        return { type: "error", now, message, pr_number, author: prInfo.author?.login };
+    function botError(message: string): BotError {
+        return { type: "error", now, message, author: prInfo.author?.login };
     }
 
-    function botEnsureRemovedFromProject(pr_number: number, message: string, isDraft: boolean): BotEnsureRemovedFromProject {
-        return { type: "remove", now, pr_number, message, isDraft };
+    function botEnsureRemovedFromProject(message: string): BotEnsureRemovedFromProject {
+        return { type: "remove", now, message, isDraft: prInfo.isDraft };
     }
 }
 


Test patch:
diff --git a/src/_tests/fixtures/43960-post-close/derived.json b/src/_tests/fixtures/43960-post-close/derived.json
index 4763775..eee3c8f 100644
--- a/src/_tests/fixtures/43960-post-close/derived.json
+++ b/src/_tests/fixtures/43960-post-close/derived.json
@@ -1,7 +1,6 @@
 {
   "type": "remove",
   "now": "2020-04-30T19:01:56.000Z",
-  "pr_number": 43960,
   "message": "PR is not active",
   "isDraft": false
 }
diff --git a/src/_tests/fixtures/44105/derived.json b/src/_tests/fixtures/44105/derived.json
index 0fe0f68..decb965 100644
--- a/src/_tests/fixtures/44105/derived.json
+++ b/src/_tests/fixtures/44105/derived.json
@@ -1,7 +1,5 @@
 {
   "type": "remove",
   "now": "2020-04-28T22:49:39.000Z",
-  "pr_number": 44105,
-  "message": "PR is not active",
-  "isDraft": false
+  "message": "PR is not active"
 }
diff --git a/src/_tests/fixtures/44256/derived.json b/src/_tests/fixtures/44256/derived.json
index 562305a..d751a9e 100644
--- a/src/_tests/fixtures/44256/derived.json
+++ b/src/_tests/fixtures/44256/derived.json
@@ -1,7 +1,6 @@
 {
   "type": "remove",
   "now": "2020-04-30T19:07:55.000Z",
-  "pr_number": 44256,
   "message": "PR is not active",
   "isDraft": false
 }
diff --git a/src/_tests/fixtures/44290/derived.json b/src/_tests/fixtures/44290/derived.json
index cbf0317..c42988c 100644
--- a/src/_tests/fixtures/44290/derived.json
+++ b/src/_tests/fixtures/44290/derived.json
@@ -1,7 +1,6 @@
 {
   "type": "remove",
   "now": "2020-04-28T16:41:44.000Z",
-  "pr_number": 44290,
   "message": "PR is a draft",
   "isDraft": true
 }
diff --git a/src/_tests/fixtures/45982/derived.json b/src/_tests/fixtures/45982/derived.json
index 8a17a85..77108b8 100644
--- a/src/_tests/fixtures/45982/derived.json
+++ b/src/_tests/fixtures/45982/derived.json
@@ -2,6 +2,5 @@
   "type": "error",
   "now": "2020-07-11T20:41:49.000Z",
   "message": "error parsing owners: At 1:1 : Expected /\\/\\/ Type definitions for (non-npm package )?/",
-  "pr_number": 45982,
   "author": "dasa"
 }