last_green_go_pipeline 1.0.3 → 1.0.4
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 +4 -4
- data/README.md +2 -0
- data/lib/go_cd/last_green_build_fetcher.rb +60 -0
- metadata +2 -2
- data/lib/last_green_build_fetcher.rb +0 -58
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 87b98ffdb93df57680657c29f521cb1dbc4d622a
         | 
| 4 | 
            +
              data.tar.gz: 09f7e09b2003bebb7dba8de8fee36195aa16f3c0
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f5bf14908eb824c754869d979279747ef06904216a0f49b9f3a82cd87f6fb39785d12b7e4a56fcb78c17a1b772581995566d3d2f353ba792646f01fd85672d60
         | 
| 7 | 
            +
              data.tar.gz: 5c87fc4de01af797a761392713301d7aa998ac1535d00323ee4b51da4029356e4a6939f16127934eb00e33dcfa61318e872d334605a23618a0ba1203dd6c684c
         | 
    
        data/README.md
    CHANGED
    
    
| @@ -0,0 +1,60 @@ | |
| 1 | 
            +
            require 'bundler'
         | 
| 2 | 
            +
            Bundler.setup
         | 
| 3 | 
            +
            require 'go_api_client'
         | 
| 4 | 
            +
            require 'pstore'
         | 
| 5 | 
            +
            require 'benchmark'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module GoCD
         | 
| 8 | 
            +
              class LastGreenBuildFetcher
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def initialize(options)
         | 
| 11 | 
            +
                  @options = options
         | 
| 12 | 
            +
                  @pipeline = @options[:pipeline_name]
         | 
| 13 | 
            +
                  @stage = @options.delete(:stage_name)
         | 
| 14 | 
            +
                  @cache = PStore.new(File.expand_path(File.join(File.dirname(__FILE__), '..', '.go_watchdog_cache')))
         | 
| 15 | 
            +
                  @options.merge!(:latest_atom_entry_id => recall(:latest_atom_entry_id))
         | 
| 16 | 
            +
                  if @options[:latest_atom_entry_id].nil? && ENV['QUIET'].nil?
         | 
| 17 | 
            +
                    puts "Retrieving the feed for #{@options[:pipeline_name]}/#{@stage} for the first time.  This could take quite awhile for pipelines with lots of history."
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def fetch
         | 
| 22 | 
            +
                  feed = nil
         | 
| 23 | 
            +
                  ms = Benchmark.realtime do
         | 
| 24 | 
            +
                    feed = GoApiClient.runs(@options)
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                  puts "fetched pipeline runs in #{ms/1000}sec" unless ENV['QUIET']
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  pipelines = feed[:pipelines]
         | 
| 29 | 
            +
                  remember(:latest_atom_entry_id, feed[:latest_atom_entry_id])
         | 
| 30 | 
            +
                  puts "Checking for last green run of #{@stage}. Latest event: #{feed[:latest_atom_entry_id]}" unless ENV['QUIET']
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  pipelines.reverse.each do |pipeline|
         | 
| 33 | 
            +
                    stage = pipeline.stages.find { |stage| stage.name == @stage }
         | 
| 34 | 
            +
                    if stage && stage.result == 'Passed'
         | 
| 35 | 
            +
                      return stage.completed_at.tap { |time| remember(:latest_green_build_time, time) }
         | 
| 36 | 
            +
                    end
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  recall :latest_green_build_time
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                private
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                def remember(key, value)
         | 
| 45 | 
            +
                  @cache.transaction do
         | 
| 46 | 
            +
                    if @cache[@pipeline]
         | 
| 47 | 
            +
                      @cache[@pipeline].merge!(key => value)
         | 
| 48 | 
            +
                    else
         | 
| 49 | 
            +
                      @cache[@pipeline] = { key => value }
         | 
| 50 | 
            +
                    end
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                def recall(key)
         | 
| 55 | 
            +
                  @cache.transaction(true) do
         | 
| 56 | 
            +
                    @cache[@pipeline] && @cache[@pipeline][key]
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: last_green_go_pipeline
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Bill DePhillips
         | 
| @@ -48,7 +48,7 @@ extra_rdoc_files: [] | |
| 48 48 | 
             
            files:
         | 
| 49 49 | 
             
            - LICENSE
         | 
| 50 50 | 
             
            - README.md
         | 
| 51 | 
            -
            - lib/last_green_build_fetcher.rb
         | 
| 51 | 
            +
            - lib/go_cd/last_green_build_fetcher.rb
         | 
| 52 52 | 
             
            homepage: https://github.com/rearadmiral/last_green_go_pipeline
         | 
| 53 53 | 
             
            licenses:
         | 
| 54 54 | 
             
            - MIT
         | 
| @@ -1,58 +0,0 @@ | |
| 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
         |