From bc95708fe005cd36a49946db22e35ae82da4584b Mon Sep 17 00:00:00 2001 From: varac Date: Thu, 29 Sep 2016 10:03:58 +0200 Subject: [wip] gitlab-builds --- jobs/gitlab_builds.rb | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 jobs/gitlab_builds.rb (limited to 'jobs/gitlab_builds.rb') diff --git a/jobs/gitlab_builds.rb b/jobs/gitlab_builds.rb new file mode 100644 index 0000000..0071835 --- /dev/null +++ b/jobs/gitlab_builds.rb @@ -0,0 +1,66 @@ +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 + -- cgit v1.2.3