go_api_client 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in go_api_client.gemspec
4
4
  gemspec
5
-
6
- gem "webmock"
@@ -5,9 +5,9 @@ require "go_api_client/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "go_api_client"
7
7
  s.version = GoApiClient::VERSION
8
- s.authors = ["Nikhil Mungel"]
9
- s.email = ["hyfather@gmail.com"]
10
- s.homepage = ""
8
+ s.authors = ["Nikhil Mungel", "Ketan Padegaonkar", "Shishir Das"]
9
+ s.email = ["hyfather@gmail.com", "KetanPadegaonkar@gmail.com", "shishir.das@gmail.com"]
10
+ s.homepage = "https://github.com/ThoughtWorksInc/go-api-client"
11
11
  s.summary = %q{Client to parse Go CI atom feed}
12
12
  s.description = %q{This gem parses atom feed generated by the Go Continuous Integration server and provides an OO representation of the pipelines and stages.}
13
13
 
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
22
+ s.add_development_dependency "webmock"
23
+
23
24
  s.add_runtime_dependency "nokogiri"
24
25
  end
@@ -1,10 +1,7 @@
1
1
  module GoApiClient
2
2
  module Atom
3
3
  class Feed
4
- attr_accessor :updated_at
5
- attr_accessor :next_page
6
- attr_accessor :url
7
- attr_accessor :entries
4
+ attr_accessor :updated_at, :next_page, :url, :entries
8
5
 
9
6
  def initialize(root)
10
7
  @root = root
@@ -12,14 +9,17 @@ module GoApiClient
12
9
 
13
10
  def parse!
14
11
  self.updated_at = @root.xpath('xmlns:updated').first.content
15
- self.next_page = @root.xpath("xmlns:link[@rel='next']").first.attribute('href').value
16
- self.url = @root.xpath("xmlns:link[@rel='self']").first.attribute('href').value
17
-
12
+ self.next_page = href_from(@root.xpath("xmlns:link[@rel='next']"))
13
+ self.url = href_from(@root.xpath("xmlns:link[@rel='self']"))
18
14
  self.entries = @root.xpath("xmlns:entry").collect do |entry|
19
15
  Entry.new(entry).parse!
20
16
  end
21
17
  self
22
18
  end
19
+
20
+ def href_from(xml)
21
+ xml.first.attribute('href').value unless xml.empty?
22
+ end
23
23
  end
24
24
  end
25
25
  end
@@ -18,11 +18,8 @@ module GoApiClient
18
18
 
19
19
  def authors
20
20
  authors = stages.map(&:authors).flatten
21
- authors.map(&:name).flatten.uniq.join(" ,")
22
- end
23
-
24
- def same?(link)
25
- @details_link == link
21
+ authors.map(&:name).flatten.uniq.join(", ")
26
22
  end
23
+
27
24
  end
28
25
  end
@@ -1,31 +1,28 @@
1
1
  module GoApiClient
2
2
  class Stage
3
- attr_reader :authors, :details_link, :name, :result, :jobs
3
+ attr_accessor :authors, :stage_link, :name, :result, :jobs, :pipeline
4
4
 
5
5
  def initialize(entry, pipelines)
6
6
  @authors = entry.authors
7
- @details_link = entry.stage_href
7
+ @stage_link = entry.stage_href
8
8
  @pipelines = pipelines
9
9
  end
10
10
 
11
11
  def fetch
12
- doc = Nokogiri::XML(open(self.details_link))
12
+ doc = Nokogiri::XML(open(self.stage_link))
13
13
  @name = doc.root.xpath("@name").first.value
14
14
  @result = doc.root.xpath("//result").first.content
15
15
  job_detail_links = doc.root.xpath("//job").collect{|job| job.attributes["href"]}
16
16
  @jobs = Job.build(self, job_detail_links)
17
-
17
+
18
18
  pipeline_link = doc.root.xpath("//pipeline").first.attributes["href"].value
