9

現在のブランチとマスターの間で変更されたファイルに対して Rubocop スタイル チェッカーを実行するspec/lint/rubocop_spec.rbを作成しました。これは、ローカルでテストする場合は機能しますが、ビルド サーバー Circle.ci でテストを実行する場合は機能しません。問題のブランチのみがダウンロードされているためと思われるため、マスター間の違いは見つかりません。よりも良い方法はありgit co master && git pull origin masterますか?変更されたファイルを一覧表示するために Github API にクエリを実行できますか?

require 'spec_helper'

describe 'Check that the files we have changed have correct syntax' do
  before do
    current_sha = `git rev-parse --verify HEAD`.strip!
    files = `git diff master #{current_sha} --name-only | grep .rb`
    files.tr!("\n", ' ')
    @report = 'nada'
    if files.present?
      puts "Changed files: #{files}"

      @report = `rubocop #{files}`
      puts "Report: #{@report}"
    end
  end

  it { @report.match('Offenses').should_not be true }
end
4

6 に答える 6

6

api.github.com にクエリを実行して修正しました。これにより、current_sha と master ブランチの間で変更されたすべてのファイルに対して rubocop が実行されます。

require 'spec_helper'

describe 'Check that the files we have changed have correct syntax' do
  before do
    current_sha = `git rev-parse --verify HEAD`.strip!
    token = 'YOUR GITHUB TOKEN'
    url = 'https://api.github.com/repos/orwapp/orwapp/compare/' \
          "master...#{current_sha}?access_token=#{token}"
    files = `curl -i #{url} | grep filename | cut -f2 -d: | grep \.rb | tr '"', '\ '`
    files.tr!("\n", ' ')
    @report = 'nada'
    if files.present?
      puts "Changed files: #{files}"

      @report = `rubocop #{files}`
      puts "Report: #{@report}"
    end
  end

  it { expect(@report.match('Offenses')).to be_falsey }
end
于 2015-09-14T10:34:59.310 に答える
4

非常にうまく機能するhttps://github.com/m4i/rubocop-gitを見つけました。ただし、git diff (オプションで --cached を使用) で機能するため、ブランチを比較することはできません。

于 2015-11-17T12:45:38.083 に答える