- run: bundle exec rspec --format json --out rspec.json
- run:
name: Create CircleCI Test Summary
when: always
command: |
gem install circleci-test_report
circleci-test_report -f rspec.json -o /tmp/test-results/rspec.xml
- run:
name: Update github pull request
when: on_fail
command: |
bundle exec rake github:update_pull_request
- store_test_results:
path: /tmp/test-results
require "octokit"
namespace :github do
task update_pull_request: :environment do
if ENV["CI_PULL_REQUEST"].present? && File.exist?("#{Rails.root}/rspec.json")
json = JSON.parse(File.read("#{Rails.root}/rspec.json"))
examples = json["examples"].select {|e| e["status"] == "failed" }
error_files = examples.map {|e| "#{e["file_path"]}:#{e["line_number"]}" }
fail_message = error_files.map {|v| "- [ ] `#{v}`" }.join("\n")
client = Octokit::Client.new(access_token: ENV["GITHUB_ACCESS_TOKEN"])
repo = "#{ENV["CIRCLE_PROJECT_USERNAME"]}/#{ENV["CIRCLE_PROJECT_REPONAME"]}"
pr_number = ENV["CI_PULL_REQUEST"].split("/").last.to_i
body = client.pull_request(repo, pr_number)[:body]
body = "#{body}\n## [:cry: #{Time.current.strftime("%Y/%m/%d %H:%M")}](#{ENV["CIRCLE_BUILD_URL"]})\n#{fail_message}"
client.update_pull_request(repo, pr_number, { body: body })
end
end
end
## [:cry: 2018/10/30 15:00](https://circleci.com/gh/bluerabbit/repo/1)
- [ ] `./spec/models/user_spec.rb:4`