19
- existing_pipeline = @pipelines.find {|p| p.same?(pipeline_link)}
20
-
21
- if existing_pipeline
22
- existing_pipeline.stages << self
23
- else
24
- new_pipeline = Pipeline.new(pipeline_link).fetch
25
- new_pipeline.stages << self
26
- @pipelines << new_pipeline
27
- end
28
- @pipelines
19
+
20
+ pipeline = @pipelines[pipeline_link] || Pipeline.new(pipeline_link).fetch
21
+ pipeline.stages << self
22
+
23
+ @pipelines[pipeline_link] ||= pipeline
24
+ self
29
25
  end
30
26
  end
31
27
  end
28
+
@@ -1,3 +1,3 @@
1
1
  module GoApiClient
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/go_api_client.rb CHANGED
@@ -11,10 +11,10 @@ module GoApiClient
11
11
  def self.runs(host)
12
12
  doc = Nokogiri::XML(open("http://#{host}/go/api/pipelines/defaultPipeline/stages.xml"))
13
13
  feed = GoApiClient::Atom::Feed.new(doc.root).parse!
14
- pipelines = []
15
- feed.entries.collect do |entry|
16
- pipelines = Stage.new(entry, pipelines).fetch
14
+ pipelines = {}
15
+ feed.entries.each do |entry|
16
+ Stage.new(entry, pipelines).fetch
17
17
  end
18
- pipelines
18
+ pipelines.values
19
19
  end
20
20
  end
@@ -0,0 +1,9 @@
1
+ <feed xmlns="http://www.w3.org/2005/Atom" xmlns:go="http://www.thoughtworks-studios.com/ns/go">
2
+ <title><![CDATA[defaultPipeline]]></title>
3
+ <id>http://localhost:8153/go/api/pipelines/defaultPipeline/stages.xml</id>
4
+ <author>
5
+ <name>Go</name>
6
+ </author>
7
+ <updated>2012-03-07T11:15:10+05:30</updated>
8
+ <link rel="self" href="http://localhost:8153/go/api/pipelines/defaultPipeline/stages.xml"/>
9
+ </feed>
@@ -1,25 +1,37 @@
1
1
  require "test_helper"
2
2
 
3
- class PipelineTest < Test::Unit::TestCase
3
+ module GoApiClient
4
+ class PipelineTest < Test::Unit::TestCase
4
5
 
5
- def setup()
6
- stub_request(:get, "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml").to_return(:body => file_contents("pipelines_1.xml"))
7
- end
6
+ def setup
7
+ stub_request(:get, "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml").to_return(:body => file_contents("pipelines_1.xml"))
8
+ end
8
9
 
9
- def test_fetch_populates_necessary_fields
10
- link = "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml"
11
- pipeline = GoApiClient::Pipeline.new(link)
12
- pipeline.fetch
10
+ def test_fetch_populates_necessary_fields
11
+ link = "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml"
12
+ pipeline = GoApiClient::Pipeline.new(link)
13
+ pipeline.fetch
13
14
 
14
- assert_equal "1", pipeline.label
15
- assert_equal ["Update README"], pipeline.commit_messages
16
- end
15
+ assert_equal "1", pipeline.label
16
+ assert_equal ["Update README"], pipeline.commit_messages
17
+ end
18
+
19
+ def test_should_return_string_delimited_list_of_authors
20
+ link = "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml"
21
+ pipeline = GoApiClient::Pipeline.new(link).fetch
22
+ author_foo = Atom::Author.new(nil)
23
+ author_foo.name = 'foo'
24
+ author_foo.email = 'foo@example.com'
25
+ author_foo.uri = 'http://foo.example.com'
26
+
27
+ author_bar = Atom::Author.new(nil)
28
+ author_bar.name = 'bar'
29
+ author_bar.email = 'bar@example.com'
30
+ author_bar.uri = 'http://bar.example.com'
17
31
 
