last_green_go_pipeline 1.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: db2f358dac48a112830e58e9e53c742b2262575f
4
+ data.tar.gz: 0130e30f06a3053dab4eeab91eb30eb8155cb0ef
5
+ SHA512:
6
+ metadata.gz: 87e4930383cc674b10af4cf5885e54228db2d6ea43c6ecfa0c6c9b5690d974fc33e0fee9214b11c85b86571606925dd0ee5593d77dee33e7a514a32724fd2e95
7
+ data.tar.gz: 78abd794626f599fde67755cb045e1c80e989c9412e4d1aecf1a834abf2da7cb15228da88abea69f1a22805dc9a320c85f6edf2d1cae26b62745b75df4ea160f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Bill DePhillips
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ last_green_go_pipeline
2
+ ======================
3
+
4
+ friendly wrapper around the go-api-client that looks up the last green build of a Go.CD pipeline
@@ -0,0 +1,58 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+ require 'go_api_client'
4
+ require 'pstore'
5
+ require 'benchmark'
6
+
7
+ class LastGreenBuildFetcher
8
+
9
+ def initialize(options)
10
+ @options = options
11
+ @pipeline = @options[:pipeline_name]
12
+ @stage = @options.delete(:stage_name)
13
+ @cache = PStore.new(File.expand_path(File.join(File.dirname(__FILE__), '..', '.go_watchdog_cache')))
14
+ @options.merge!(:latest_atom_entry_id => recall(:latest_atom_entry_id))
15
+ if @options[:latest_atom_entry_id].nil? && ENV['QUIET'].nil?
16
+ puts "Retrieving the feed for #{@options[:pipeline_name]}/#{@stage} for the first time. This could take quite awhile for pipelines with lots of history."
17
+ end
18
+ end
19
+
20
+ def fetch
21
+ feed = nil
22
+ ms = Benchmark.realtime do
23
+ feed = GoApiClient.runs(@options)
24
+ end
25
+ puts "fetched pipeline runs in #{ms/1000}sec" unless ENV['QUIET']
26
+
27
+ pipelines = feed[:pipelines]
28
+ remember(:latest_atom_entry_id, feed[:latest_atom_entry_id])
29
+ puts "Checking for last green run of #{@stage}. Latest event: #{feed[:latest_atom_entry_id]}" unless ENV['QUIET']
30
+
31
+ pipelines.reverse.each do |pipeline|
32
+ stage = pipeline.stages.find { |stage| stage.name == @stage }
33
+ if stage && stage.result == 'Passed'
34
+ return stage.completed_at.tap { |time| remember(:latest_green_build_time, time) }
35
+ end
36
+ end
37
+
38
+ recall :latest_green_build_time
39
+ end
40
+
41
+ private
42
+
43
+ def remember(key, value)
44
+ @cache.transaction do
45
+ if @cache[@pipeline]
46
+ @cache[@pipeline].merge!(key => value)
47
+ else
48
+ @cache[@pipeline] = { key => value }
49
+ end
50
+ end
51
+ end
52
+
53
+ def recall(key)
54
+ @cache.transaction(true) do
55
+ @cache[@pipeline] && @cache[@pipeline][key]
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: last_green_go_pipeline
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bill DePhillips
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: go-api-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: friendly wrapper around the go-api-client that looks up the last green
42
+ build of a Go.CD pipeline
43
+ email:
44
+ - bill.dephillips@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE
50
+ - README.md
51
+ - lib/last_green_build_fetcher.rb
52
+ homepage: https://github.com/rearadmiral/last_green_go_pipeline
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project: last_green_go_pipeline
72
+ rubygems_version: 2.3.0
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: last green Go.CD pipeline fetcher
76
+ test_files: []