go_api_client 0.5.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,43 @@
1
+ require 'csv'
2
+
3
+ module GoApiClient
4
+ module Api
5
+ class Properties < GoApiClient::Api::AbstractApi
6
+
7
+ def initialize(attributes = {})
8
+ super(attributes)
9
+ end
10
+
11
+ def properties(options = {})
12
+ options = ({:properties_uri => nil, :pipeline_name => nil, :pipeline_counter => nil, :stage_name => nil, :stage_counter => nil, :job_name => nil, :property_name => nil}).merge(options)
13
+ if options[:properties_uri]
14
+ uri = options[:properties_uri]
15
+ else
16
+ raise 'Insufficient arguments' unless options[:pipeline_name] && options[:pipeline_counter] && options[:stage_name] && options[:stage_counter] && options[:job_name]
17
+ uri = "#{@base_uri}/properties/#{options[:pipeline_name]}/#{options[:pipeline_counter]}/#{options[:stage_name]}/#{options[:stage_counter]}/#{options[:job_name]}" + (options[:property_name] ? "/#{options[:property_name]}" : '')
18
+ end
19
+
20
+ begin
21
+ body = @http_fetcher.get!(uri)
22
+ rescue GoApiClient::HttpFetcher::HttpError
23
+ # ignore, error message will be logged
24
+ end
25
+
26
+ body ? CSV.new(body, :headers => true).to_a.map { |row| row.to_hash } : []
27
+ end
28
+
29
+ def create_property(options = {})
30
+ options = ({:properties_uri => nil, :pipeline_name => nil, :pipeline_counter => nil, :stage_name => nil, :stage_counter => nil, :job_name => nil, :property_name => nil, :property_value => nil}).merge(options)
31
+ if options[:properties_uri]
32
+ uri = options[:properties_uri]
33
+ else
34
+ raise 'Insufficient arguments' unless options[:pipeline_name] && options[:pipeline_counter] && options[:stage_name] && options[:stage_counter] && options[:job_name] && options[:property_name] && options[:property_value]
35
+ uri = "#{@base_uri}/properties/#{options[:pipeline_name]}/#{options[:pipeline_counter]}/#{options[:stage_name]}/#{options[:stage_counter]}/#{options[:job_name]}/#{options[:property_name]}"
36
+ end
37
+
38
+ response_body = @http_fetcher.post!(uri, {:params => {:value => options[:property_value]}})
39
+ response_body == "Property '#{options[:property_name]}' created with value '#{options[:property_value]}'" ? true : false
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,45 @@
1
+ require 'nokogiri'
2
+
3
+ module GoApiClient
4
+ module Api
5
+ class Stage < GoApiClient::Api::AbstractApi
6
+
7
+ def initialize(attributes = {})
8
+ attributes = ({:pipeline_cache => {}, :stage_cache => {}}).merge(attributes)
9
+ super(attributes)
10
+ end
11
+
12
+ def stage(options = {})
13
+ options = ({:stage_uri => nil, :stage_id => nil, :pipeline_name => nil, :pipeline_tag => nil, :stage_name => nil, :stage_counter => nil, :eager_parser => []}).merge(options)
14
+ if options[:stage_uri]
15
+ uri = options[:stage_uri]
16
+ elsif options[:stage_id]
17
+ uri = "#{@base_uri}/api/stages/#{options[:stage_id]}.xml"
18
+ else
19
+ raise 'Insufficient arguments' unless options[:pipeline_name] && options[:pipeline_tag] && options[:stage_name] && options[:stage_counter]
20
+ uri = "#{@base_uri}/pipelines/#{options[:pipeline_name]}/#{options[:pipeline_tag]}/#{options[:stage_name]}/#{options[:stage_counter]}.xml"
21
+ end
22
+ stage = GoApiClient::Parsers::Stage.parse(Nokogiri::XML(@http_fetcher.get!(uri)).root)
23
+ @stage_cache[GoApiClient::Domain::InternalCache.new(stage.self_uri, options)] ||= stage
24
+ if options[:eager_parser]
25
+ if options[:eager_parser].include?(:job)
26
+ job_api = GoApiClient::Api::Job.new({:base_uri => @base_uri, :http_fetcher => @http_fetcher})
27
+ stage.parsed_jobs = stage.jobs.collect do |job_uri|
28
+ job_api.job(options.merge({:job_uri => job_uri}))
29
+ end
30
+ end
31
+ if options[:eager_parser].include?(:pipeline)
32
+ pipeline_api = GoApiClient::Api::Pipeline.new({:base_uri => @base_uri, :http_fetcher => @http_fetcher, :pipeline_cache => @pipeline_cache, :stage_cache => @stage_cache})
33
+ pipeline = @pipeline_cache[GoApiClient::Domain::InternalCache.new(stage.pipeline_uri, options)] || pipeline_api.pipeline(options.merge({:pipeline_uri => stage.pipeline_uri}))
34
+ @pipeline_cache[GoApiClient::Domain::InternalCache.new(stage.pipeline_uri, options)] ||= pipeline
35
+ stage.parsed_pipeline = pipeline
36
+ end
37
+ end
38
+ stage
39
+ end
40
+
41
+ private
42
+ attr_accessor :pipeline_cache, :stage_cache
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,9 @@
1
+ module GoApiClient
2
+ class AttributeHelper
3
+ def initialize(attributes={})
4
+ attributes.each do |name, value|
5
+ send("#{name}=", value) unless value.to_s.empty?
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ module GoApiClient
2
+ class Client
3
+ def initialize(options={})
4
+ options = ({:uri => nil, :username => nil, :password => nil, :ssl_verify_mode => nil}).merge(options)
5
+ @http_fetcher = GoApiClient::HttpFetcher.new(options)
6
+ if options[:uri]
7
+ @base_uri = options[:uri].chomp('/')
8
+ else
9
+ options = ({:host => 'localhost', :port => 8153, :ssl => false}).merge(options)
10
+ @base_uri = "#{options[:ssl] ? 'https' : 'http'}://#{options[:host]}:#{options[:port]}/go"
11
+ end
12
+ end
13
+
14
+ def api(name, options={})
15
+ class_name = name.slice(0, 1).capitalize + name.slice(1..-1)
16
+ api_class = "#{self.class.to_s.split('::').first}::Api::#{class_name}".split('::').inject(Object) { |n, c| n.const_get c }
17
+ api_class.new({:base_uri => @base_uri, :http_fetcher => @http_fetcher}.merge(options))
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class Artifact < GoApiClient::AttributeHelper
4
+
5
+ attr_accessor :base_uri, :src, :dest, :artifact_type
6
+
7
+ def initialize(attributes)
8
+ super(attributes)
9
+ end
10
+
11
+ def as_zip_file_url
12
+ "#{File.join(base_uri, src)}.zip"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class Author < GoApiClient::AttributeHelper
4
+ attr_accessor :name, :email, :uri
5
+
6
+ def initialize(attributes={})
7
+ super(attributes)
8
+ end
9
+
10
+ def ==(other)
11
+ other && self.class.equal?(other.class) &&
12
+ name == other.name &&
13
+ email == other.email &&
14
+ uri == other.uri
15
+ end
16
+
17
+ def hash
18
+ self.class.hash ^ name.hash ^ email.hash ^ uri.hash
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class Changeset < GoApiClient::AttributeHelper
4
+
5
+ attr_accessor :parsed_user, :checkin_time, :revision, :message, :files, :uri
6
+
7
+ def initialize(attributes={})
8
+ super(attributes)
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module GoApiClient
2
+ module Domain
3
+ module Config
4
+ class Job < GoApiClient::AttributeHelper
5
+
6
+ attr_accessor :name
7
+ attr_accessor :parsed_tasks, :parsed_resources, :parsed_artifacts, :parsed_test_artifacts, :parsed_tabs
8
+
9
+ def initialize(attributes={})
10
+ super(attributes)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module GoApiClient
2
+ module Domain
3
+ module Config
4
+ class Pipeline < GoApiClient::AttributeHelper
5
+
6
+ attr_accessor :name, :label_template, :locked, :template, :timer
7
+ attr_accessor :parsed_params, :parsed_env_vars, :parsed_stages, :parsed_template
8
+
9
+ def initialize(attributes={})
10
+ super(attributes)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module GoApiClient
2
+ module Domain
3
+ module Config
4
+ class Stage < GoApiClient::AttributeHelper
5
+
6
+ attr_accessor :name, :fetch_materials, :approval, :clean_working_dir
7
+ attr_accessor :parsed_jobs, :parsed_env_vars
8
+
9
+ def initialize(attributes={})
10
+ super(attributes)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class Entry < GoApiClient::AttributeHelper
4
+
5
+ attr_accessor :updated, :title, :id, :stage_uri, :pipeline_uri
6
+ attr_accessor :parsed_categories, :parsed_authors, :parsed_pipeline, :parsed_stage
7
+
8
+ def initialize(attributes={})
9
+ super(attributes)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class Feed < GoApiClient::AttributeHelper
4
+
5
+ attr_accessor :updated, :title, :id, :self_uri, :next_uri
6
+ attr_accessor :parsed_entries, :parsed_authors
7
+
8
+ def initialize(attributes={})
9
+ super(attributes)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class InternalCache
4
+ attr_accessor :uri, :options
5
+
6
+ def initialize(uri, options = {})
7
+ @uri = uri
8
+ @options = options
9
+ end
10
+
11
+ def ==(other)
12
+ other && self.class.equal?(other.class) &&
13
+ @uri == other.uri &&
14
+ @options[:eager_parser] == other.options[:eager_parser]
15
+ end
16
+
17
+ def hash
18
+ @uri.hash ^ @options[:eager_parser].hash
19
+ end
20
+
21
+ def eql?(other)
22
+ other && self.class.equal?(other.class) &&
23
+ @uri.eql?(other.uri) &&
24
+ @options[:eager_parser].eql?(other.options[:eager_parser])
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class Job < GoApiClient::AttributeHelper
4
+
5
+ attr_accessor :artifacts_uri, :console_log_url, :self_uri, :id, :name, :parsed_artifacts,
6
+ :duration, :result, :scheduled, :assigned, :preparing, :building, :completing, :completed
7
+
8
+ def initialize(attributes={})
9
+ super(attributes)
10
+ end
11
+
12
+ def console_log_url
13
+ @console_log_url ||= "#{artifacts_uri}/cruise-output/console.log"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class Material < GoApiClient::AttributeHelper
4
+
5
+ attr_accessor :uri, :type, :pipeline_name, :stage_name, :branch, :url
6
+ attr_accessor :parsed_changesets
7
+
8
+ def initialize(attributes)
9
+ super(attributes)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,27 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class Pipeline < GoApiClient::AttributeHelper
4
+
5
+ # TODO: Add materials
6
+
7
+ # Self attributes
8
+ attr_accessor :name, :counter, :label
9
+ # Tags
10
+ attr_accessor :id, :self_uri, :inserted_after_uri, :schedule_time, :stages, :approved_by
11
+ # Parsed object
12
+ attr_accessor :parsed_stages, :parsed_materials
13
+
14
+ def initialize(attributes={})
15
+ super(attributes)
16
+ end
17
+
18
+ def stages
19
+ @stages ||= []
20
+ end
21
+
22
+ def authors
23
+ @authors ||= stages.first.authors
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class Project < GoApiClient::AttributeHelper
4
+
5
+ attr_accessor :name, :activity, :last_build_status, :last_build_label, :last_build_time, :web_uri
6
+ attr_accessor :parsed_messages, :parsed_pipeline_name, :parsed_stage_name, :parsed_job_name, :parsed_stage
7
+
8
+ def initialize(attributes)
9
+ super(attributes)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,12 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class ScheduledJob < GoApiClient::AttributeHelper
4
+
5
+ attr_accessor :name, :id, :self_uri, :build_locator, :resources, :environment_variables, :environment
6
+
7
+ def initialize(attributes={})
8
+ super(attributes)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class Stage < GoApiClient::AttributeHelper
4
+
5
+ # Self attributes
6
+ attr_accessor :name, :counter
7
+ # Tags
8
+ attr_accessor :id, :self_uri, :result, :state, :approved_by, :jobs, :updated
9
+ # Pipeline tag
10
+ attr_accessor :pipeline_name, :pipeline_counter, :pipeline_label, :pipeline_uri
11
+ # Parsed object
12
+ attr_accessor :parsed_pipeline, :parsed_jobs
13
+
14
+ def initialize(attributes={})
15
+ super(attributes)
16
+ end
17
+
18
+ def failed?
19
+ 'Failed' == @result
20
+ end
21
+
22
+ def passed?
23
+ !failed?
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,30 @@
1
+ module GoApiClient
2
+ module Domain
3
+ class User
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
+ end
29
+ end
30
+ end