18
- def test_pipeline_instance_identified_by_details_link
19
- link = "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml"
20
- pipeline = GoApiClient::Pipeline.new(link)
32
+ pipeline.stages << OpenStruct.new(:authors => [author_foo, author_bar])
33
+ assert_equal 'foo, bar', pipeline.authors
34
+ end
21
35
 
22
- assert pipeline.same?(link)
23
- assert(false == pipeline.same?("http://localhost:8153/go/api"))
24
36
  end
25
37
  end
@@ -1,32 +1,41 @@
1
1
  require "test_helper"
2
2
 
3
- class StageTest < Test::Unit::TestCase
3
+ module GoApiClient
4
+ class StageTest < Test::Unit::TestCase
4
5
 
5
- def setup()
6
- stub_request(:get, "http://localhost:8153/go/api/pipelines/defaultPipeline/stages.xml").to_return(:body => file_contents("stages.xml"))
7
- stub_request(:get, "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml").to_return(:body => file_contents("pipelines_1.xml"))
8
- stub_request(:get, "http://localhost:8153/go/api/stages/1.xml").to_return(:body => file_contents("stages_1.xml"))
9
- stub_request(:get, "http://localhost:8153/go/api/stages/2.xml").to_return(:body => file_contents("stages_2.xml"))
10
- stub_request(:get, "http://localhost:8153/go/api/jobs/1.xml").to_return(:body => file_contents("jobs_1.xml"))
11
- stub_request(:get, "http://localhost:8153/go/api/jobs/2.xml").to_return(:body => file_contents("jobs_2.xml"))
12
- end
6
+ def setup
7
+ stub_request(:get, "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml").to_return(:body => file_contents("pipelines_1.xml"))
8
+ stub_request(:get, "http://localhost:8153/go/api/stages/1.xml").to_return(:body => file_contents("stages_1.xml"))
9
+ stub_request(:get, "http://localhost:8153/go/api/stages/2.xml").to_return(:body => file_contents("stages_2.xml"))
10
+ stub_request(:get, "http://localhost:8153/go/api/jobs/1.xml").to_return(:body => file_contents("jobs_1.xml"))
11
+ stub_request(:get, "http://localhost:8153/go/api/jobs/2.xml").to_return(:body => file_contents("jobs_2.xml"))
12
+ end
13
+
14
+ def test_stage_parsing
15
+ stub_request(:get, "http://localhost:8153/go/api/pipelines/defaultPipeline/stages.xml").to_return(:body => file_contents("stages.xml"))
16
+ pipelines = GoApiClient.runs("localhost:8153")
17
+ stages = pipelines.first.stages
13
18
 
14
- def test_stage
15
- pipelines = GoApiClient.runs("localhost:8153")
16
- stages = pipelines.first.stages
17
-
18
- assert_equal 1, pipelines.count
19
- assert_equal 2, stages.count
20
- assert_equal "oogabooga <twgosaas@gmail.com>", pipelines.first.authors
21
- stages.each do |stage|
22
- assert_equal "oogabooga <twgosaas@gmail.com>", stage.authors.first.name
23
- assert_equal "Failed", stage.result
19
+ assert_equal 1, pipelines.count
20
+ assert_equal 2, stages.count
21
+ assert_equal "oogabooga <twgosaas@gmail.com>", pipelines.first.authors
22
+ stages.each do |stage|
23
+ assert_equal "oogabooga <twgosaas@gmail.com>", stage.authors.first.name
24
+ assert_equal "Failed", stage.result
25
+ end
26
+ assert_equal "Acceptance", stages.first.name
27
+ assert_equal "Units", stages.last.name
28
+ assert_equal ["Update README"], pipelines.first.commit_messages
29
+
30
+ assert_equal "http://localhost:8153/go/files/defaultPipeline/1/Acceptance/1/Test/cruise-output/console.log", stages.first.jobs.first.console_log_url
31
+ assert_equal "http://localhost:8153/go/files/defaultPipeline/1/Units/1/Test/cruise-output/console.log", stages.last.jobs.first.console_log_url
24
32
  end
