Repository navigation
Fix matching of backports with their original Pull Request #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Decidim | ||
| module MaintainersToolbox | ||
| # Shared logic to identify the backport Pull Requests of a given Pull Request. | ||
| # | ||
| # A backport Pull Request is linked with its original Pull Request in two ways: | ||
| # - By the body, as it always contains a line like "Backport #1234 to v0.32" | ||
| # - By the title, that follows the pattern "Backport 'Title of the original' to v0.32" | ||
| module BackportsHelper | ||
| private | ||
|
|
||
| # Checks if a related issue is a backport of the given Pull Request for the given version. | ||
| # | ||
| # @param related_issue [Hash] a cross-referenced issue or pull request, with the :title, :body and :state | ||
| # @param base_pull_request [Hash] the Pull Request that we want to check, with the :id and :title | ||
| # @param version [String] the version number that we want to check, with the "v" prefix (i.e. "v0.32") | ||
| # | ||
| # @return [Boolean] | ||
| def backport_of_pull_request?(related_issue, base_pull_request, version) | ||
| return false unless related_issue[:title].to_s.start_with?("Backport") | ||
| return false unless backport_for_version?(related_issue, version) | ||
|
|
||
| base_pull_request_id = base_pull_request[:id] | ||
| return true if base_pull_request_id && related_issue[:body].to_s.match?(/\bBackport ##{base_pull_request_id}\b/) | ||
|
|
||
| related_issue[:title].to_s.match?( | ||
| /\ABackport ['"]?#{Regexp.escape(base_pull_request[:title].to_s)}['"]? to / | ||
|
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reject a conflicting original PR ID before title fallback. If PR Use title fallback only when no usable original PR ID is present. If the body identifies another PR, reject the candidate. This retains the legacy title-only path while addressing the PR objective of excluding unrelated backports.
|
||
| ) | ||
| end | ||
|
|
||
| # Checks if a related issue is a backport for the given version. | ||
| # | ||
| # @param related_issue [Hash] a cross-referenced issue or pull request, with the :title and :body | ||
| # @param version [String] the version number that we want to check, with or without the "v" prefix (i.e. "v0.32" or "0.32") | ||
| # | ||
| # @return [Boolean] | ||
| def backport_for_version?(related_issue, version) | ||
| [related_issue[:title], related_issue[:body]].any? do |text| | ||
| text.to_s.match?(/\bto v?#{Regexp.escape(version)}\b/) | ||
|
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The version check reads the original title as a target version. For example, an automatically generated Match the version in the same complete body declaration or title suffix that identifies the original PR. Prompt To Fix With AIThis is a comment left during a code review.
Path: lib/decidim/maintainers_toolbox/backports_helper.rb
Line: 39-40
Comment:
**One backport matches two releases**
The version check reads the original title as a target version. For example, an automatically generated `Backport 'Upgrade to v0.31' to v0.32` with body `Backport #123 to v0.32` matches both versions. If merged, that single backport can fill both report columns and hide missing work, or make `ActionBackporter` skip a required backport.
Match the version in the same complete body declaration or title suffix that identifies the original PR.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Match the version in the backport directive. For a PR titled Parse the target version from the same backport directive as the original PR ID. For title fallback, match the version in that title. Keep the canonical v0.29 match valid.
|
||
| end | ||
| end | ||
|
|
||
| # The state priority, so we show merged Pull Requests before the opened or closed ones. | ||
| # | ||
| # @param state [String] the state of the Pull Request | ||
| # | ||
| # @return [Integer] | ||
| def backport_state_priority(state) | ||
| { "merged" => 0, "open" => 1, "closed" => 2 }.fetch(state.to_s, 3) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,6 @@ | |
|
|
||
| module Decidim | ||
| module MaintainersToolbox | ||
| VERSION = "0.7.1" | ||
| VERSION = "0.7.2" | ||
| end | ||
| end | ||
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.
The title fallback accepts a backport even when its body names a different original PR. If two originals share a title, a cross-referenced backport with body
Backport #999 to v0.32still matches original #123 by title. The report can then mark required work done, andActionBackportercan skip it.Treat an explicit original ID as authoritative. Use the title only when that declaration is absent.
Prompt To Fix With AI