Skip to content

Instantly share code, notes, and snippets.

@jwalton
Last active July 30, 2020 23:17
Show Gist options
  • Save jwalton/6499159 to your computer and use it in GitHub Desktop.
Save jwalton/6499159 to your computer and use it in GitHub Desktop.
Dashing Widget to Display Next Git Milestone
<script type='text/javascript'>
$(function() {
Dashing.widget_base_dimensions = [307, 252]
Dashing.numColumns = 6
});
</script>
<% content_for :title do %>1080p dashboard<% end %>
<div class="gridster">
<ul>
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="git_next_milesone" data-view="Text" data-title="Next Milestone"
style="background-color:#333A52; padding-bottom: 70px"
></div>
<i class="icon-github icon-background"></i>
</li>
</ul>
</div>
#!/usr/bin/env ruby
require 'rest-client'
require 'json'
require 'date'
git_token = "YOUR-KEY-HERE"
git_owner = "OWNER"
git_project = "PROJECT"
SCHEDULER.every '10m', :first_in => 0 do |job|
uri = "https://api.github.com/repos/#{git_owner}/#{git_project}/milestones?access_token=#{git_token}"
puts "Getting #{uri}"
response = RestClient.get uri
milestones = JSON.parse(response.body, symbolize_names: true)
# Remove all the milestones with no due date, or where all the issues are closed.
milestones.select! { |milestone| !milestone[:due_on].nil? and (milestone[:open_issues] > 0) }
if milestones.length > 0
milestones.sort! { |a,b| a[:due_on] <=> b[:due_on] }
next_milestone = milestones.first
days_left = (Date.parse(next_milestone[:due_on]) - Date.today).to_i
if days_left > 0
due = "Due in #{days_left} days"
elsif days_left == 0
due = "Due today"
else
due = "Overdue by #{days_left.abs} days"
end
send_event('git_next_milesone', {
text: "#{next_milestone[:title] or 'Unnamed Milestone'}<br>#{due}",
moreinfo: "#{next_milestone[:open_issues]}/#{next_milestone[:open_issues] + next_milestone[:closed_issues]} issues remain"
})
else
# There are no milestones left with open issues.
send_event('git_next_milesone', {
text: "None",
moreinfo: ""
})
end
end # SCHEDULER

This will show your next GitHub milestone as a Dashing widget. Built on top of the Text widget.

To use:

  • Add the following to your gemfile:

  •   gem 'rest-client'
    
  • Replace the git_token, git_owner, and git_project in git-milestone.rb as appropriate.

@jurre
Copy link

jurre commented Dec 7, 2013

Thanks a bunch for this! I used this as the basis for our dashboards but added support for multiple projects and gave it it's own widget, it's over here.

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