go_api_client 0.5.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.travis.yml +26 -0
  4. data/README.md +86 -0
  5. data/go_api_client.gemspec +11 -11
  6. data/lib/go_api_client/api/abstract_api.rb +12 -0
  7. data/lib/go_api_client/api/cctray.rb +53 -0
  8. data/lib/go_api_client/api/config.rb +60 -0
  9. data/lib/go_api_client/api/feed.rb +39 -0
  10. data/lib/go_api_client/api/job.rb +34 -0
  11. data/lib/go_api_client/api/pipeline.rb +87 -0
  12. data/lib/go_api_client/api/properties.rb +43 -0
  13. data/lib/go_api_client/api/stage.rb +45 -0
  14. data/lib/go_api_client/attribute_helper.rb +9 -0
  15. data/lib/go_api_client/client.rb +20 -0
  16. data/lib/go_api_client/domain/artifact.rb +16 -0
  17. data/lib/go_api_client/domain/author.rb +22 -0
  18. data/lib/go_api_client/domain/changeset.rb +13 -0
  19. data/lib/go_api_client/domain/config/job.rb +15 -0
  20. data/lib/go_api_client/domain/config/pipeline.rb +15 -0
  21. data/lib/go_api_client/domain/config/stage.rb +15 -0
  22. data/lib/go_api_client/domain/entry.rb +13 -0
  23. data/lib/go_api_client/domain/feed.rb +13 -0
  24. data/lib/go_api_client/domain/internal_cache.rb +28 -0
  25. data/lib/go_api_client/domain/job.rb +17 -0
  26. data/lib/go_api_client/domain/material.rb +14 -0
  27. data/lib/go_api_client/domain/pipeline.rb +27 -0
  28. data/lib/go_api_client/domain/project.rb +14 -0
  29. data/lib/go_api_client/domain/scheduled_job.rb +12 -0
  30. data/lib/go_api_client/domain/stage.rb +28 -0
  31. data/lib/go_api_client/domain/user.rb +30 -0
  32. data/lib/go_api_client/http_fetcher.rb +73 -48
  33. data/lib/go_api_client/parsers/artifact_parser.rb +17 -0
  34. data/lib/go_api_client/parsers/author_parser.rb +24 -0
  35. data/lib/go_api_client/parsers/changeset.rb +26 -0
  36. data/lib/go_api_client/parsers/config/job_parser.rb +48 -0
  37. data/lib/go_api_client/parsers/config/pipeline_parser.rb +42 -0
  38. data/lib/go_api_client/parsers/config/stage_parser.rb +33 -0
  39. data/lib/go_api_client/parsers/entry_parser.rb +27 -0
  40. data/lib/go_api_client/parsers/feed_parser.rb +27 -0
  41. data/lib/go_api_client/parsers/job_parser.rb +47 -0
  42. data/lib/go_api_client/parsers/material_parser.rb +29 -0
  43. data/lib/go_api_client/parsers/parser_helper.rb +11 -0
  44. data/lib/go_api_client/parsers/pipeline_parser.rb +30 -0
  45. data/lib/go_api_client/parsers/project_parser.rb +26 -0
  46. data/lib/go_api_client/parsers/scheduled_job_parser.rb +28 -0
  47. data/lib/go_api_client/parsers/stage_parser.rb +31 -0
  48. data/lib/go_api_client/parsers/user_parser.rb +12 -0
  49. data/lib/go_api_client/version.rb +4 -4
  50. data/lib/go_api_client.rb +56 -110
  51. data/test/go_api_client/artifact_test.rb +8 -8
  52. data/test/go_api_client/author_test.rb +27 -0
  53. data/test/go_api_client/building_test.rb +21 -19
  54. data/test/go_api_client/{atom/entry_test.rb → entry_test.rb} +8 -8
  55. data/test/go_api_client/job_test.rb +15 -14
  56. data/test/go_api_client/pipeline_test.rb +24 -27
  57. data/test/go_api_client/stage_test.rb +21 -74
  58. data/test/go_api_client/user_test.rb +15 -20
  59. metadata +108 -78
  60. data/.init.sh +0 -8
  61. data/.rbenv-gemsets +0 -1
  62. data/.ruby-version +0 -1
  63. data/.rvmrc +0 -1
  64. data/.yardopts +0 -6
  65. data/Gemfile.lock +0 -32
  66. data/README.textile +0 -64
  67. data/lib/go_api_client/artifact.rb +0 -27
  68. data/lib/go_api_client/atom/author.rb +0 -42
  69. data/lib/go_api_client/atom/entry.rb +0 -34
  70. data/lib/go_api_client/atom/feed.rb +0 -40
  71. data/lib/go_api_client/atom/feed_page.rb +0 -49
  72. data/lib/go_api_client/atom.rb +0 -4
  73. data/lib/go_api_client/commit.rb +0 -30
  74. data/lib/go_api_client/helpers/simple_attribute_support.rb +0 -11
  75. data/lib/go_api_client/helpers.rb +0 -1
  76. data/lib/go_api_client/job.rb +0 -68
  77. data/lib/go_api_client/pipeline.rb +0 -48
  78. data/lib/go_api_client/stage.rb +0 -57
  79. data/lib/go_api_client/user.rb +0 -36
  80. data/test/go_api_client/atom/author_test.rb +0 -27
  81. data/test/go_api_client/atom/feed_page_test.rb +0 -41
  82. data/test/go_api_client/atom/feed_test.rb +0 -39
  83. data/test/go_api_client/commit_test.rb +0 -38
  84. data/test/schedule_test.rb +0 -12
