You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2020/12/27 13:57:25 UTC

[airflow-label-when-approved] 09/09: Turns missing pr in workflow_run into warning. (#5)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow-label-when-approved.git

commit 4c5190fec5661e98d83f50bbd4ef9ebb48bd1194
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Sun Nov 1 11:44:43 2020 +0100

    Turns missing pr in workflow_run into warning. (#5)
    
    * Turns missing pr in workflow_run into warning.
    
    Sometimes (quite often really) when PR gets approved, the PR
    gets merged rather quickly, without waiting for result of this
    action. Or a new PR gets pushed quickly. In those cases PR will
    not be found. But this is usually not a problem then and rather
    than failing, we should simply print a warning and exit.
    
    * fixup! Turns missing pr in workflow_run into warning.
    
    Co-authored-by: Tobiasz Kędzierski <to...@polidea.com>
---
 dist/index.js |  9 +++++++--
 src/main.ts   | 10 +++++++---
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/dist/index.js b/dist/index.js
index 8e040f7..081b94d 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1625,9 +1625,14 @@ function run() {
         }
         else if (eventName === 'workflow_run') {
             if (pullRequestNumberInput === 'not set') {
-                throw Error(`If action is triggered by "workflow_run" then input "pullRequestNumber" is required.`);
+                core.warning(`If action is triggered by "workflow_run" then input "pullRequestNumber" is required.\n` +
+                    `It might be missing because the pull request might have been already merged or a fixup pushed to` +
+                    `the PR branch. None of the outputs will be set as we cannot find the right PR.`);
+                return;
+            }
+            else {
+                pullRequestNumber = parseInt(pullRequestNumberInput);
             }
-            pullRequestNumber = parseInt(pullRequestNumberInput);
         }
         else {
             throw Error(`This action is only useful in "pull_request_review" or "workflow_run" triggered runs and you used it in "${eventName}"`);
diff --git a/src/main.ts b/src/main.ts
index f7b61d6..d9d012c 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -211,11 +211,15 @@ async function run(): Promise<void> {
     }
   } else if (eventName === 'workflow_run') {
     if (pullRequestNumberInput === 'not set') {
-      throw Error(
-        `If action is triggered by "workflow_run" then input "pullRequestNumber" is required.`
+      core.warning(
+        `If action is triggered by "workflow_run" then input "pullRequestNumber" is required.\n` +
+          `It might be missing because the pull request might have been already merged or a fixup pushed to` +
+          `the PR branch. None of the outputs will be set as we cannot find the right PR.`
       )
+      return
+    } else {
+      pullRequestNumber = parseInt(pullRequestNumberInput)
     }
-    pullRequestNumber = parseInt(pullRequestNumberInput)
   } else {
     throw Error(
       `This action is only useful in "pull_request_review" or "workflow_run" triggered runs and you used it in "${eventName}"`