gocd 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63993090abad17999418558d8b6e606750f54040
4
- data.tar.gz: 4307c49d5512dde53787187d2ddb03d9c2b6fe1d
3
+ metadata.gz: 73f02afa4f1563b4fc200676645ab8047153b75e
4
+ data.tar.gz: 7d25be9fbfe3c95a416512843dc5bed296da824d
5
5
  SHA512:
6
- metadata.gz: 68a632187ddaf3d085c44f325ae164798ed7c8f870f9a22649ef9696b2a76fd72c85b4c0dfbe046b650c07cdb9d3505d3b46833c5564fd2fe9d6311c91347d1a
7
- data.tar.gz: 8d4e5a047341f4a6ff82bbfdff73dd66e13962a959f383657716fd199577b7594194b80cd02d3dc92e54d86a04bcf0684192e8d1b2bfa36360fc8d2c3c79b20b
6
+ metadata.gz: 50d506196fffd2f73f7fd2dfe4e82850dc0281655368ce473b9c2bbebd92d01786a4ebcde9f7da90fc0520968f83d782132c017cf790d32522dee4b0c72b137a
7
+ data.tar.gz: bdca6eb4b5c49d67b6e09be596dbc05393d0ae5943eb424c179be0ff3105d6986fdbbf681fc64a902a5da2524d7783f2bbf3f8716c94aa894975dfce30783cab
@@ -0,0 +1,2 @@
1
+ .idea/
2
+ *.gem
@@ -1,27 +1,2 @@
1
- require 'active_support/core_ext/hash/conversions'
2
-
3
- module GOCD
4
- module PipelineStatus
5
- class BuildInformer
6
- def initialize(gocd_url)
7
- @pipeline_statuses ||= Hash.from_xml(`curl -s #{gocd_url}/go/cctray.xml`)
8
- end
9
-
10
- def information_available?
11
- !@pipeline_statuses.nil?
12
- end
13
-
14
- def red_pipelines
15
- pipelines.select { |stage| stage['lastBuildStatus'] == 'Failure' }
16
- end
17
-
18
- def status
19
- pipelines
20
- end
21
-
22
- def pipelines
23
- @pipeline_statuses['Projects']['Project']
24
- end
25
- end
26
- end
27
- end
1
+ project_root = File.dirname(File.absolute_path(__FILE__))
2
+ Dir.glob(project_root + '/gocd/**/*.rb', &method(:require))
@@ -0,0 +1,20 @@
1
+ module GOCD
2
+ class Credentials
3
+ def initialize(username, password)
4
+ @username = username
5
+ @password = password
6
+ end
7
+
8
+ def curl_credentials
9
+ "#{@username}:#{@password}"
10
+ end
11
+ end
12
+
13
+ def self.credentials=(credentials)
14
+ @credentials = credentials
15
+ end
16
+
17
+ def self.credentials
18
+ @credentials
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module GOCD
2
+ class Server
3
+ attr_reader :url
4
+
5
+ def initialize(url)
6
+ @url = url
7
+ end
8
+ end
9
+
10
+ def self.server=(server)
11
+ @server = server
12
+ end
13
+
14
+ def self.server
15
+ @server
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ class GOCDDataFetchException < Exception
2
+ end
@@ -0,0 +1,27 @@
1
+ module GOCD
2
+ class Pipeline
3
+ def initialize(pipeline)
4
+ @pipeline = pipeline
5
+ end
6
+
7
+ def name
8
+ @pipeline['name']
9
+ end
10
+
11
+ def last_build_status
12
+ @pipeline['lastBuildStatus']
13
+ end
14
+
15
+ def status
16
+ {pipeline: name, status: last_build_status}
17
+ end
18
+
19
+ def red?
20
+ @pipeline['lastBuildStatus'] == 'Failure'
21
+ end
22
+
23
+ def green?
24
+ @pipeline['lastBuildStatus'] == 'Success'
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ require 'active_support/core_ext/hash/conversions'
2
+
3
+ module GOCD
4
+ class PipelineRepository
5
+ def self.pipelines
6
+ @pipelines ||= fetch_data
7
+ end
8
+
9
+ private
10
+ def self.fetch_data
11
+ raw_pipelines = Hash.from_xml(`curl -s -k -u #{GOCD.credentials.curl_credentials} #{GOCD.server.url}/go/cctray.xml`)
12
+ to_pipelines raw_pipelines
13
+ end
14
+
15
+ def self.to_pipelines(raw_pipelines)
16
+ raise GOCDDataFetchException, 'Could not fetch data from server!!' if raw_pipelines.nil?
17
+ raw_pipelines['Projects']['Project'].map { |raw_pipeline| GOCD::Pipeline.new raw_pipeline }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ module GOCD
2
+ class AllPipelines
3
+ class << self
4
+ def information_available?
5
+ !pipelines.nil?
6
+ end
7
+
8
+ def red_pipelines
9
+ pipelines.select { |pipeline| pipeline.red? }
10
+ end
11
+
12
+ def green_pipelines
13
+ pipelines.select { |pipeline| pipeline.green? }
14
+ end
15
+
16
+ def status
17
+ pipelines.map { |pipeline| pipeline.status }
18
+ end
19
+
20
+ def any_red?
21
+ !red_pipelines.empty?
22
+ end
23
+
24
+ def pipelines
25
+ GOCD::PipelineRepository.pipelines
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module GOCD
2
- VERSION = "0.1"
2
+ VERSION = "0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gocd
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ajit Singh
@@ -16,10 +16,17 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - ".gitignore"
19
20
  - Gemfile
20
21
  - Gemfile.lock
21
22
  - gocd.gemspec
22
23
  - lib/gocd.rb
24
+ - lib/gocd/config/credentials.rb
25
+ - lib/gocd/config/server.rb
26
+ - lib/gocd/exception/data_fetch_exception.rb
27
+ - lib/gocd/pipeline/pipeline.rb
28
+ - lib/gocd/pipeline/pipeline_repository.rb
29
+ - lib/gocd/pipelines.rb
23
30
  - lib/gocd/version.rb
24
31
  homepage: https://github.com/ajitsing/gocd.git
25
32
  licenses: