Skip to content

fix: get_author() to traverse full backport chain#8

Merged
barredterra merged 2 commits intomainfrom
copilot/find-original-author-fix
Mar 5, 2026
Merged

fix: get_author() to traverse full backport chain#8
barredterra merged 2 commits intomainfrom
copilot/find-original-author-fix

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 2, 2026

When backports are chained (each backport points to the previous backport rather than directly to the original PR), get_author() only resolved one level up, returning the bot author of the intermediate PR instead of the original human author.

Changes

  • models/pull_request.py: Changed get_author() from a single-level lookup to a recursive traversal. At each step, _set_backport_of() is called on the parent to lazily load its own parent before recursing — no redundant API calls since _set_backport_of() already no-ops if backport_of is already populated.
# Before — only one level deep
def get_author(self) -> str:
    return self.backport_of.author if self.backport_of else self.author

# After — walks the full chain
def get_author(self) -> str:
    if self.backport_of:
        self.backport_of._set_backport_of()
        return self.backport_of.get_author()
    return self.author
  • tests/test_pull_request.py: Added test_get_author_chained_backports covering a 4-level chain (PR4 → PR3 → PR2 → PR1), asserting that get_author() on any backport in the chain returns the original author.
Original prompt

This section details on the original issue you should resolve

<issue_title>Find original author</issue_title>
<issue_description>In cases of automated backports via Mergify, typically all backports have a common root:

  1. PR by original author
  2. backport of (1) for branch A
  3. backport of (1) for branch B
  4. backport of (1) for branch C

In this case, we can find the original author of all the backports by looking at the parent PR.

However, we might also have a chain of backports like this:

  1. PR by original author
  2. backport of (1) for branch A
  3. backport of (2) for branch B
  4. backport of (3) for branch C

Currently, we can find the original author from (2) only. However, from (3) and (4) the original author is not found, because we only check parents one level deep.

This should be fixed by iterating up the chain until we find a non-backport PR.</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Fix method to find original author in backports Fix get_author() to traverse full backport chain Mar 2, 2026
@barredterra barredterra marked this pull request as ready for review March 5, 2026 00:04
@barredterra barredterra changed the title Fix get_author() to traverse full backport chain fix: get_author() to traverse full backport chain Mar 5, 2026
@barredterra barredterra merged commit 380da22 into main Mar 5, 2026
3 checks passed
@barredterra barredterra deleted the copilot/find-original-author-fix branch March 5, 2026 00:18
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.

Find original author

2 participants