Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: pgEdge/control-plane
Length of output: 208
🏁 Script executed:
Repository: pgEdge/control-plane
Length of output: 1645
🌐 Web query:
GitHub Actions pull_request closed head ref source branch deleted after merge documentation💡 Result:
When a pull request is merged, GitHub automatically closes it [1]. Whether the head branch is deleted after a merge depends on your repository settings, not the GitHub Actions event itself [2]. GitHub provides an "Automatically delete head branches" setting in repository general settings that, when enabled, will delete the source branch once the pull request is merged. Regarding GitHub Actions and GITHUB_REF during this event: 1. GITHUB_REF Behavior: When a pull request is closed (with or without a merge), you can use the pull_request event with the closed activity type to trigger a workflow [1]. It is important to note that the value of GITHUB_REF changes based on whether the pull request was merged [3][4][1]. - If the pull request is closed but not merged, GITHUB_REF is set to refs/pull/PULL_REQUEST_NUMBER/merge [3][4][1]. - If the pull request is merged, GITHUB_REF is set to the fully qualified ref of the branch it was merged into (e.g., refs/heads/main) [3][4][1]. 2. Accessing Source Branch Information: Because GITHUB_REF may not point to your source branch after a merge, relying on it to perform cleanup tasks can lead to errors [5]. To safely identify the pull request information or access the source branch (if it still exists), you should use the context object provided by the event payload, such as ${{ github.event.pull_request.head.sha }} or ${{ github.event.pull_request.number }} [5][6]. 3. Branch Deletion: If you are writing a workflow to handle post-merge cleanup, ensure your logic does not assume GITHUB_REF is the head branch [5]. If the branch has already been deleted by GitHub's automatic cleanup, attempting to check out the head branch by name may fail unless you use fallback mechanisms, such as accessing the ref via refs/pull/NUMBER/head, which GitHub may keep available for a period [7].
Citations:
🌐 Web query:
GitHub Actions pull_request closed event github.sha after merge squash rebase merge documentation💡 Result:
In GitHub Actions, the value of github.sha (and the GITHUB_SHA environment variable) for a pull_request event is the SHA of the temporary merge commit created by GitHub to simulate the pull request merge [1][2]. This behavior applies to the closed event as well [2][3]. Key points regarding the behavior of github.sha: 1. Temporary Merge Commit: For pull_request events, GitHub creates a surrogate merge commit representing the state of the pull request's head branch merged into the base branch [4][5][6]. The github.sha variable points to this specific commit [1][2]. 2. Independence of Merge Strategy: Because github.sha points to this temporary test merge commit, its value is generally consistent regardless of whether you ultimately use squash, rebase, or standard merge strategies to complete the pull request [7]. However, the actual merge commit created on your target branch after a squash or rebase will be a different, permanent commit [7]. 3. Retrieving the Head Commit: If you need the SHA of the actual latest commit from the pull request's head branch (rather than the test merge commit), you should use the context variable: ${{ github.event.pull_request.head.sha }} [1][5][2]. 4. Behavior on Closed Event: When a pull request is closed, the github.sha continues to represent the last known merge commit of the pull request merge branch [1][2]. If the pull request was merged, GITHUB_REF will point to the fully qualified reference of the target branch (e.g., refs/heads/main), but github.sha will still correspond to that last temporary merge commit [1][2]. For workflows that need to perform operations based on the actual head of the feature branch, always prefer github.event.pull_request.head.sha to ensure accuracy [8][5][9].
Citations:
github.shain other events thanpushgithub/docs#30093Use the merged branch ref instead of the PR source branch.
pull_requestclosed events run after the PR is merged, butgithub.shastill points to the PR’s temporary merge commit for squash and rebase merges. Check outgithub.refso the tag points at the branch that received the merged changes instead of the PR source branch.Proposed fix
🤖 Prompt for AI Agents