Skip to content

Commit c888b75

Browse files
hsbtclaude
andcommitted
Add Redmine ticket link comments to auto review PR
When a pull request title or body contains references like [Bug #22003], [Feature ruby#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>
1 parent b21043f commit c888b75

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tool/auto_review_pr.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class AutoReviewPR
3838
UPSTREAM_COMMENT_PREFIX = 'The following files are maintained in the following upstream repositories:'
3939
UPSTREAM_COMMENT_SUFFIX = 'Please file a pull request to the above instead. Thank you!'
4040

41+
REDMINE_TICKET_PATTERN = /\[(Bug|Feature|Misc)\s*#(\d+)\]/
42+
REDMINE_COMMENT_PREFIX = 'This pull request references the following Redmine tickets:'
43+
4144
FORK_COMMENT_PREFIX = 'It looks like this pull request was filed from a branch in ruby/ruby.'
4245
FORK_COMMENT_BODY = <<~COMMENT
4346
#{FORK_COMMENT_PREFIX}
@@ -59,6 +62,7 @@ def review(pr_number)
5962
existing_comments = fetch_existing_comments(pr_number)
6063
review_non_fork_branch(pr_number, existing_comments)
6164
review_upstream_repos(pr_number, existing_comments)
65+
review_redmine_links(pr_number, existing_comments)
6266
end
6367

6468
private
@@ -120,6 +124,32 @@ def review_upstream_repos(pr_number, existing_comments)
120124
post_comment(pr_number, format_upstream_comment(upstream_repos))
121125
end
122126

127+
def review_redmine_links(pr_number, existing_comments)
128+
if already_commented?(existing_comments, REDMINE_COMMENT_PREFIX)
129+
puts "Skipped: The PR ##{pr_number} already has a Redmine links comment."
130+
return
131+
end
132+
133+
pr = @client.get("/repos/#{REPO}/pulls/#{pr_number}")
134+
text = "#{pr[:title]}\n#{pr[:body]}"
135+
136+
tickets = text.scan(REDMINE_TICKET_PATTERN).uniq
137+
if tickets.empty?
138+
puts "Skipped: The PR ##{pr_number} doesn't reference any Redmine tickets."
139+
return
140+
end
141+
142+
post_comment(pr_number, format_redmine_comment(tickets))
143+
end
144+
145+
def format_redmine_comment(tickets)
146+
comment = +"#{REDMINE_COMMENT_PREFIX}\n\n"
147+
tickets.each do |type, number|
148+
comment << "* [#{type} ##{number}](https://bugs.ruby-lang.org/issues/#{number})\n"
149+
end
150+
comment
151+
end
152+
123153
def format_upstream_comment(upstream_repos)
124154
comment = +''
125155
comment << "#{UPSTREAM_COMMENT_PREFIX}\n\n"

0 commit comments

Comments
 (0)