Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Combined GitHub Status #333

Merged
merged 2 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ Use `GithubStatusFormatter` to submit [commit status](https://github.com/blog/12
$ PRONTO_GITHUB_ACCESS_TOKEN=token pronto run -f github_status -c origin/master
```

If you want to show a one single status for all runners, instead of status per runner:

```sh
$ PRONTO_GITHUB_ACCESS_TOKEN=token pronto run -f github_combined_status -c origin/master
```

It's possible to combine multiple formatters.
To get both pull request comments and commit status summary use:

Expand Down
1 change: 1 addition & 0 deletions lib/pronto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
require 'pronto/formatter/pull_request_formatter'
require 'pronto/formatter/github_formatter'
require 'pronto/formatter/github_status_formatter'
require 'pronto/formatter/github_combined_status_formatter'
require 'pronto/formatter/github_pull_request_formatter'
require 'pronto/formatter/github_pull_request_review_formatter'
require 'pronto/formatter/gitlab_formatter'
Expand Down
1 change: 1 addition & 0 deletions lib/pronto/formatter/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def self.names
FORMATTERS = {
'github' => GithubFormatter,
'github_status' => GithubStatusFormatter,
'github_combined_status' => GithubCombinedStatusFormatter,
'github_pr' => GithubPullRequestFormatter,
'github_pr_review' => GithubPullRequestReviewFormatter,
'gitlab' => GitlabFormatter,
Expand Down
24 changes: 24 additions & 0 deletions lib/pronto/formatter/github_combined_status_formatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require_relative 'github_status_formatter/status_builder'

module Pronto
module Formatter
class GithubCombinedStatusFormatter
def format(messages, repo, _)
client = Github.new(repo)
head = repo.head_commit_sha

create_status(client, head, messages.uniq || [])
end

private

def create_status(client, sha, messages)
builder = GithubStatusFormatter::StatusBuilder.new(nil, messages)
status = Status.new(sha, builder.state,
'pronto', builder.description)

client.create_commit_status(status)
end
end
end
end
4 changes: 2 additions & 2 deletions spec/pronto/formatter/formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ module Formatter
subject { Formatter.names }
it do
should =~ %w[github github_pr github_pr_review github_status
gitlab gitlab_mr bitbucket bitbucket_pr bitbucket_server_pr
json checkstyle text null]
github_combined_status gitlab gitlab_mr bitbucket bitbucket_pr
bitbucket_server_pr json checkstyle text null]
end
end
end
Expand Down
102 changes: 102 additions & 0 deletions spec/pronto/formatter/github_combined_status_formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
module Pronto
module Formatter
RSpec.describe GithubCombinedStatusFormatter do
let(:formatter) { described_class.new }

describe '#format' do
subject { formatter.format(messages, repo, nil) }

let(:repo) { Git::Repository.new('spec/fixtures/test.git') }
let(:runner_class) do
Class.new do
def self.title
'fake_runner'
end
end
end
let(:message) do
Pronto::Message.new('app/path', nil, level, '', sha, runner_class)
end
let(:sha) { '64dadfdb7c7437476782e8eb024085862e6287d6' }
let(:status) { Status.new(sha, state, context, description) }
let(:context) { 'pronto' }

let(:messages) { [message, message] }

before do
Pronto::Github.any_instance
.should_receive(:create_commit_status)
.with(status)
.once
.and_return(nil)
end

context 'when has no messages' do
let(:messages) { [] }

let(:state) { :success }
let(:description) { 'Coast is clear!' }

it 'has no issues' do
subject
end
end

context 'when has one message' do
let(:messages) { [message, message] }

context 'when severity level is info' do
let(:level) { :info }

let(:state) { :success }
let(:description) { 'Found 1 info.' }

it 'has issue' do
subject
end
end

context 'when severity level is warning' do
let(:level) { :warning }

let(:state) { :failure }
let(:description) { 'Found 1 warning.' }

it 'has warning' do
subject
end
end
end

context 'when has multiple messages' do
let(:level) { :warning }
let(:level2) { :error }
let(:message2) do
Pronto::Message.new('app/path', nil, level2, '', sha, runner_class)
end

let(:state) { :failure }
let(:description) { 'Found 1 warning and 1 error.' }

context 'order of messages does not matter' do
context 'ordered' do
let(:messages) { [message, message2] }

it 'has issues' do
subject
end
end

context 'reversed' do
let(:messages) { [message2, message] }

it 'has issues' do
subject
end
end
end
end
end
end
end
end