Skip to content

Commit

Permalink
add branch check
Browse files Browse the repository at this point in the history
  • Loading branch information
ratherblue committed Mar 11, 2016
1 parent 43f988d commit fbff67b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/xambassador/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

require_relative "connection"
require_relative "status_checks/peer_review"
require_relative "status_checks/branch_name"

module Xambassador
# Pull Request helpers
Expand All @@ -25,6 +26,7 @@ def handle_opened_pull_request(pull_request)
@connection = Xambassador::Connection.new

Xambassador::PeerReview.new(@connection, pull_request)
Xambassador::BranchName.new(@connection, pull_request)
end
end
end
27 changes: 27 additions & 0 deletions lib/xambassador/status_checks/branch_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "json"
require "net/https"
require "uri"
require "renegade/branch_name"

require_relative "../status_check"

module Xambassador
# Check peer review status
class BranchName < StatusCheck
def initialize(connection, pull_request)
super(connection, pull_request, "Branch Name")

branch_check = Renegade::BranchName.new
@description_success = ""
@description_failure = branch_check.warning

branch_name = pull_request['head']['ref']

if branch_check.check_branch_name(branch_name)
success
else
failure
end
end
end
end
2 changes: 1 addition & 1 deletion test/fixtures/pull_request/opened.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"statuses_url": "https://api.github.com/repos/ratherblue/git-hooks/statuses/d79da21d5d8330332895dcff4b49400705de78c9",
"head": {
"label": "ratherblue:test-web-hook",
"ref": "test-web-hook",
"ref": "story-12343",
"sha": "d79da21d5d8330332895dcff4b49400705de78c9",
"user": {
"login": "ratherblue",
Expand Down
35 changes: 35 additions & 0 deletions test/unit/xambassador/pull_request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
labels = File.read(
File.expand_path("./test/fixtures/pull_request/labels/good.json")
)

stub_request(:post, "#{url_prefix}/statuses/#{sha}")
.with(body: '{"context":"Peer Review","description"'\
':"Success","state":"success"}',
Expand All @@ -30,6 +31,17 @@
"User-Agent" => "Octokit Ruby Gem 4.3.0" })
.to_return(status: 200, body: "", headers: {})

stub_request(:post, "#{url_prefix}/statuses/#{sha}")
.with(body: '{"context":"Branch Name","description"'\
':"","state":"success"}',
headers: {
"Accept" => "application/vnd.github.v3+json",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"Authorization" => "token " + ENV["GITHUB_AUTH_TOKEN"],
"Content-Type" => "application/json",
"User-Agent" => "Octokit Ruby Gem 4.3.0" })
.to_return(status: 200, body: "", headers: {})

stub_request(:get, "#{url_prefix}/issues/27")
.with(headers: { "Accept" => "*/*", "User-Agent" => "Ruby" })
.to_return(status: 200, body: labels, headers: {})
Expand All @@ -53,6 +65,17 @@
"User-Agent" => "Octokit Ruby Gem 4.3.0" })
.to_return(status: 200, body: "", headers: {})

stub_request(:post, "#{url_prefix}/statuses/#{sha}")
.with(body: '{"context":"Branch Name","description"'\
':"","state":"success"}',
headers: {
"Accept" => "application/vnd.github.v3+json",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"Authorization" => "token " + ENV["GITHUB_AUTH_TOKEN"],
"Content-Type" => "application/json",
"User-Agent" => "Octokit Ruby Gem 4.3.0" })
.to_return(status: 200, body: "", headers: {})

stub_request(:get, "#{url_prefix}/issues/27")
.with(headers: { "Accept" => "*/*", "User-Agent" => "Ruby" })
.to_return(status: 200, body: labels, headers: {})
Expand Down Expand Up @@ -87,6 +110,18 @@
"User-Agent" => "Octokit Ruby Gem 4.3.0" })
.to_return(status: 200, body: "", headers: {})

stub_request(:post, "#{url_prefix}/statuses/#{sha}")
.with(body: '{"context":"Branch Name","description"'\
':"Branches must start with bug-##### or story-#####.",'\
'"state":"failure"}',
headers: {
"Accept" => "application/vnd.github.v3+json",
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"Authorization" => "token " + ENV["GITHUB_AUTH_TOKEN"],
"Content-Type" => "application/json",
"User-Agent" => "Octokit Ruby Gem 4.3.0" })
.to_return(status: 200, body: "", headers: {})

stub_request(:get, "#{url_prefix}/issues/27")
.with(headers: { "Accept" => "*/*", "User-Agent" => "Ruby" })
.to_return(status: 200, body: labels, headers: {})
Expand Down
1 change: 1 addition & 0 deletions xambassador.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency("octokit", "~> 4.3.0")
spec.add_development_dependency("webmock", "~> 1.24.2")
spec.add_development_dependency("sinatra", "~> 1.4.7")
spec.add_development_dependency("renegade", "0.1.49")
end

0 comments on commit fbff67b

Please sign in to comment.