Skip to content

[auto-backport] Assign backport PRs to the original PR author or merger - #21379

Merged
mrodm merged 4 commits into
elastic:mainfrom
mrodm:add_assignee_apply_backport
Sep 18, 2026
Merged

mrodm merged 4 commits into
elastic:mainfrom
mrodm:add_assignee_apply_backport

Conversation

@mrodm

@mrodm mrodm commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Proposed commit message

[auto-backport] Assign backport PRs to the original PR author or merger

When the auto-backport workflow opens a PR targeting a backport branch,
resolve the assignee from the source PR that was merged into main using
the same logic introduced for sync-changelog PRs in #21243:

  1. Use the PR author if they are not a bot and have repo write access.
  2. Fall back to whoever merged the PR if the author doesn't qualify (also
    checked for write access to guard against revoked access post-merge).
  3. Omit --assignee entirely if neither qualifies, so PR creation is not
    blocked.

Resolution logic is centralised in a new cmd/backport/assign package
(PRActor, Resolve, Pick) shared by both the apply and changelog/sync
code paths, eliminating the duplication that existed between them.

The workflow passes the original PR number via --origin-pr-number through
backport_apply.sh to the backport binary, which performs the two API
calls (gh pr view + collaborator permission check) internally.
assign.Resolve is guarded by OpenPR && !DryRun to avoid redundant API
calls in non-PR paths.

Author's Checklist

  • assign.Pick is covered by unit tests (TestPick) including bot-author, external-contributor, revoked-access merger, and both-bots scenarios.
  • Verified that assign.Resolve is only called when OpenPR && !DryRun to avoid redundant GitHub API calls.
  • Both sync.go and apply.go now delegate to assign.Resolve/assign.Pick — no local duplicate definitions remain.

Related issues


This PR was generated with the assistance of Claude (claude-sonnet-4-6).

🤖 Generated with Claude Code

mrodm and others added 4 commits September 17, 2026 12:00
When the auto-backport workflow opens a PR targeting a backport branch,
resolve the assignee from the source PR that was merged into main:

- Use the PR author if they are not a bot and have repo write access.
- Fall back to whoever merged the PR if the author doesn't qualify.
- Omit --assignee entirely if neither qualifies, so PR creation is not
  blocked.

Resolution logic lives in Go (apply.go: resolveAssignee/pickAssignee),
mirroring the approach introduced in sync.go for changelog-sync PRs.

The workflow passes the original PR number via --origin-pr-number through
backport_apply.sh to the backport binary, which performs the two API
calls (gh pr view + collaborator permission check) internally.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move the duplicated prActor/resolveAssignee/pickAssignee logic from
changelog/sync.go and apply/apply.go into a new cmd/backport/assign
package with exported PRActor, Resolve, and Pick symbols.

Both callers now import assign.Resolve and assign.Pick. The canonical
unit tests live in assign/assign_test.go; the redundant TestPickAssignee
copies in sync_test.go and apply_test.go are removed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Guard assign.Resolve behind opts.OpenPR to avoid redundant GitHub API
  calls when --open-pr is not set.
- Document the PR_NUMBER optional env var in the process-checked-branches.sh
  header comment.
- Add a comment to assign.Pick explaining why the mergedBy fallback skips
  the write-access check (GitHub requires write permission to merge).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Check hasWriteAccess for mergedBy in assign.Pick: a login that lost
  repo access after merging would cause gh pr create --assignee to fail
  and abort backport PR creation. Both author and mergedBy paths now
  verify write access before returning the login.
- Skip assign.Resolve during DryRun (guard is now OpenPR && !DryRun):
  the resolved assignee is never consumed in a dry run, so the two
  GitHub API calls were wasted.
- Update TestPick: use a login-selective predicate for the external-
  contributor case, and add a case covering a revoked-access merger.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mrodm mrodm self-assigned this Sep 17, 2026
@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

💚 Build Succeeded

cc @mrodm

@mrodm
mrodm marked this pull request as ready for review September 17, 2026 14:35
@mrodm
mrodm requested a review from a team as a code owner September 17, 2026 14:35
Copilot AI lite review requested due to automatic review settings September 17, 2026 14:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved blocking issues were identified.

Pull request overview

Updates automated backport and changelog-sync PR creation to assign eligible authors or mergers.

Changes:

  • Adds shared assignee resolution logic and tests.
  • Propagates the originating PR number through CLI and workflows.
  • Applies resolved assignees to created PRs.
File summaries
File Description
dev/scripts/backport_apply.sh Forwards the origin PR number.
cmd/backport/main.go Adds the CLI option.
cmd/backport/backports/changelog/sync.go Uses shared assignment logic.
cmd/backport/backports/changelog/sync_test.go Removes migrated tests.
cmd/backport/backports/apply/apply.go Assigns backport PRs automatically.
cmd/backport/assign/assign.go Implements assignee resolution.
cmd/backport/assign/assign_test.go Tests assignment scenarios.
.github/workflows/auto-backport.yml Passes the source PR number.
.github/scripts/backport/process-checked-branches.sh Forwards the source PR number.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

mrodm added a commit to mrodm/integrations that referenced this pull request Sep 17, 2026
…tion

Add a paragraph to step 4 explaining that the sync-backport-changelog
workflow now automatically assigns the sync PR to the backport PR's
author (if not a bot and has write/maintain/admin access) or to the
merger (if not a bot). Reflects elastic#21243, merged 2026-09-15.

Add a sentence to the checklist comment section documenting that
auto-backport PRs are automatically assigned to the original PR's
author or merger using the same logic. Preemptive for elastic#21379 (open).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
mrodm added a commit to mrodm/integrations that referenced this pull request Sep 18, 2026
@mergify

mergify Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@mrodm
mrodm merged commit 1161c10 into elastic:main Sep 18, 2026
14 checks passed
@mrodm
mrodm deleted the add_assignee_apply_backport branch September 18, 2026 09:35
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