[llvm] [workflows] issue-write: Avoid race condition when PR branch is deleted (PR #87118)

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 29 15:14:33 PDT 2024


https://github.com/tstellar created https://github.com/llvm/llvm-project/pull/87118

Fixes #87102 .

>From 20151fcb159fc6cc143a1fbfafcc82d1d06183fe Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Fri, 29 Mar 2024 15:12:58 -0700
Subject: [PATCH] [workflows] issue-write: Avoid race condition when PR branch
 is deleted

---
 .github/workflows/issue-write.yml | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/.github/workflows/issue-write.yml b/.github/workflows/issue-write.yml
index 02a5f7c213e898..cb5a96caf8e91e 100644
--- a/.github/workflows/issue-write.yml
+++ b/.github/workflows/issue-write.yml
@@ -77,6 +77,15 @@ jobs:
             }
             const gql_result = await github.graphql(gql_query, gql_variables);
             console.log(gql_result);
+            // If the branch for the PR was deleted before this job has a chance
+            // to run, then the ref will be null.  This can happen if someone:
+            // 1. Rebase the PR, which triggers some workflow.
+            // 2. Immediately merges the PR and deletes the branch.
+            // 3. The workflow finishes and triggers this job.
+            if (!gql_result.repository.ref) {
+              console.log("Ref has been deleted");
+              return;
+            }
             console.log(gql_result.repository.ref.associatedPullRequests.nodes);
 
             var pr_number = 0;



More information about the llvm-commits mailing list