Skip to content

Commit 286a8ee

Browse files
committed
Move grouping by upstreams to SyncDefaultGems::Repository
It is also useful to distribution changes to each upstream repository.
1 parent 9720d49 commit 286a8ee

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

tool/auto_review_pr.rb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def review(pr_number)
4646
changed_files = @client.get("/repos/#{REPO}/pulls/#{pr_number}/files").map { it.fetch(:filename) }
4747

4848
# Build a Hash: { upstream_repo => files, ... }
49-
upstream_repos = changed_files.group_by { |file| find_upstream_repo(file) }
49+
upstream_repos = SyncDefaultGems::Repository.group(changed_files)
5050
upstream_repos.delete(nil) # exclude no-upstream files
5151
upstream_repos.delete('prism') if changed_files.include?('prism_compile.c') # allow prism changes in this case
5252
if upstream_repos.empty?
@@ -70,17 +70,6 @@ def review(pr_number)
7070

7171
private
7272

73-
def find_upstream_repo(file)
74-
SyncDefaultGems::REPOSITORIES.each do |repo_name, repository|
75-
repository.mappings.each do |_src, dst|
76-
if file.start_with?(dst)
77-
return repo_name
78-
end
79-
end
80-
end
81-
nil
82-
end
83-
8473
# upstream_repos: { upstream_repo => files, ... }
8574
def format_comment(upstream_repos)
8675
comment = +''

tool/sync_default_gems.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,20 @@ def lib((upstream, branch), gemspec_in_subdir: false)
293293
]),
294294
}.transform_keys(&:to_s)
295295

296+
class << Repository
297+
def find_upstream(file)
298+
REPOSITORIES.find do |repo_name, repository|
299+
if repository.mappings.any? {|_src, dst| file.start_with?(dst) }
300+
break repo_name
301+
end
302+
end
303+
end
304+
305+
def group(files)
306+
files.group_by {|file| find_upstream(file)}
307+
end
308+
end
309+
296310
# Allow synchronizing commits up to this FETCH_DEPTH. We've historically merged PRs
297311
# with about 250 commits to ruby/ruby, so we use this depth for ruby/ruby in general.
298312
FETCH_DEPTH = 500

0 commit comments

Comments
 (0)