This will allow you to visualize data easier in tables. It could aslo be easily adapted to show other data, only need to change the URI for another github type of data.
- Create a script dashboard.erb in the dashboard directory
<% content_for :title do %>Super Dashboard<% end %>
<div class="gridster">
<ul>
<li data-row="1" data-col="1" data-sizex="3.5" data-sizey="1">
<div data-id="issues" data-view="Table" data-unordered="true" data-title="GitHub Issues"></div>
</li>
</ul>
</div>
- Create a script github-issues.rb in the jobs directory
#!/usr/bin/env ruby
require 'rest-client'
require 'json'
require 'date'
github_token = "token here"
github_owner = "owner here"
github_project = "repo here"
since_data = "since when you want to collect data"
## Change this if you want to run more than one set of issue widgets
event_name = "github_issues_labeled_defects"
uri = "https://api.github.com/repos/#{github_owner}/#{github_project}/issues?state=all&direction=asc&access_token=#{github_token}&since=#{since_data}"
# Change headers to what you want
table_headers = [{ value: "Title" }, {value:"State" }, {value: "Created at"}, {value: "Updated at" }, {value: "Number of comment(s)"}]
#send_event('issues', { table_headers: table_headers } )
SCHEDULER.every '10m', :first_in => 0 do |job|
issues = Hash.new({ value: 0 })
puts "Getting #{uri}"
response = RestClient.get uri
issuesJson = JSON.parse(response.body, symbolize_names: true)
for i in 0..15 do
indexTCreatedAT = issuesJson[i][:created_at].index("T")
indexTUpdatedAT = issuesJson[i][:updated_at].index("T")
# Get title
title = issuesJson[i][:title]
# Get state
state = issuesJson[i][:state]
# Get created_at year-month-day
created_at = issuesJson[i][:created_at][0..indexTCreatedAT-1]
# Get updated_at year-month-day
updated_at = issuesJson[i][:updated_at][0..indexTUpdatedAT-1]
# Get number of comments
comments = issuesJson[i][:comments]
# Seperate every element in json object to dynamicly display the right number of columns
issues[issuesJson[i][:title]] = [ {value: title}, {value: state}, {value: created_at}, {value: updated_at}, {value: comments}]
end
send_event('issues', { table_headers: table_headers, items: issues.values })
end
This will look like this: