Use a constant instead of a global variable in sync_default_gems.rb

This commit is contained in:
Benoit Daloze 2020-08-29 11:51:05 +02:00
Родитель 6d946665bd
Коммит 232d6c4077
1 изменённых файлов: 12 добавлений и 12 удалений

Просмотреть файл

@ -3,7 +3,7 @@
require 'fileutils'
include FileUtils
$repositories = {
REPOSITORIES = {
rubygems: 'rubygems/rubygems',
bundler: 'rubygems/rubygems',
rdoc: 'ruby/rdoc',
@ -70,9 +70,9 @@ $repositories = {
}
def sync_default_gems(gem)
puts "Sync #{$repositories[gem.to_sym]}"
puts "Sync #{REPOSITORIES[gem.to_sym]}"
upstream = File.join("..", "..", $repositories[gem.to_sym])
upstream = File.join("..", "..", REPOSITORIES[gem.to_sym])
case gem
when "rubygems"
@ -292,11 +292,11 @@ IGNORE_FILE_PATTERN =
)\z/x
def sync_default_gems_with_commits(gem, ranges, edit: nil)
puts "Sync #{$repositories[gem.to_sym]} with commit history."
puts "Sync #{REPOSITORIES[gem.to_sym]} with commit history."
IO.popen(%W"git remote") do |f|
unless f.read.split.include?(gem)
`git remote add #{gem} git@github.com:#{$repositories[gem.to_sym]}.git`
`git remote add #{gem} git@github.com:#{REPOSITORIES[gem.to_sym]}.git`
end
end
system(*%W"git fetch --no-tags #{gem}")
@ -326,7 +326,7 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
ENV["FILTER_BRANCH_SQUELCH_WARNING"] = "1"
commits.each do |sha, subject|
puts "Pick #{sha} from #{$repositories[gem.to_sym]}."
puts "Pick #{sha} from #{REPOSITORIES[gem.to_sym]}."
skipped = false
result = IO.popen(%W"git cherry-pick #{sha}", &:read)
@ -371,8 +371,8 @@ def sync_default_gems_with_commits(gem, ranges, edit: nil)
puts "Update commit message: #{sha}"
prefix = "[#{($repositories[gem.to_sym])}]".gsub(/\//, '\/')
suffix = "https://github.com/#{($repositories[gem.to_sym])}/commit/#{sha[0,10]}"
prefix = "[#{(REPOSITORIES[gem.to_sym])}]".gsub(/\//, '\/')
suffix = "https://github.com/#{(REPOSITORIES[gem.to_sym])}/commit/#{sha[0,10]}"
`git filter-branch -f --msg-filter 'sed "1s/^/#{prefix} /" && echo && echo #{suffix}' -- HEAD~1..HEAD`
unless $?.success?
puts "Failed to modify commit message of #{sha}"
@ -408,7 +408,7 @@ end
def update_default_gems(gem)
author, repository = $repositories[gem.to_sym].split('/')
author, repository = REPOSITORIES[gem.to_sym].split('/')
puts "Update #{author}/#{repository}"
@ -439,14 +439,14 @@ when "up"
if ARGV[1]
update_default_gems(ARGV[1])
else
$repositories.keys.each{|gem| update_default_gems(gem.to_s)}
REPOSITORIES.keys.each{|gem| update_default_gems(gem.to_s)}
end
when "all"
$repositories.keys.each{|gem| sync_default_gems(gem.to_s)}
REPOSITORIES.keys.each{|gem| sync_default_gems(gem.to_s)}
when "list"
ARGV.shift
pattern = Regexp.new(ARGV.join('|'))
$repositories.each_pair do |name, gem|
REPOSITORIES.each_pair do |name, gem|
next unless pattern =~ name or pattern =~ gem
printf "%-15s https://github.com/%s\n", name, gem
end