Skip to content

Commit

Permalink
Fix init_new_gems (#381)
Browse files Browse the repository at this point in the history
To support gems with names longer than existing ones.
  • Loading branch information
soutaro authored Aug 7, 2023
1 parent 42c126f commit 965029a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
10 changes: 6 additions & 4 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# except files which have code owners.
* @pocke

# Misc
/generators/aws-sdk-rbs-generator @ksss
/generators/yard-generator @ksss

# *** DON'T EDIT LINES BELOW (see bin/init_new_gem) ***

# Maintainer of individual gems (alphabetical order)
/gems/ast @pocke
/gems/aws-sdk-* @ksss
Expand All @@ -21,7 +27,3 @@
/gems/stackprof @pocke
/gems/rails-dom-testing @ksss
/gems/yard @ksss

# Misc
/generators/aws-sdk-rbs-generator @ksss
/generators/yard-generator @ksss
30 changes: 15 additions & 15 deletions bin/init_new_gem
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,25 @@ if git_repo
end

if github_account
github_account = "@#{github_account}" unless github_account.start_with?('@')
update(Pathname('.github/CODEOWNERS')) do |content|
lines = content.lines
insert_idx = nil
at_col = nil
entered = false
lines.each.with_index do |line, idx|
insert_idx = idx and break if entered && !line.match?(%r!^/gems/!)
next unless entered = line.match?(%r!^/gems/!)
insert_idx = idx
at_col ||= line.index('@')

break if "/gems/#{gem_name}" < line

pre_gems_lines, gems_lines =
lines.map(&:chomp).slice_before('# Maintainer of individual gems (alphabetical order)').to_a
pre_gems_lines << gems_lines.shift

gems_lines << "/gems/#{gem_name} #{github_account}"
gems_lines.sort!

gems = gems_lines.map {|line| line.split }
longest_gem_size = gems.map {|gem, _| gem.size }.max
gem_lines = gems.map do |gem, owner|
space = " " * (longest_gem_size - gem.size)
"#{gem}#{space} #{owner}"
end

insert_line = "/gems/#{gem_name}"
insert_line += ' ' * (at_col - insert_line.size)
insert_line += "@#{github_account}\n"
lines.insert(insert_idx, insert_line)
lines.join
(pre_gems_lines + gem_lines).join("\n")
end
end

Expand Down

0 comments on commit 965029a

Please sign in to comment.