25
- assert_equal "Acceptance", stages.first.name
26
- assert_equal "Units", stages.last.name
27
- assert_equal ["Update README"], pipelines.first.commit_messages
28
33
 
29
- assert_equal "http://localhost:8153/go/files/defaultPipeline/1/Acceptance/1/Test/cruise-output/console.log", stages.first.jobs.first.console_log_url
30
- assert_equal "http://localhost:8153/go/files/defaultPipeline/1/Units/1/Test/cruise-output/console.log", stages.last.jobs.first.console_log_url
34
+ def test_empty_atom_feed_should_not_throw_up
35
+ stub_request(:get, "http://localhost:8153/go/api/pipelines/defaultPipeline/stages.xml").to_return(:body => file_contents("stages_empty.xml"))
36
+ pipelines = GoApiClient.runs("localhost:8153")
37
+
38
+ assert pipelines.empty?
39
+ end
31
40
  end
32
41
  end
data/test/test_helper.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  require 'test/unit'
2
2
  require 'go_api_client'
3
- Dir["go_api_client/**/*.rb"].each {|f| require f}
3
+ require 'ostruct'
4
+ Dir["go_api_client/**/*.rb"].each {|f| require f}
4
5
  require 'webmock/test_unit'
5
6
 
6
7
  def file_contents(file_name)
7
8
  File.read(File.expand_path("../../test/fixtures/#{file_name}", __FILE__))
8
9
  end
9
10
 
10
-
11
+ module Test::Unit::Assertions
12
+ def assert_false(test, failure_message = nil)
13
+ assert(!test, failure_message || "Expected <#{test}> to be <false>.")
14
+ end
15
+ end
metadata CHANGED
@@ -1,19 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: go_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nikhil Mungel
9
+ - Ketan Padegaonkar
10
+ - Shishir Das
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
12
- date: 2012-02-28 00:00:00.000000000Z
14
+ date: 2012-03-07 00:00:00.000000000Z
13
15
  dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: webmock
18
+ requirement: &70210519943860 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *70210519943860
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: nokogiri
16
- requirement: &70186482958560 !ruby/object:Gem::Requirement
29
+ requirement: &70210519941940 !ruby/object:Gem::Requirement
17
30
  none: false
18
31
  requirements:
19
32
  - - ! '>='
@@ -21,11 +34,13 @@ dependencies:
21
34
  version: '0'
22
35
  type: :runtime
23
36
  prerelease: false
24
- version_requirements: *70186482958560
37
+ version_requirements: *70210519941940
25
38
  description: This gem parses atom feed generated by the Go Continuous Integration
26
39
  server and provides an OO representation of the pipelines and stages.
27
40
  email:
28
41
  - hyfather@gmail.com
42
+ - KetanPadegaonkar@gmail.com
43
+ - shishir.das@gmail.com
29
44
  executables:
30
45
  - go_api_client
31
46
  extensions: []
@@ -55,10 +70,11 @@ files:
55
70
  - test/fixtures/stages.xml
56
71
  - test/fixtures/stages_1.xml
57
72
  - test/fixtures/stages_2.xml
73
+ - test/fixtures/stages_empty.xml
58
74
  - test/go_api_client/pipeline_test.rb
59
75
  - test/go_api_client/stage_test.rb
60
76
  - test/test_helper.rb
61
- homepage: ''
77
+ homepage: https://github.com/ThoughtWorksInc/go-api-client
62
78
  licenses: []
63
79
  post_install_message:
64
80
  rdoc_options: []
@@ -91,6 +107,7 @@ test_files:
91
107
  - test/fixtures/stages.xml
92
108
  - test/fixtures/stages_1.xml
93
109
  - test/fixtures/stages_2.xml
110
+ - test/fixtures/stages_empty.xml
94
111
  - test/go_api_client/pipeline_test.rb
95
112
  - test/go_api_client/stage_test.rb
96
113
  - test/test_helper.rb