@@ -1,48 +0,0 @@
1
- module GoApiClient
2
- class Pipeline
3
- attr_accessor :url, :commits, :label, :counter, :authors, :stages, :name, :http_fetcher, :identifier, :schedule_time, :branch_name
4
-
5
- include GoApiClient::Helpers::SimpleAttributesSupport
6
-
7
- def initialize(root, attributes={})
8
- @root = root
9
- super(attributes)
10
- end
11
-
12
- class << self
13
- def from(url, attributes = {})
14
- attributes[:http_fetcher] ||= GoApiClient::HttpFetcher.new
15
- doc = Nokogiri::XML(attributes[:http_fetcher].get!(url))
16
- self.new(doc.root, attributes).parse!
17
- end
18
- end
19
-
20
- def stages
21
- @stages ||= []
22
- end
23
-
24
- def parse!
25
- self.name = @root.attributes["name"].value
26
- self.label = @root.attributes["label"].value
27
- self.counter = @root.attributes["counter"].value.to_i
28
- self.url = href_from(@root.xpath("./link[@rel='self']"))
29
- self.identifier = @root.xpath("./id").first.content
30
- self.schedule_time = Time.parse(@root.xpath('./scheduleTime').first.content).utc
31
- self.commits = @root.xpath('./materials/material[@type = "GitMaterial"]/modifications/changeset').collect do |changeset|
32
- Commit.new(changeset).parse!
33
- end
34
-
35
- @root = nil
36
- self
37
- end
38
-
39
- def authors
40
- @authors ||= stages.first.authors
41
- end
42
-
43
- private
44
- def href_from(xml)
45
- xml.first.attribute('href').value unless xml.empty?
46
- end
47
- end
48
- end
@@ -1,57 +0,0 @@
1
- require 'time'
2
- module GoApiClient
3
- class Stage
4
- attr_accessor :authors, :url, :name, :result, :jobs, :pipeline, :completed_at, :pipeline_cache, :http_fetcher, :counter, :identifier
5
-
6
- include GoApiClient::Helpers::SimpleAttributesSupport
7
-
8
- def initialize(root, attributes={})
9
- @root = root
10
- super(attributes)
11
- end
12
-
13
- class << self
14
- def from(url, attributes = {})
15
- attributes[:http_fetcher] ||= GoApiClient::HttpFetcher.new
16
- doc = Nokogiri::XML(attributes[:http_fetcher].get!(url))
17
- self.new(doc.root, attributes).parse!
18
- end
19
- end
20
-
21
- def parse!
22
- self.name = @root.attributes['name'].value
23
- self.counter = @root.attributes['counter'].value.to_i
24
- self.url = href_from(@root.xpath("./link[@rel='self']"))
25
- self.result = @root.xpath("./result").first.content
26
- self.completed_at = Time.parse(@root.xpath("./updated").first.content).utc
27
- self.jobs = @root.xpath("./jobs/job").collect do |job_element|
28
- Job.from(job_element.attributes["href"].value, :http_fetcher => http_fetcher)
29
- end
30
- self.identifier = @root.xpath('./id').first.content
31
-
32
- pipeline_link = @root.xpath("./pipeline").first.attributes["href"].value
33
-
34
- pipeline = @pipeline_cache[pipeline_link] || Pipeline.from(pipeline_link, :http_fetcher => http_fetcher)
35
- pipeline.stages << self
36
-
37
- self.pipeline_cache[pipeline_link] ||= pipeline
38
- @root = nil
39
- self
40
- end
41
-
42
- def failed?
43
- "Failed" == @result
44
- end
45
-
46
- def passed?
47
- !failed?
48
- end
49
-
50
- private
51
- def href_from(xml)
52
- xml.first.attribute('href').value unless xml.empty?
53
- end
54
-
55
- end
56
- end
57
-
@@ -1,36 +0,0 @@
1
- module GoApiClient
2
- class User
3
-
4
- attr_accessor :name, :email
5
-
6
- def initialize(name, email)
7
- @name = name
8
- @email = email
9
- end
10
-
11
- def ==(other)
12
- other && self.class.equal?(other.class) &&
13
- name == other.name &&
14
- email == other.email
15
- end
16
-
17
- def hash
18
- self.class.hash ^ name.hash ^ email.hash
19
- end
20
-
21
- def to_s
22
- "#{name} <#{email}>"
23
- end
24
-
25
- def inspect
26
- "User(#{to_s})"
27
- end
28
-
29
- class << self
30
- def parse(str)
31
- _, name, email = *str.match(/(.*) <(.+?)>/)
32
- self.new(name.strip, email.strip)
33
- end
34
- end
35
- end
36
- end
@@ -1,27 +0,0 @@
1
- require "test_helper"
2
-
3
- module GoApiClient
4
- module Atom
5
- class AuthorTest < Test::Unit::TestCase
6
-
7
- test "should be able to parse author's info" do
8
- doc = Nokogiri::XML(%Q{<author xmlns="http://www.w3.org/2005/Atom"><name><![CDATA[oogabooga <twgosaas@gmail.com>]]></name><uri>http://oogabooga.example.com<uri></author>})
9
- author = Author.new(doc.root).parse!
10
- assert_equal Author.new(nil, :name => 'oogabooga', :email => 'twgosaas@gmail.com', :uri => 'http://oogabooga.example.com'), author
11
- end
12
-
13
- test "should be able to parse author xml with no email and uri" do
14
- doc = Nokogiri::XML(%Q{<author xmlns="http://www.w3.org/2005/Atom"><name><![CDATA[oogabooga]]></name></author>})
15
- author = Author.new(doc.root).parse!
16
- assert_equal Author.new(nil, :name => 'oogabooga'), author
17
- end
18
-
19
- test "should be able to parse author xml with email specified in the name tag" do
20
- doc = Nokogiri::XML(%Q{<author xmlns="http://www.w3.org/2005/Atom"><name><![CDATA[oogabooga <twgosaas@gmail.com>]]></name></author>})
21
- author = Author.new(doc.root).parse!
22
- assert_equal Author.new(nil, :name => 'oogabooga', :email => 'twgosaas@gmail.com'), author
23
- end
24
-
25
- end
26
- end
27
- end
@@ -1,41 +0,0 @@
1
- require "test_helper"
2
-
3
- module GoApiClient
4
- module Atom
5
- class FeedPageTest < Test::Unit::TestCase
6
-
7
- setup do
8
- doc = Nokogiri::XML(file_contents("pagination/stages.xml"))
9
- @feed_page = FeedPage.new(doc.root).parse!
10
- end
11
-
12
- test "should be able to parse one page of the paginated Go atom feed" do
13
- assert_equal 25, @feed_page.entries.count
14
- assert_equal 'https://go-server.example.com/go/api/pipelines/tlb/stages.xml', @feed_page.url
15
- assert_equal 'https://go-server.example.com/go/api/pipelines/tlb/stages.xml?before=7959831', @feed_page.next_page
16
- assert_equal Time.parse('2012-04-17 10:56:53 UTC'), @feed_page.updated_at
17
- end
18
-
19
- test "should answer if an entry id is present in the feed page" do
20
- assert @feed_page.contains_entry?(@feed_page.entries[5].id)
21
- assert_false @feed_page.contains_entry?("foo")
22
- end
23
-
24
- test "should answer if an entry object is present in the feed page" do
25
- assert @feed_page.contains_entry?(@feed_page.entries[5])
26
- assert_false @feed_page.contains_entry?(Entry.new(nil))
27
- end
28
-
29
- test "should return entries after a particular entry (top entries in feed)" do
30
- entry = @feed_page.entries[5]
31
-
32
- assert_equal @feed_page.entries_after(entry.id), @feed_page.entries_after(entry)
33
-
34
- assert_equal 5, @feed_page.entries_after(entry.id).count
35
- assert_equal 5, @feed_page.entries_after(entry).count
36
-
37
- assert_false @feed_page.entries_after(entry).include?(entry)
38
- end
39
- end
40
- end
41
- end
@@ -1,39 +0,0 @@
1
- require "test_helper"
2
-
3
- module GoApiClient
4
- module Atom
5
- class FeedTest < Test::Unit::TestCase
6
- setup do
7
- stub_request(:get, "https://go-server.example.com/go/api/pipelines/tlb/stages.xml").to_return(:body => file_contents("pagination/stages.xml"))
8
- stub_request(:get, "https://go-server.example.com/go/api/pipelines/tlb/stages.xml?before=7959831").to_return(:body => file_contents("pagination/stages_before_7959831.xml"))
9
- end
10
-
11
- test "should stop at last seen atom entry id" do
12
- feed = GoApiClient::Atom::Feed.new('https://go-server.example.com/go/api/pipelines/tlb/stages.xml', 'https://go-server.example.com/go/pipelines/tlb/175/ant_count_tlb/1').fetch!
13
- assert_equal (25+4), feed.entries.count
14
- end
15
-
16
- test "should stop at first page if entry id not specified" do
17
- stub_request(:get, "https://go-server.example.com/go/api/pipelines/tlb/stages.xml?before=7916973").to_return(:body => file_contents("pagination/stages_before_7916973.xml"))
18
-
19
- feed = GoApiClient::Atom::Feed.new('https://go-server.example.com/go/api/pipelines/tlb/stages.xml').fetch!
20
- assert_equal 25*3, feed.entries.count
21
- end
22
-
23
- test "should fetch all the pipelines" do
24
- stub_request(:get,"https://localhost:8153/go/api/pipelines.xml" ).to_return(:body => file_contents("pipelines.xml"))
25
- stub_request(:get,"http://localhost:8153/go/api/pipelines/defaultPipeline/stages.xml" ).to_return(:body => file_contents("default_pipeline.xml"))
26
- stub_request(:get,"http://localhost:8153/go/api/pipelines/integrationPipeline/stages.xml" ).to_return(:body => file_contents("integration_pipeline.xml"))
27
-
28
- feeds = GoApiClient::Atom::Feed.new("https://localhost:8153/go/api/pipelines.xml", nil).fetch_all!
29
- assert_equal 2, feeds.count
30
- assert_equal "http://localhost:8153/go/api/pipelines/defaultPipeline/stages.xml", feeds.keys[0]
31
- assert_equal "http://localhost:8153/go/api/pipelines/integrationPipeline/stages.xml", feeds.keys[1]
32
-
33
- assert_equal 1, feeds.values[0].entries.count
34
- assert_equal 1, feeds.values[1].entries.count
35
- end
36
- end
37
-
38
- end
39
- end
@@ -1,38 +0,0 @@
1
- require "test_helper"
2
-
3
- module GoApiClient
4
- class CommitTest < Test::Unit::TestCase
5
-
6
- test "should parse a changeset xml node" do
7
- doc = Nokogiri::XML.parse %q{<changeset changesetUri="http://localhost:8153/go/api/materials/1/changeset/9f77888d7a594699894a17f4d61fc9dfac3cfb74.xml">
8
- <bar>
9
- <revision>jhgasdfjkhgads</revision>
10
- <message>some message</message>
11
- <checkinTime>unparsable cruft</checkinTime>
12
- <user>unparsable cruft</user>
13
- </bar>
14
-
15
- <user><![CDATA[oogabooga <twgosaas@gmail.com>]]></user>
16
- <checkinTime>2012-02-21T15:41:30+05:30</checkinTime>
17
- <revision><![CDATA[9f77888d7a594699894a17f4d61fc9dfac3cfb74]]></revision>
18
- <message><![CDATA[Update README]]></message>
19
- <file name="README" action="modified"/>
20
- <foo>
21
- <revision>jhgasdfjkhgads</revision>
22
- <message>some message</message>
23
- <checkinTime>unparsable cruft</checkinTime>
24
- <user>unparsable cruft</user>
25
- </foo>
26
- </changeset>
27
- }
28
-
29
- commit = Commit.new(doc.root).parse!
30
-
31
- assert_equal '9f77888d7a594699894a17f4d61fc9dfac3cfb74', commit.revision
32
- assert_equal 'Update README', commit.message
33
- assert_equal Time.parse("2012-02-21 10:11:30 UTC"), commit.time
34
- assert_equal User.parse("oogabooga <twgosaas@gmail.com>"), commit.user
35
- end
36
-
37
- end
38
- end
@@ -1,12 +0,0 @@
1
- require "test_helper"
2
-
3
- module GoApiClient
4
- class ScheduleTest < Test::Unit::TestCase
5
- test "should schedule a build specified" do
6
- stub_request(:post, "http://go-server.2.project:8153/go/api/pipelines/defaultPipeline/schedule")
7
- GoApiClient.schedule_pipeline(:host => 'go-server.2.project')
8
-
9
- assert_requested(:post, "http://go-server.2.project:8153/go/api/pipelines/defaultPipeline/schedule", :body => '')
10
- end
11
- end
12
- end