From 4d6005b1e9c1aeee678415ff39da6f0364ae1fcf Mon Sep 17 00:00:00 2001 From: varac Date: Sat, 1 Oct 2016 00:02:01 +0200 Subject: Gitlab Build Status works now --- jobs/gitlab_build_status.rb | 44 +++++++++++++++ jobs/gitlab_builds.rb | 66 ---------------------- .../gitlab_build_status/gitlab_build_status.html | 7 ++- 3 files changed, 48 insertions(+), 69 deletions(-) create mode 100644 jobs/gitlab_build_status.rb delete mode 100644 jobs/gitlab_builds.rb diff --git a/jobs/gitlab_build_status.rb b/jobs/gitlab_build_status.rb new file mode 100644 index 0000000..addfaed --- /dev/null +++ b/jobs/gitlab_build_status.rb @@ -0,0 +1,44 @@ +require 'gitlab' +require 'date' +require 'pp' + +Gitlab.configure do |config| + # API endpoint URL, default + config.endpoint = ENV['GITLAB_ENDPOINT'] + + # User's private token or OAuth2 access token + config.private_token = ENV['GITLAB_TOKEN'] +end + +SCHEDULER.every '300s', :first_in => 0 do + broken_builds = [] + + # 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'] } + end + + projects.each do |proj| + + begin + pipeline = Gitlab.pipelines(proj[:id], { per_page: 1 }) + #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") + proj[:date] = date + rescue + proj[:status] = 'No builds configured' + end + + 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 }) +end diff --git a/jobs/gitlab_builds.rb b/jobs/gitlab_builds.rb deleted file mode 100644 index 0071835..0000000 --- a/jobs/gitlab_builds.rb +++ /dev/null @@ -1,66 +0,0 @@ -require 'gitlab' -require 'date' -require 'pp' - -endpoint = 'https://0xacab.org/api/v3' -#group_path = 'leap' -#group_id = 52 -token = '8vw3vWRrzFw8B6XH9e6d' -broken_builds = [] - -Gitlab.configure do |config| - # API endpoint URL, default - config.endpoint = endpoint - - # User's private token or OAuth2 access token - config.private_token = token -end - -# find group id by name -#my_group = Gitlab.groups(:search => group_path).find do |group| - #group.path == group_path -#end -#my_group_id = my_group.id - - -SCHEDULER.every '60s', :first_in => 0 do - - projects = [ - # {:id=>327, :name=>"zeromq3", :path=>"leap/zeromq3"}, - # {:id=>97, :name=>"soledad", :path=>"leap/soledad"}, - # {:id=>129, :name=>"platform", :path=>"leap/platfrom"}, - {:id=>241, :name=>"leap_cli", :path=>"leap/leap_cli"} - ] - - # get a list of all projects - #projects = Gitlab.group(group_id).projects.map do |proj| - #pp proj - #{ :id => proj['id'], :name => proj['name'], :path => proj['path_with_namespace'] } - #end - - - projects.each do |proj| - - begin - pipeline = Gitlab.pipelines(proj[:id], { per_page: 1 }) - #pp pipeline[0] - proj[:status] = pipeline[0].status - proj[:pipeline_id] = pipeline[0].id - proj[:ref] = pipeline[0].ref - proj[:date] = pipeline[0].finished_at - rescue - proj[:status] = 'No builds configured' - end - - unless proj[:status] =~ /^success|running|No builds configured$/ - broken_builds << proj - end - puts proj - end - - failed = broken_builds.size > 0 - #puts failed - - send_event('gitlab-builds', { failed: failed, header: "Gitlab builds", broken_builds: broken_builds }) -end - diff --git a/widgets/gitlab_build_status/gitlab_build_status.html b/widgets/gitlab_build_status/gitlab_build_status.html index b71d8a6..00d799b 100644 --- a/widgets/gitlab_build_status/gitlab_build_status.html +++ b/widgets/gitlab_build_status/gitlab_build_status.html @@ -1,9 +1,10 @@ -
+

FAILED

  • -
    -
    + +
    -
    +
    ()
-- cgit v1.2.3