Skip to content

Instantly share code, notes, and snippets.

@Fiyorden
Last active February 29, 2020 11:42
Show Gist options
  • Save Fiyorden/6020838 to your computer and use it in GitHub Desktop.
Save Fiyorden/6020838 to your computer and use it in GitHub Desktop.
Gitlab repo for dashing

Description

Simple Dashing widget (and associated job) to display a your Repositories from Gitlab

Dependencies

No dependence

Usage

Put the gitlab_repo.rb file in your /jobs folder.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="gitlab_repo" data-view="List" data-title="Gitlab issues" style="background-color: #71388a"></div>
</li>

Settings

Issues and project are fetched every 3 minutes, but you can change that by editing the job schedule.

Update

  • Gitlab V4 api
#!/usr/bin/env ruby
require 'net/http'
require 'json'
gitlab_token = "YOUR TOKEN"
gitlab_uri = "URL GITLAB"
# number of repositories to display in the list
# order the list by the numbers
ordered = true
SCHEDULER.every '3m', :first_in => 0 do |job|
uri = URI("#{gitlab_uri}api/v4/projects?private_token=#{gitlab_token}")
response = Net::HTTP.get(uri)
data = JSON.parse(response)
result = Array.new
data.each do |app|
uri2 = URI("#{gitlab_uri}api/v4/projects/#{app["id"]}/issues?private_token=#{gitlab_token}")
response2 = Net::HTTP.get(uri2)
data2 = JSON.parse(response2)
compteur = 0
data2.each do |issue|
if issue["state"] == "opened"
compteur += 1
end
end
result.push({
label: app["name"],
value: compteur
})
end
if ordered
result = result.sort_by { |obj| -obj[:value] }
end
send_event('gitlab_repo', { items: result})
end # SCHEDULER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment