Module: GoApiClient

Defined in:
lib/go_api_client.rb,
lib/go_api_client/job.rb,
lib/go_api_client/user.rb,
lib/go_api_client/stage.rb,
lib/go_api_client/commit.rb,
lib/go_api_client/engine.rb,
lib/go_api_client/logger.rb,
lib/go_api_client/version.rb,
lib/go_api_client/artifact.rb,
lib/go_api_client/pipeline.rb,
lib/go_api_client/atom/feed.rb,
lib/go_api_client/atom/entry.rb,
lib/go_api_client/atom/author.rb,
lib/go_api_client/http_fetcher.rb,
lib/go_api_client/atom/feed_page.rb,
lib/go_api_client/helpers/simple_attribute_support.rb

Defined Under Namespace

Modules: Atom, Helpers, Version Classes: Artifact, Commit, Engine, HttpFetcher, Job, LastRun, Pipeline, Stage, User

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/go_api_client/logger.rb', line 5

def logger
  @logger
end

Class Method Details

.all_runs(options = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/go_api_client.rb', line 64

def all_runs(options={})
  options = ({:ssl => false, :host => 'localhost', :port => 8153, :username => nil, :password => nil}).merge(options)
  http_fetcher = GoApiClient::HttpFetcher.new(:username => options[:username], :password => options[:password])
  feed_url = "#{options[:ssl] ? 'https' : 'http'}://#{options[:host]}:#{options[:port]}/go/api/pipelines.xml"
  feed = GoApiClient::Atom::Feed.new(feed_url, nil)
  feed = feed.fetch_all!(http_fetcher)
  feed.inject({}) do |memo, (href, entries)|
    memo[href] = construct_last_run(entries, http_fetcher, nil)
    memo
  end
end

.build_finished?(options) ⇒ Boolean

Answers if a build is in completed. For the list of supported connection options see #runs

Returns:

  • (Boolean)

See Also:



89
90
91
# File 'lib/go_api_client.rb', line 89

def build_finished?(options)
  !build_in_progress?(options)
end

.build_in_progress?(options = {}) ⇒ Boolean

Answers if a build is in progress. For the list of supported connection options see #runs

Returns:

  • (Boolean)

See Also:



78
79
80
81
82
83
84
85
# File 'lib/go_api_client.rb', line 78

def build_in_progress?(options={})
  raise ArgumentError("Hostname is mandatory") unless options[:host]
  options = ({:ssl => false, :port => 8153, :username => nil, :password => nil, :pipeline_name => 'defaultPipeline'}).merge(options)
  http_fetcher = GoApiClient::HttpFetcher.new(:username => options[:username], :password => options[:password])
  url = "#{options[:ssl] ? 'https' : 'http'}://#{options[:host]}:#{options[:port]}/go/cctray.xml"
  doc = Nokogiri::XML(http_fetcher.get!(url))
  doc.css("Project[activity='Building'][name^='#{options[:pipeline_name]} ::']").count > 0
end

.runs(options = {}) ⇒ LastRun

Connects to the a go server via the Atom Feed API and fetches entire the pipeline history for that pipeline. Since this this is a wrapper around an atom feed, it is important to remember the last atom feed entry that was seen in order to prevent crawling the entire atom feed over and over again and slow the process down.

Parameters:

  • options (Hash) (defaults to: {})

    the connection options

Options Hash (options):

  • :host (String) — default: "localhost"

    Host to connect to.

  • :port (Ingeger) — default: 8153

    Port to connect to.

  • :ssl (Boolean) — default: false

    If connection should be made over ssl.

  • :username (String) — default: nil

    The username to be used if server or the pipeline requires authorization.

  • :password (String) — default: nil

    The password to be used if server or the pipeline requires authorization.

  • :pipeline_name (String)

    The name of the pipeline that should be fetched.

  • :latest_atom_entry_id (String) — default: nil

    The id of the last atom feed entry

Returns:

  • (LastRun)

    an object containing a list of all pipelines ordered by their counter along with the last stage that ran in the pipeline



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/go_api_client.rb', line 52

def runs(options={})
  options = ({:ssl => false, :host => 'localhost', :port => 8153, :username => nil, :password => nil, :latest_atom_entry_id => nil}).merge(options)

  http_fetcher = GoApiClient::HttpFetcher.new(:username => options[:username], :password => options[:password])

  pipeline_name = options[:pipeline_name] || "defaultPipeline"
  feed_url = "#{options[:ssl] ? 'https' : 'http'}://#{options[:host]}:#{options[:port]}/go/api/pipelines/#{pipeline_name}/stages.xml"
  feed = GoApiClient::Atom::Feed.new(feed_url, options[:latest_atom_entry_id])
  feed.fetch!(http_fetcher)
  return construct_last_run(feed, http_fetcher, options[:latest_atom_entry_id])
end

.schedule_pipeline(options) ⇒ Object

Schedule a particular pipeline with the latest available materials.



94
95
96
97
98
99
100
# File 'lib/go_api_client.rb', line 94

def schedule_pipeline(options)
  raise ArgumentError("Hostname is mandatory") unless options[:host]
  options = ({:ssl => false, :port => 8153, :username => nil, :password => nil, :pipeline_name => 'defaultPipeline'}).merge(options)

  uri = "#{options[:ssl] ? 'https' : 'http'}://#{options[:host]}:#{options[:port]}/go/api/pipelines/#{options[:pipeline_name]}/schedule"
  GoApiClient::HttpFetcher.new.post!(uri)
end