Skip to content

Added the --gitrepo and --gitdiff switches to .check.rb#521

Draft
dearblue wants to merge 4 commits into
mruby:masterfrom
dearblue:checker
Draft

Added the --gitrepo and --gitdiff switches to .check.rb#521
dearblue wants to merge 4 commits into
mruby:masterfrom
dearblue:checker

Conversation

@dearblue

Copy link
Copy Markdown
Contributor

Overview: This allows checking against a Git repository and a specified branch. For pull requests, only modified or added “.gem” files are checked.

@dearblue dearblue requested a review from matz as a code owner June 21, 2026 13:54

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds command-line options (--gitdiff, --gitrepo, and --interval) to .check.rb to allow verifying files with changes between Git refs or checking a Git repository and its branch. Feedback includes improving check_git_repository with defensive checks, idiomatic array methods, and cleaner string formatting, as well as optimizing the script to avoid executing git ls-files twice when --gitdiff is disabled.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread .check.rb
Comment on lines +65 to +87
def check_git_repository(gemname, tree, errinfo) # rubocop:disable Metrics/MethodLength
repo = tree["repository"]
branch = tree["branch"] || "master"
refs = git_get_remote_refs(repo)

if refs.nil?
errinfo.push <<~INFO
#{gemname}: unable to access the repository or locate a valid branch name.
INFO
elsif refs.any?("refs/heads/#{branch}")
# OK
elsif refs.any?("refs/tags/#{branch}")
errinfo.push <<~INFO
WARN: #{gemname}: instead of branches, the tag "#{branch}" is used.
INFO
else
candidates = refs.grep(%r{^refs/heads/}).join("\n").gsub(%r{^refs/heads/}, "").tr("\n", " ")
errinfo.push <<~INFO
#{gemname}: branch "#{branch}" is missing.
\tcandidates: #{candidates}
INFO
end
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There are a few improvements we can make to check_git_repository:

  1. Defensive Programming: If repository is missing or empty in the YAML file, repo will be nil or empty. Calling git_get_remote_refs with nil will run a failing git command. We should guard against this and return early.
  2. Idiomatic Membership Check: Use Array#include? instead of Array#any? with an argument for checking exact string matching. It is more standard and compatible.
  3. Cleaner String Manipulation: Instead of joining the array with newlines, performing a regex replacement, and then translating newlines back to spaces, we can map over the array using delete_prefix and join them with spaces directly.
def check_git_repository(gemname, tree, errinfo) # rubocop:disable Metrics/MethodLength
  repo = tree["repository"]
  return if repo.to_s.empty?

  branch = tree["branch"] || "master"
  refs = git_get_remote_refs(repo)

  if refs.nil?
    errinfo.push <<~INFO
      #{gemname}: unable to access the repository or locate a valid branch name.
    INFO
  elsif refs.include?("refs/heads/#{branch}")
    # OK
  elsif refs.include?("refs/tags/#{branch}")
    errinfo.push <<~INFO
      WARN: #{gemname}: instead of branches, the tag "#{branch}" is used.
    INFO
  else
    candidates = refs.grep(%r{\Arefs/heads/}).map { |r| r.delete_prefix("refs/heads/") }.join(" ")
    errinfo.push <<~INFO
      #{gemname}: branch "#{branch}" is missing.
      \tcandidates: #{candidates}
    INFO
  end
end

Comment thread .check.rb Outdated
Comment on lines 117 to 133
if gitdiff
case ARGV.size
when 1, 2
# do nothing
else
warn banner
exit 1
end
cmd = %w[git diff -z --name-only --diff-filter=ACMR]
cmd.concat ARGV
cmd.concat %w[-- :^*/*]
gemfiles = run_and_split_nul(cmd)
else
gemfiles = run_and_split_nul(%w[git ls-files -z :^*/*])
end

entries = run_and_split_nul(%w[git ls-files -z :^*/*])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When --gitdiff is not specified, git ls-files is executed twice: once to populate gemfiles and once to populate entries. We can optimize this by running git ls-files once, storing it in entries, and then assigning gemfiles = entries in the else branch.

entries = run_and_split_nul(%w[git ls-files -z :^*/*])

if gitdiff
  case ARGV.size
  when 1, 2
    # do nothing
  else
    warn banner
    exit 1
  end
  cmd = %w[git diff -z --name-only --diff-filter=ACMR]
  cmd.concat ARGV
  cmd.concat %w[-- :^*/*]
  gemfiles = run_and_split_nul(cmd)
else
  gemfiles = entries
end

@dearblue dearblue marked this pull request as draft June 21, 2026 14:19
dearblue added 4 commits June 27, 2026 21:43
The purpose is to enable verification of the validity of Git repositories and branches.

It actually accesses the URL specified by the "repository" in the ".gem" file and retrieves the branch and tag names.
If the "branch" in the ".gem" file is not included in the retrieved reference name, it reports an error.
Additionally, if the "branch" in the ".gem" file is actually a tag name, it also reports an error.

Furthermore, the `.check.rb --interval` switch has been added.
The `--gitrepo` switch is equivalent to web scraping from the perspective of the target server.
Therefore, unlimited consecutive access may be restricted by the target server’s rate limits.
This switch allows specifying the interval between consecutive accesses as a real number in seconds.
The default value is 1.2 seconds.
The goal is to enable efficient verification of specific changes rather than verifying all files.

Using `.check.rb --gitdiff base-ref head-ref` allows verifying only the files that have changed between Git commits.
The `.check.rb --gitrepo` switch now verifies the validity of the Git repository and branch specified by the ".gem" file.
The actual targets for verification are the ".gem" files detected by the `.check.rb --gitdiff` switch.

Although the logic is triggered by "push" events as well, the current workflow configuration is limited to pull requests only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant