-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implementing the can-i-merge logic and can-i-merge build badge logic * Add badge resource * Fix test build failing due to inconsistent data setup Fixed rubocop warnings * Minor code cleanup * Trying to fix github build * Force installing docker compose, picked the current latest version But maybe it should be picking up based on latest available at runtime * Correctly using docker compose command --------- Co-authored-by: Phanindra Srungavarapu <[email protected]>
- Loading branch information
Showing
11 changed files
with
211 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require "pact_broker/api/resources/base_resource" | ||
require "pact_broker/api/resources/badge_methods" | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class CanIMergeBadge < BaseResource | ||
include BadgeMethods # This module contains all necessary webmachine methods for badge implementation | ||
|
||
def badge_url | ||
if pacticipant.nil? | ||
# if the pacticipant is nil, we return an error badge url | ||
badge_service.error_badge_url("pacticipant", "not found") | ||
elsif version.nil? | ||
# when there is no main branch version, we return an error badge url | ||
badge_service.error_badge_url("main branch version", "not found") | ||
else | ||
# we call badge_service to build the badge url | ||
badge_service.can_i_merge_badge_url( | ||
version_number: version.number, | ||
deployable: results | ||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
def results | ||
# can_i_merge returns true or false if the main branch version is compatible with all the integrations | ||
@results ||= matrix_service.can_i_merge(pacticipant: pacticipant, latest_main_branch_version: version) | ||
end | ||
|
||
def version | ||
@version ||= version_service.find_latest_version_from_main_branch(pacticipant) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
#/bin/sh | ||
|
||
cleanup() { | ||
docker-compose -f docker-compose-ci-mysql.yml down | ||
docker compose -f docker-compose-ci-mysql.yml down | ||
} | ||
|
||
trap cleanup EXIT | ||
docker-compose -f docker-compose-ci-mysql.yml up --exit-code-from tests --abort-on-container-exit --remove-orphans | ||
docker compose -f docker-compose-ci-mysql.yml up --exit-code-from tests --abort-on-container-exit --remove-orphans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
#/bin/sh | ||
|
||
cleanup() { | ||
docker-compose -f docker-compose-ci-postgres.yml down | ||
docker compose -f docker-compose-ci-postgres.yml down | ||
} | ||
|
||
trap cleanup EXIT | ||
docker-compose -f docker-compose-ci-postgres.yml up --exit-code-from tests --abort-on-container-exit --remove-orphans | ||
docker compose -f docker-compose-ci-postgres.yml up --exit-code-from tests --abort-on-container-exit --remove-orphans |
61 changes: 61 additions & 0 deletions
61
spec/lib/pact_broker/api/resources/can_i_merge_badge_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require "pact_broker/api/resources/can_i_merge_badge" | ||
require "pact_broker/api/resources/base_resource" | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
describe CanIMergeBadge do | ||
before do | ||
allow_any_instance_of(described_class).to receive(:badge_service).and_return(badge_service) | ||
|
||
allow(badge_service). to receive(:can_i_merge_badge_url).and_return("http://badge_url") | ||
allow(badge_service). to receive(:error_badge_url).and_return("http://error_badge_url") | ||
|
||
allow_any_instance_of(CanIMergeBadge).to receive(:pacticipant).and_return(pacticipant) | ||
allow_any_instance_of(CanIMergeBadge).to receive(:version).and_return(version) | ||
allow_any_instance_of(CanIMergeBadge).to receive(:results).and_return(results) | ||
end | ||
|
||
let(:branch_service) { class_double("PactBroker::Versions::BranchService").as_stubbed_const } | ||
let(:badge_service) { class_double("PactBroker::Badges::Service").as_stubbed_const } | ||
|
||
let(:pacticipant) { double("pacticipant") } | ||
let(:version) { double("version", number: "1") } | ||
let(:results) { true } | ||
|
||
let(:path) { "/pacticipants/Foo/main-branch/can-i-merge/badge" } | ||
|
||
subject { get(path) } | ||
|
||
context "when everything is found" do | ||
it "returns a 307" do | ||
expect(subject.status).to eq 307 | ||
end | ||
|
||
it "return the badge URL" do | ||
expect(badge_service). to receive(:can_i_merge_badge_url).with(version_number: "1", deployable: true) | ||
expect(subject.headers["Location"]).to eq "http://badge_url" | ||
end | ||
end | ||
|
||
context "when the pacticipant is not found" do | ||
let(:pacticipant) { nil } | ||
|
||
it "returns an error badge URL" do | ||
expect(badge_service).to receive(:error_badge_url).with("pacticipant", "not found") | ||
expect(subject.headers["Location"]).to eq "http://error_badge_url" | ||
end | ||
end | ||
|
||
context "when the version is not found" do | ||
let(:version) { nil } | ||
|
||
it "returns an error badge URL" do | ||
expect(badge_service).to receive(:error_badge_url).with("main branch version", "not found") | ||
expect(subject.headers["Location"]).to eq "http://error_badge_url" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters