summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2026-04-16 09:32:13 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2026-04-16 10:20:19 +0900
commit8177af52da8d6978cfd22ea20e99a4262acd2b28 (patch)
tree1daf94610c4b03d687b5c6cc8652ee95bb604911
parente6508f099ab6e0b98937e7cb181c850671ddb5ae (diff)
Add Redmine ticket link comments to auto review PR
When a pull request title or body contains references like [Bug #22003], [Feature #12345], or [Misc #67890], automatically post a comment with links to the corresponding bugs.ruby-lang.org issues. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
-rwxr-xr-xtool/auto_review_pr.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/tool/auto_review_pr.rb b/tool/auto_review_pr.rb
index a8f64fab9d..e281cec00e 100755
--- a/tool/auto_review_pr.rb
+++ b/tool/auto_review_pr.rb
@@ -38,6 +38,9 @@ class AutoReviewPR
UPSTREAM_COMMENT_PREFIX = 'The following files are maintained in the following upstream repositories:'
UPSTREAM_COMMENT_SUFFIX = 'Please file a pull request to the above instead. Thank you!'
+ REDMINE_TICKET_PATTERN = /\[(Bug|Feature|Misc)\s*#(\d+)\]/
+ REDMINE_COMMENT_PREFIX = 'This pull request references the following Redmine tickets:'
+
FORK_COMMENT_PREFIX = 'It looks like this pull request was filed from a branch in ruby/ruby.'
FORK_COMMENT_BODY = <<~COMMENT
#{FORK_COMMENT_PREFIX}
@@ -59,6 +62,7 @@ class AutoReviewPR
existing_comments = fetch_existing_comments(pr_number)
review_non_fork_branch(pr_number, existing_comments)
review_upstream_repos(pr_number, existing_comments)
+ review_redmine_links(pr_number, existing_comments)
end
private
@@ -120,6 +124,32 @@ class AutoReviewPR
post_comment(pr_number, format_upstream_comment(upstream_repos))
end
+ def review_redmine_links(pr_number, existing_comments)
+ if already_commented?(existing_comments, REDMINE_COMMENT_PREFIX)
+ puts "Skipped: The PR ##{pr_number} already has a Redmine links comment."
+ return
+ end
+
+ pr = @client.get("/repos/#{REPO}/pulls/#{pr_number}")
+ text = "#{pr[:title]}\n#{pr[:body]}"
+
+ tickets = text.scan(REDMINE_TICKET_PATTERN).uniq
+ if tickets.empty?
+ puts "Skipped: The PR ##{pr_number} doesn't reference any Redmine tickets."
+ return
+ end
+
+ post_comment(pr_number, format_redmine_comment(tickets))
+ end
+
+ def format_redmine_comment(tickets)
+ comment = +"#{REDMINE_COMMENT_PREFIX}\n\n"
+ tickets.each do |type, number|
+ comment << "* [#{type} ##{number}](https://bugs.ruby-lang.org/issues/#{number})\n"
+ end
+ comment
+ end
+
def format_upstream_comment(upstream_repos)
comment = +''
comment << "#{UPSTREAM_COMMENT_PREFIX}\n\n"