From dabb0d5f4900599209748cd207ffe0ae5434d177 Mon Sep 17 00:00:00 2001 From: varac Date: Thu, 29 Sep 2016 10:03:58 +0200 Subject: [wip] gitlab-builds --- dashboards/dashboard.erb | 19 +++--- jobs/gitlab_builds.rb | 66 +++++++++++++++++++++ jobs/gitlab_merge_requests.rb | 36 ------------ jobs/nagios.rb | 7 +-- .../gitlab_build_status/gitlab_build_status.coffee | 11 ++++ .../gitlab_build_status/gitlab_build_status.html | 15 +++++ .../gitlab_build_status/gitlab_build_status.scss | 56 ++++++++++++++++++ .../gitlab_merge_requests.coffee | 9 --- .../gitlab_merge_requests.html | 18 ------ .../gitlab_merge_requests.scss | 67 ---------------------- 10 files changed, 161 insertions(+), 143 deletions(-) create mode 100644 jobs/gitlab_builds.rb delete mode 100644 jobs/gitlab_merge_requests.rb create mode 100644 widgets/gitlab_build_status/gitlab_build_status.coffee create mode 100644 widgets/gitlab_build_status/gitlab_build_status.html create mode 100644 widgets/gitlab_build_status/gitlab_build_status.scss delete mode 100644 widgets/gitlab_merge_requests/gitlab_merge_requests.coffee delete mode 100644 widgets/gitlab_merge_requests/gitlab_merge_requests.html delete mode 100644 widgets/gitlab_merge_requests/gitlab_merge_requests.scss diff --git a/dashboards/dashboard.erb b/dashboards/dashboard.erb index 35ae341..babc0f2 100644 --- a/dashboards/dashboard.erb +++ b/dashboards/dashboard.erb @@ -1,25 +1,26 @@ -
  • +
  • +
    +
  • + +
  • -
  • +
  • -
  • +
  • -
  • +
  • -
  • +
  • -
  • +
  • -
  • -
    -
  • 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 + diff --git a/jobs/gitlab_merge_requests.rb b/jobs/gitlab_merge_requests.rb deleted file mode 100644 index f39caf9..0000000 --- a/jobs/gitlab_merge_requests.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'gitlab' -require 'date' - -# TODO: Move config to yaml -my_group_path = 'leap' -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 - -pr_widget_data_id = 'gitlab-merge-requests' -SCHEDULER.every '10m', :first_in => 0 do |job| - my_group = Gitlab.groups(:search => my_group_path).find do |group| - group.path == my_group_path - end - projects = Gitlab.group(my_group.id).projects.map do |proj| - { :id => proj['id'], :name => proj['name'] } - end - - open_merge_requests = projects.inject([]) { |merges, proj| - Gitlab.merge_requests(proj[:id], :state => 'opened').each do |request| - puts proj[:name] + ': ' + request.title - merges.push({ - title: request.title, - repo: proj[:name], - updated_at: DateTime.parse(request.updated_at).strftime("%b %-d %Y, %l:%m %p"), - creator: "@" + request.author.username - }) - end - merges - } - send_event(pr_widget_data_id, { header: "Open Merge Requests", merges: open_merge_requests }) -end diff --git a/jobs/nagios.rb b/jobs/nagios.rb index 1f76237..bda1b59 100644 --- a/jobs/nagios.rb +++ b/jobs/nagios.rb @@ -1,7 +1,6 @@ SCHEDULER.every '10s' do require 'bundler/setup' require 'nagiosharder' - require 'pp' environments = { cdev: { @@ -87,9 +86,9 @@ SCHEDULER.every '10s' do end end - puts key.to_s + ": " + critical_count.to_s - puts critical_services.join(", ") - puts + #puts key.to_s + ": " + critical_count.to_s + #puts critical_services.join(", ") + #puts send_event('nagios-' + key.to_s, { criticals: critical_count, critical_services: critical_services, diff --git a/widgets/gitlab_build_status/gitlab_build_status.coffee b/widgets/gitlab_build_status/gitlab_build_status.coffee new file mode 100644 index 0000000..e501aed --- /dev/null +++ b/widgets/gitlab_build_status/gitlab_build_status.coffee @@ -0,0 +1,11 @@ +class Dashing.GitlabBuildStatus extends Dashing.Widget + + onData: (data) -> + if data.failed + $(@node).find('div.gitlab-build-failed').show() + $(@node).find('div.gitlab-build-succeeded').hide() + $(@node).css("background-color", "red") + else + $(@node).find('div.gitlab-build-failed').hide() + $(@node).find('div.gitlab-build-succeeded').show() + $(@node).css("background-color", "#50BA5B") diff --git a/widgets/gitlab_build_status/gitlab_build_status.html b/widgets/gitlab_build_status/gitlab_build_status.html new file mode 100644 index 0000000..b71d8a6 --- /dev/null +++ b/widgets/gitlab_build_status/gitlab_build_status.html @@ -0,0 +1,15 @@ +
    +

    FAILED

    + +
    + +
    +

    All Gitlab builds are successful

    +
    + +

    diff --git a/widgets/gitlab_build_status/gitlab_build_status.scss b/widgets/gitlab_build_status/gitlab_build_status.scss new file mode 100644 index 0000000..46e867d --- /dev/null +++ b/widgets/gitlab_build_status/gitlab_build_status.scss @@ -0,0 +1,56 @@ +// ---------------------------------------------------------------------------- +// Sass declarations +// ---------------------------------------------------------------------------- +$background-color: #ec663c; +$title-color: rgba(255, 255, 255, 0.7); +$label-color: rgba(255, 255, 255, 0.7); +$value-color: #fff; + +// ---------------------------------------------------------------------------- +// Widget-text styles +// ---------------------------------------------------------------------------- +.widget-gitlab-build-status { + + background-color: $background-color; + + .title { + color: $title-color; + } + .updated-at { + color: rgba(255, 255, 255, 0.7); + } + + ol, ul { + margin: 0 15px; + text-align: left; + color: $label-color; + } + + li { + margin-bottom: 5px; + font-size: 20px; + } + + .label { + color: $label-color; + } + + .value { + margin-left: 12px; + font-weight: 600; + color: $value-color; + } + + .updated-at { + color: rgba(0, 0, 0, 0.3); + } + + .build-failed { + display: none; + } + + .fa { + font-size: 10em; + color: $label-color; + } +} diff --git a/widgets/gitlab_merge_requests/gitlab_merge_requests.coffee b/widgets/gitlab_merge_requests/gitlab_merge_requests.coffee deleted file mode 100644 index e68c3f6..0000000 --- a/widgets/gitlab_merge_requests/gitlab_merge_requests.coffee +++ /dev/null @@ -1,9 +0,0 @@ -class Dashing.GitlabMergeRequests extends Dashing.Widget - - ready: -> - # This is fired when the widget is done being rendered - - onData: (data) -> - # Handle incoming data - # You can access the html node of this widget with `@node` - # Example: $(@node).fadeOut().fadeIn() will make the node flash each time data comes in. \ No newline at end of file diff --git a/widgets/gitlab_merge_requests/gitlab_merge_requests.html b/widgets/gitlab_merge_requests/gitlab_merge_requests.html deleted file mode 100644 index 396da97..0000000 --- a/widgets/gitlab_merge_requests/gitlab_merge_requests.html +++ /dev/null @@ -1,18 +0,0 @@ -

    GitLab

    -

    - - - -

    diff --git a/widgets/gitlab_merge_requests/gitlab_merge_requests.scss b/widgets/gitlab_merge_requests/gitlab_merge_requests.scss deleted file mode 100644 index d3c51f5..0000000 --- a/widgets/gitlab_merge_requests/gitlab_merge_requests.scss +++ /dev/null @@ -1,67 +0,0 @@ -// ---------------------------------------------------------------------------- -// Sass declarations -// ---------------------------------------------------------------------------- -$background-color: teal; - -$heading-color: rgba(255, 255, 255, 0.7); -$merge-title-color: rgba(255, 255, 255, 1.0); -$merge-info-color: rgba(255, 255, 255, 1.0); - -// ---------------------------------------------------------------------------- -// Widget-gitlab-merge-requests styles -// ---------------------------------------------------------------------------- -.widget-gitlab-merge-requests { - - background-color: $background-color; - vertical-align: top !important; - - .header { - margin-bottom: 0; - font-size: xx-large; - color: $heading-color; - } - - .sub-header { - color: $heading-color; - font-size: large; - margin-bottom: 1vh; - } - - .merge { - margin-bottom: 2vh; - } - - .merge-title { - font-size: medium; - font-weight: bold; - color: $merge-title-color; - } - - .merge-info { - font-size: small; - font-style: italic; - color: $merge-info-color; - } - - .merge-info div { - float:left; - } - - .list { - list-style: none; - } - - .updated-at { - color: rgba(0, 0, 0, 0.3); - } - - ol, ul { - margin: 0 15px; - text-align: left; - } - - ol { - list-style-position: inside; - } - -} -- cgit v1.2.3