diff options
| author | Azul <azul@riseup.net> | 2017-07-18 14:13:16 +0200 | 
|---|---|---|
| committer | Varac <varac@leap.se> | 2017-10-16 13:20:43 +0200 | 
| commit | fc531b2895eb57d675c0037cc5d3381ff664f5d4 (patch) | |
| tree | 5c4a38230eb00e0a8f0f7a71aa0a49244c8ecb56 | |
| parent | bf3d53d415bdc8daef7313c8db0916056abff5f4 (diff) | |
feat: only check builds where enabled and not archived
also reduced time between checks to 2 minutes and looking at last 50 builds.
| -rw-r--r-- | jobs/gitlab_build_status.rb | 8 | ||||
| -rw-r--r-- | lib/gitlab_stats.rb | 8 | 
2 files changed, 11 insertions, 5 deletions
| diff --git a/jobs/gitlab_build_status.rb b/jobs/gitlab_build_status.rb index f2f669a..fdfe8a8 100644 --- a/jobs/gitlab_build_status.rb +++ b/jobs/gitlab_build_status.rb @@ -1,21 +1,23 @@  require 'gitlab_stats' -SCHEDULER.every '300s', :first_in => 0 do +SCHEDULER.every '120s', :first_in => 0 do    broken_builds = []    started = Time.now    GitlabStats.projects.each do |proj| +    next if proj[:archived] +    next unless proj[:builds_enabled]      GitlabStats.add_pipeline_stats_to proj +    puts "#{proj[:name]} (#{proj[:ref]}): #{proj[:status]}"      unless proj[:status] =~ /^success|running|No builds configured/        broken_builds << proj      end -    puts proj    end    failed = broken_builds.size > 0    send_event('gitlab-builds', { failed: failed, header: "Gitlab builds", broken_builds: broken_builds }) -  puts "Going through all projects took: #{started - Time.now}." +  puts "Going through all projects took: #{Time.now - started}."  end diff --git a/lib/gitlab_stats.rb b/lib/gitlab_stats.rb index 5b41263..20b040a 100644 --- a/lib/gitlab_stats.rb +++ b/lib/gitlab_stats.rb @@ -13,13 +13,17 @@ module GitlabStats    # get a list of all projects    def self.projects      Gitlab.group(ENV['GITLAB_GROUP_ID']).projects.map do |proj| -      { :id => proj['id'], :name => proj['name'], :path => proj['path_with_namespace'], +      { :id => proj['id'], +        :name => proj['name'], +        :path => proj['path_with_namespace'], +        :archived => proj['archived'], +        :builds_enabled => proj['builds_enabled'],          :default_branch => proj['default_branch']}      end    end    def self.add_pipeline_stats_to(proj) -    pipelines = Gitlab.pipelines(proj[:id], { per_page: 10 }) +    pipelines = Gitlab.pipelines(proj[:id], { per_page: 50 })      #pp pipeline[0]      pipeline = pipelines.find{|p| p.ref == proj[:default_branch]}      if pipeline.nil? | 
