From 90be5e3859fbdd02202720716894b6b5261ab0e3 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 17 Jul 2017 20:51:46 +0200 Subject: feat: only alert for failing master builds --- Gemfile | 3 +-- Gemfile.lock | 16 +++++----------- jobs/gitlab_build_status.rb | 18 ++++++++++-------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index 08e8f3f..a1601d1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -gem 'gitlab', :git => 'https://github.com/varac/gitlab.git', :branch => 'pipeline_support' +gem 'gitlab' # activesupport >= 5.0.0 requires ruby 2.2 which break jessie support gem 'activesupport', '< 5.0.0' # both following gems will break on jessie with @@ -8,7 +8,6 @@ gem 'activesupport', '< 5.0.0' gem 'mime-types', '2.6.2' gem 'rest-client', '< 2.0.0' - gemspec gem "nagiosharder" diff --git a/Gemfile.lock b/Gemfile.lock index f541e3d..9629ed0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,12 +1,3 @@ -GIT - remote: https://github.com/varac/gitlab.git - revision: a2d105128aab0226082bbdabf7da0e24892e5b79 - branch: pipeline_support - specs: - gitlab (3.7.0) - httparty - terminal-table - PATH remote: . specs: @@ -48,6 +39,9 @@ GEM eventmachine (1.2.0.1) execjs (2.0.2) fakeweb (1.3.0) + gitlab (4.2.0) + httparty + terminal-table haml (4.0.7) tilt hashie (1.2.0) @@ -137,7 +131,7 @@ DEPENDENCIES activesupport (< 5.0.0) dashing! fakeweb (~> 1.3.0) - gitlab! + gitlab haml (~> 4.0.4) mime-types (= 2.6.2) minitest (~> 5.2.0) @@ -147,4 +141,4 @@ DEPENDENCIES simplecov (~> 0.8.2) BUNDLED WITH - 1.11.2 + 1.14.6 diff --git a/jobs/gitlab_build_status.rb b/jobs/gitlab_build_status.rb index be52f98..317118d 100644 --- a/jobs/gitlab_build_status.rb +++ b/jobs/gitlab_build_status.rb @@ -14,18 +14,20 @@ SCHEDULER.every '3000s', :first_in => 0 do # get a list of all projects 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'], + :default_branch => proj['default_branch']} end projects.each do |proj| - begin - pipeline = Gitlab.pipelines(proj[:id], { per_page: 1 }) + pipelines = Gitlab.pipelines(proj[:id], { per_page: 10 }) #pp pipeline[0] - proj[:status] = pipeline[0].status - proj[:pipeline_id] = pipeline[0].id - proj[:ref] = pipeline[0].ref - date = DateTime.parse(pipeline[0].updated_at).strftime("%F %T") + pipeline = pipelines.find{|p| p.ref == proj[:default_branch]} + next if pipeline.nil? + proj[:status] = pipeline.status + proj[:pipeline_id] = pipeline.id + proj[:ref] = pipeline.ref + date = DateTime.parse(pipeline.updated_at).strftime("%F %T") proj[:date] = date rescue proj[:status] = 'No builds configured' @@ -34,7 +36,7 @@ SCHEDULER.every '3000s', :first_in => 0 do unless proj[:status] =~ /^success|running|No builds configured$/ broken_builds << proj end - #puts proj + puts proj end failed = broken_builds.size > 0 -- cgit v1.2.3