Skip to content

Instantly share code, notes, and snippets.

@dragonai
Last active July 15, 2019 18:48
Show Gist options
  • Save dragonai/9d91e0f0bc78265e8281 to your computer and use it in GitHub Desktop.
Save dragonai/9d91e0f0bc78265e8281 to your computer and use it in GitHub Desktop.
GitHub Organization Open Pull Requests

##Preview

Description

Simple Dashing widget that displays all currently open pull requests across a GitHub organization.

##Usage

#####Dependencies

Add octokit to the gemfile:

gem 'octokit'

and then just run

$ bundle install

#####Setup

To install this widget, simply run dashing install 9d91e0f0bc78265e8281.

Then substitute the following placeholders in github_prs.rb with the appropriate values:

  • YOUR_GITHUB_AUTH_TOKEN => your GitHub personal access token
  • YOUR_EXACT_GITHUB_ORGANIZATION_NAME => the exact name of the organization to monitor on GitHub itself
  • PR_WIDGET_DATA_ID => the target HTML element's data-id attribute in your layout

Finally, to include the widget on a dashboard, drop the following snippet into your layout:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-view="PullRequests" data-id="whatever_id_you_like"></div>
</li>
require 'octokit'
SCHEDULER.every '1m', :first_in => 0 do |job|
client = Octokit::Client.new(:access_token => "YOUR_GITHUB_AUTH_TOKEN")
my_organization = "YOUR_EXACT_GITHUB_ORGANIZATION_NAME"
repos = client.organization_repositories(my_organization).map { |repo| repo.name }
open_pull_requests = repos.inject([]) { |pulls, repo|
client.pull_requests("#{my_organization}/#{repo}", :state => 'open').each do |pull|
pulls.push({
title: pull.title,
repo: repo,
updated_at: pull.updated_at.strftime("%b %-d %Y, %l:%m %p"),
creator: "@" + pull.user.login,
})
end
pulls
}
send_event('PR_WIDGET_DATA_ID', { header: "Open Pull Requests", pulls: open_pull_requests })
end
class Dashing.PullRequests 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.
<h1 class="header" data-bind="header"></h1>
<ul class="list">
<li data-foreach-pull="pulls">
<p class="title" data-bind="pull.title"></p>
<div class="pull_info">
<span class="repo" data-bind="pull.repo"></span>
<span>•</span>
<span class="creator" data-bind="pull.creator"></span>
<span>•</span>
<span class="updated_at" data-bind="pull.updated_at"></span>
</div>
</li>
</ul>
<p class="more-info" data-bind="moreinfo"></p>
<p class="updated-at" data-bind="updatedAtMessage"></p>
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: gray;
$value-color: #fff;
$pass-color: #8fb347;
$fail-color: #ad3b0e;
$else-color: #9CB4F4;
$title-color: rgba(255, 255, 255, 0.7);
$label-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-pull-requests styles
// ----------------------------------------------------------------------------
.widget-pull-requests {
background-color: teal;
vertical-align: top;
.header {
color: $label-color;
}
span {
font-size: 12px;
}
.title {
font-size: 0.8em;
font-weight: 500;
}
.pull_info {
line-height: 60%;
}
ol, ul {
margin: 0 15px;
text-align: left;
color: $label-color;
}
ol {
list-style-position: inside;
}
li {
margin-bottom: 20px;
}
.list {
list-style: none;
}
.pull {
color: $label-color;
}
.value {
float: right;
margin-left: 12px;
font-weight: 600;
color: $value-color;
}
.updated-at {
color: rgba(0, 0, 0, 0.3);
}
.more-info {
color: $moreinfo-color;
}
}
@mbbroberg
Copy link

I have a question as I'm still learning GitHub auth. What is the recommended scope for my personal access token? Thanks!

@vincentchalamon
Copy link

I recommend a fix about ghost users (deleted users) on github_prs.rb file, about creator node:

creator: "@" + (pull.user.nil? ? "ghost" : pull.user.login)

@GuGuss
Copy link

GuGuss commented May 5, 2015

Hi,

Very nice widget!

Is there a way to list other available data fetched from GitHub (other than: title, repo, updated_at and creator), like URL, ID?

Thanks

@GuGuss
Copy link

GuGuss commented May 5, 2015

Hum, actually, I just saw the GitHub API which has all documented.

@JC1738
Copy link

JC1738 commented Jun 3, 2015

Anyone see this error:

Encoding::InvalidByteSequenceError - /dashboard/widgets/pull_requests/pull_requests.html is not valid US-ASCII:

@sm97
Copy link

sm97 commented Nov 8, 2016

@JC1738 Did you try to follow recipe from Shopify/dashing#242 ?

@ScottBrenner
Copy link

@mbbroberg Working for me with just the admin:org_hook scope.

@JC1738 Change the • in lines 8&10 of pull_requests.html to a different character.

@E-Kelly2018
Copy link

is there a way to change were the api is being pointed to as i need to change that to teams can anyone point me in the right direction

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