Repository: DefinitelyTyped/dt-mergebot
Pull request #342 (2021-01-20 15:21:01)

Only delay if actually waiting for CI
Instead of waiting unconditionally for one minute after the last push, only wait if the CI result is actually "missing".

jablko: Thanks for reviewing, I addressed the comments and added the PR description to the commit message.

Patch:
diff --git a/src/compute-pr-actions.ts b/src/compute-pr-actions.ts
index 794c444..d8e1386 100644
--- a/src/compute-pr-actions.ts
+++ b/src/compute-pr-actions.ts
@@ -321,7 +321,14 @@ export function process(prInfo: BotResult,
     }
     // CI is missing
     else if (info.ciResult === "missing") {
-        label("Where is GH Actions?");
+        // This bot is faster than CI in coming back to give a response, and so the bot starts flipping between
+        // a 'where is CI'-ish state and a 'got CI deets' state. To work around this, we wait a
+        // minute since the last timeline push action before label/project states can be updated
+        if (dayjs(info.now).diff(info.lastPushDate, "minutes") >= 1) {
+            label("Where is GH Actions?");
+        } else {
+            delete context.targetColumn;
+        }
     }
     // CI is green
     else if (info.ciResult === "pass") {
@@ -355,13 +362,6 @@ export function process(prInfo: BotResult,
     // Timeline-related actions
     info.staleness?.doTimelineActions(context);
 
-    // This bot is faster than CI in coming back to give a response, and so the bot starts flipping between
-    // a 'where is CI'-ish state and a 'got CI deets' state. To work around this, we wait a
-    // minute since the last timeline push action before label/project states can be updated
-    const tooEarlyForLabelsOrProjects = dayjs(info.now).diff(info.lastPushDate, "minutes") < 1;
-    context.shouldUpdateLabels = !tooEarlyForLabelsOrProjects;
-    context.shouldUpdateProjectColumn = !tooEarlyForLabelsOrProjects;
-
     return context;
 }
 


Test patch:
diff --git a/src/_tests/fixtures/44343-pending-travis/mutations.json b/src/_tests/fixtures/44343-pending-travis/mutations.json
index d8e4093..854a140 100644
--- a/src/_tests/fixtures/44343-pending-travis/mutations.json
+++ b/src/_tests/fixtures/44343-pending-travis/mutations.json
@@ -1,4 +1,15 @@
 [
+  {
+    "mutation": "mutation ($input: RemoveLabelsFromLabelableInput!) {\n  removeLabelsFromLabelable(input: $input) {\n    __typename\n  }\n}\n",
+    "variables": {
+      "input": {
+        "labelIds": [
+          "MDU6TGFiZWwyMTU0ODU3ODAw"
+        ],
+        "labelableId": "MDExOlB1bGxSZXF1ZXN0NDEwODAzMTcz"
+      }
+    }
+  },
   {
     "mutation": "mutation ($input: UpdateIssueCommentInput!) {\n  updateIssueComment(input: $input) {\n    __typename\n  }\n}\n",
     "variables": {
diff --git a/src/_tests/fixtures/44343-pending-travis/result.json b/src/_tests/fixtures/44343-pending-travis/result.json
index 4b4abbd..909ba1e 100644
--- a/src/_tests/fixtures/44343-pending-travis/result.json
+++ b/src/_tests/fixtures/44343-pending-travis/result.json
@@ -13,7 +13,7 @@
   ],
   "shouldClose": false,
   "shouldMerge": false,
-  "shouldUpdateLabels": false,
-  "shouldUpdateProjectColumn": false,
+  "shouldUpdateLabels": true,
+  "shouldUpdateProjectColumn": true,
   "shouldRemoveFromActiveColumns": false
 }
diff --git a/src/_tests/fixtures/44343-pre-travis/mutations.json b/src/_tests/fixtures/44343-pre-travis/mutations.json
index d8e4093..854a140 100644
--- a/src/_tests/fixtures/44343-pre-travis/mutations.json
+++ b/src/_tests/fixtures/44343-pre-travis/mutations.json
@@ -1,4 +1,15 @@
 [
+  {
+    "mutation": "mutation ($input: RemoveLabelsFromLabelableInput!) {\n  removeLabelsFromLabelable(input: $input) {\n    __typename\n  }\n}\n",
+    "variables": {
+      "input": {
+        "labelIds": [
+          "MDU6TGFiZWwyMTU0ODU3ODAw"
+        ],
+        "labelableId": "MDExOlB1bGxSZXF1ZXN0NDEwODAzMTcz"
+      }
+    }
+  },
   {
     "mutation": "mutation ($input: UpdateIssueCommentInput!) {\n  updateIssueComment(input: $input) {\n    __typename\n  }\n}\n",
     "variables": {
diff --git a/src/_tests/fixtures/44343-pre-travis/result.json b/src/_tests/fixtures/44343-pre-travis/result.json
index 4b4abbd..909ba1e 100644
--- a/src/_tests/fixtures/44343-pre-travis/result.json
+++ b/src/_tests/fixtures/44343-pre-travis/result.json
@@ -13,7 +13,7 @@
   ],
   "shouldClose": false,
   "shouldMerge": false,
-  "shouldUpdateLabels": false,
-  "shouldUpdateProjectColumn": false,
+  "shouldUpdateLabels": true,
+  "shouldUpdateProjectColumn": true,
   "shouldRemoveFromActiveColumns": false
 }