Skip to content

Fix problems with GoCD partial matches of pipeline #65

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

Closed
wants to merge 2 commits into from
Closed
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
23 changes: 19 additions & 4 deletions scripts/cctray.check
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,28 @@ class CCTray
end

def latest_status
name = [@pipeline, @stage, @job].compact.join(" :: ")
projects = exact_match
projects = partial_match if projects.empty?

projects = @feed.xpath('//Project').select do |proj|
proj.attr('name').downcase.include?(name.downcase)
CCTrayMultiProjectStatus.new(projects)
end

def partial_match
name = name = [@pipeline, @stage, @job].compact.join(" :: ").downcase

@feed.xpath('//Project').select do |proj|
proj.attr('name').downcase.include?(name)
end
end

CCTrayMultiProjectStatus.new(projects)
def exact_match
@feed.xpath('//Project').select do |proj|
proj_pipeline, proj_stage, proj_job, _ = proj.attr('name').split(' :: ')
[ [ @pipeline, @stage, @job ], [ proj_pipeline, proj_stage, proj_job ]].transpose.all? do |attribute_to_compare, proj_attribute|
attribute_to_compare.nil? ||
(!proj_attribute.nil? && attribute_to_compare.downcase == proj_attribute.downcase)
end
end
end
end

Expand Down
42 changes: 42 additions & 0 deletions scripts/specs/cctray_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@

<Project name="aBadPipeline :: aBrokenStage" activity="Sleeping" lastBuildStatus="Failure" lastBuildLabel="145" lastBuildTime="2014-06-25T17:46:42" webUrl="http://www.gocd.cf-app.com/go/pipelines/Acceptance/145/provision/1" />
<Project name="aBadPipeline :: aBrokenStage :: anEvilJob" activity="Sleeping" lastBuildStatus="Failure" lastBuildLabel="145" lastBuildTime="2014-06-25T18:55:27" webUrl="http://www.gocd.cf-app.com/go/tab/build/detail/Acceptance/145/promote/1/tag" />

<Project name="Pipeline :: SomeStage" activity="Building" lastBuildStatus="Success" lastBuildLabel="1" lastBuildTime="2015-12-25T17:46:42" webUrl="http://www.example.com/go/pipelines/Acceptance/145/provision/1" />
<Project name="Pipeline :: SomeStage :: job" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="1" lastBuildTime="2015-12-25T17:46:42" webUrl="http://www.example.com/go/pipelines/Acceptance/145/provision/1" />
<Project name="Pipeline :: SomeStage :: jobWorking" activity="Building" lastBuildStatus="Success" lastBuildLabel="1" lastBuildTime="2015-12-25T17:46:42" webUrl="http://www.example.com/go/pipelines/Acceptance/145/provision/1" />

<Project name="Pipeline :: OtherStage" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="1" lastBuildTime="2015-12-25T17:46:42" webUrl="http://www.example.com/go/pipelines/Acceptance/145/provision/1" />
<Project name="Pipeline :: OtherStage2" activity="Building" lastBuildStatus="Success" lastBuildLabel="1" lastBuildTime="2015-12-25T17:46:42" webUrl="http://www.example.com/go/pipelines/Acceptance/145/provision/1" />

<Project name="Pipeline_1.0 :: SomeStage" activity="Building" lastBuildStatus="Success" lastBuildLabel="1" lastBuildTime="2015-12-25T17:46:42" webUrl="http://www.example.com/go/pipelines/Acceptance/145/provision/1" />
<Project name="Pipeline_2.0 :: SomeStage" activity="Building" lastBuildStatus="Failure" lastBuildLabel="1" lastBuildTime="2015-12-25T17:46:42" webUrl="http://www.example.com/go/pipelines/Acceptance/145/provision/1" />
</Projects>
XML

Expand All @@ -30,18 +40,50 @@
it_returns_ok %w(http://cd-server.example.com/cctray.xml goodPipe)
it_returns_fail %w(http://cd-server.example.com/cctray.xml aBadPipeline)
it_returns_changing %w(http://cd-server.example.com/cctray.xml goodPipe)

context 'when it matches some pipeline names fully' do
it_returns_ok %w(http://cd-server.example.com/cctray.xml Pipeline)
end

context 'when it does not match any pipeline name fully' do
it_returns_fail %w(http://cd-server.example.com/cctray.xml Pipeline_)
end
end

context 'when using stage specific api' do
it_returns_ok %w(http://cd-server.example.com/cctray.xml goodPipe successfulStage)
it_returns_fail %w(http://cd-server.example.com/cctray.xml aBadPipeline aBrokenStage)
it_returns_changing %w(http://cd-server.example.com/cctray.xml goodPipe busyStage)

context 'when it matches some pipeline and job name fully' do
context "when check does not indicate changing" do
let(:opts) { %w(http://cd-server.example.com/cctray.xml Pipeline OtherStage) }

it "does not return changing result" do
subject.latest_status.as_json[:changing].should == false
end
end
end

it_returns_changing %w(http://cd-server.example.com/cctray.xml Pipeline OtherStag)
end

context 'when using job specific api' do
it_returns_ok %w(http://cd-server.example.com/cctray.xml goodPipe successfulStage reliablyExcellentJob)
it_returns_fail %w(http://cd-server.example.com/cctray.xml aBadPipeline aBrokenStage anEvilJob)
it_returns_changing %w(http://cd-server.example.com/cctray.xml goodPipe busyStage workingJob)

context 'when it matches some pipeline and job name fully' do
context "when check does not indicate changing" do
let(:opts) { %w(http://cd-server.example.com/cctray.xml Pipeline SomeStage job) }

it "does not return changing result" do
subject.latest_status.as_json[:changing].should == false
end
end
end

it_returns_changing %w(http://cd-server.example.com/cctray.xml Pipeline SomeStage jobWorking)
end

context 'when using basic auth' do
Expand Down
4 changes: 2 additions & 2 deletions scripts/specs/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require "spec_helper"

describe_check :Site do
it_returns_ok %w(http://www.google.com)
it_returns_ok %w(http://www.bing.com/)

# Google's non-www version redirects to www
it_returns_fail %w(http://google.com)
it_returns_fail %w(http://bing.com)
end