Skip to content

Instantly share code, notes, and snippets.

@joren
Created August 23, 2013 11:37
Show Gist options
  • Save joren/6318392 to your computer and use it in GitHub Desktop.
Save joren/6318392 to your computer and use it in GitHub Desktop.

Description

Simple Dashing widget that show the amount of open issues and bugs for a Gitlab project.

The widget was made by @joren for use @openminds. If you end up using this widget, please send me a tweet! I'd love to hear about it.

Dependencies

This widget requires the curb gem for easy curl request in Ruby and your Gitlab API key.

Usage

This widgets uses the number-widget, so no need to create a new one. You can add as much events as you want in the config file. Add the project id and api key your project in config/gitlab.yml file. Name your number widget with 'projectname_issues' to match it with this job.

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="projectx_issues" data-view="Number" data-title="Bugs - Issues" data-min="0" data-max="100"></div>
</li>

And that is all.

This will show two numbers on the widget, the first one are the open or re-opened bugs and the second one are all open and re-opened issues. The widget wil give a warning after 1 bug and danger after 5 bugs, but this can be configured in the job file. For the bugs we look at the issues with a label 'bug', but this can also be changed in the job file.

Contributing

Have tips on making this better? Please leave a comment and/or fork the gist. Sending me a tweet on Twitter is probably a good idea as well!

require 'json'
require 'curb'
begin
gitlab_config = YAML.load_file("config/gitlab.yml")
gitlab_url = gitlab_config['url']
projects = gitlab_config['projects']
projects.each do |name, project|
SCHEDULER.every '1m', :first_in => 0 do |job|
issues = JSON.parse(Curl.get("#{gitlab_url}/api/v3/projects/#{project['id']}/issues?private_token=#{project['api_key']}&per_page=200").body_str)
opened_issues = issues.select { |issue| %w[opened reopened].include? issue['state'] }
opened_bugs = opened_issues.select { |issue| issue['labels'].include?('bug') }
status = case
when opened_bugs.size >= 5 then 'danger'
when opened_bugs.size > 0 then 'warning'
else
'ok'
end
issues_count = opened_issues.size > 50 ? "#{opened_bugs.size} - 50+" : "#{opened_bugs.size} - #{opened_issues.size}"
send_event("#{name}_issues", { current: issues_count, status: status })
end
end
rescue Errno::ENOENT
puts "No config file found for gitlab - not starting the Gitlab job"
end
url: http://my-gitlab-repo.com
projects:
projectx:
api_key: very_secret_api_key
id: 1
projecty:
api_key: maybe_another_api_key
id: 2
@wahlstedtw
Copy link

need to add gem 'curb' to the Gemfile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment