Skip to content

fix: checkout merge commit for merged PRs in auto-tag workflow - #806

Open
hudeng-go wants to merge 1 commit into
linuxdeepin:masterfrom
hudeng-go:fix/auto-tag-merged-checkout
Open

fix: checkout merge commit for merged PRs in auto-tag workflow#806
hudeng-go wants to merge 1 commit into
linuxdeepin:masterfrom
hudeng-go:fix/auto-tag-merged-checkout

Conversation

@hudeng-go

@hudeng-go hudeng-go commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

问题

当 PR 来自 fork 且合并后 fork 分支被删除时,auto-tag workflow 的 actions/checkout@v7 步骤会失败,因为:

  1. PR 被合并后,workflow 由 pull_request_target: closed 触发
  2. ref: refs/heads/${{ github.event.pull_request.head.ref }} 指向 fork 中的分支
  3. fork 的分支在 merge 后被删除,checkout 无法找到该 ref
  4. repository: ${{ github.event.pull_request.head.repo.full_name }} 指向 fork 而非 base repo

修复

actions/checkout@v7 中增加条件判断:

  • PR 已合并(merged=true):从 base repo(github.event.repository.full_name)检出 merge_commit_sha,该 commit 永久存在于 base repo 中
  • PR 未合并(opened/synchronize):保持原有行为,从 fork 检出分支 ref

变更文件

文件 修改处数
.github/workflows/auto-tag.yml 1

相关 Issue

Summary by Sourcery

Bug Fixes:

  • Ensure the auto-tag workflow can check out merged pull requests even when the source fork branch has been deleted.

When a PR is merged from a fork and the fork branch is subsequently deleted, the auto-tag workflow fails at actions/checkout@v7 because it tries to fetch refs/heads/<branch> from the fork repository which no longer exists.

Fix by conditionally using merge_commit_sha from the base repo when the PR is merged, and falling back to the branch ref from the fork repository when the PR is still open.
@sourcery-ai

sourcery-ai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the auto-tag GitHub Actions workflow to correctly checkout merged pull requests from the base repository’s merge commit when the PR branch in a fork has been deleted, while preserving existing behavior for unmerged PRs.

File-Level Changes

Change Details Files
Adjust auto-tag workflow checkout logic to handle merged PRs from forks whose branches may be deleted.
  • Replace the static head ref with a conditional ref that uses the PR merge commit SHA when the PR is merged, otherwise falls back to the original head ref format.
  • Change the repository selection to use the base repository for merged PRs while continuing to use the PR head repository for unmerged PRs.
  • Keep existing checkout safety options (allow-unsafe-pr-checkout, persist-credentials) unchanged to maintain security behavior.
.github/workflows/auto-tag.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider adding a fallback for cases where github.event.pull_request.merge_commit_sha is null or empty (e.g. squash/rebase merges), so the ref expression doesn’t resolve to an invalid value and cause checkout failures (for example falling back to github.sha).
  • You could tighten the security posture by only setting allow-unsafe-pr-checkout: true when actually checking out from the fork (non-merged case), and disabling it when checking out the merge commit from the base repository.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding a fallback for cases where `github.event.pull_request.merge_commit_sha` is null or empty (e.g. squash/rebase merges), so the `ref` expression doesn’t resolve to an invalid value and cause checkout failures (for example falling back to `github.sha`).
- You could tighten the security posture by only setting `allow-unsafe-pr-checkout: true` when actually checking out from the fork (non-merged case), and disabling it when checking out the merge commit from the base repository.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hudeng-go, wineee

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants