Skip to content

Instantly share code, notes, and snippets.

@nrichand
Last active June 1, 2016 13:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nrichand/b1b690fa2e8b87472b3b to your computer and use it in GitHub Desktop.
Save nrichand/b1b690fa2e8b87472b3b to your computer and use it in GitHub Desktop.
Bitbucket open PR

This widget list all the open pull request on bitbucket repositories.

You just have to setup your login, password, group name and the repositories you would like to verify. Add it to your dashboard :

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="bitbucket_open_pr" data-view="Bitbucket_open_pr" data-title="Open Pull Requests"></div>
</li>

The pull request is blue on the first day, yellow on the next day, then red. If there is no pull request the widget is green.

It use the look&feel of Circle CI Build Status

require 'httparty'
require 'json'
require 'time'
SCHEDULER.every '5m', :first_in => 0 do |job|
projects = ["REPOSITORY NAMES"]
prs = []
projects.each do |project|
prs.concat(getPRInfo(project))
end
send_event('bitbucket_open_pr', {projects: prs, hotness: (prs.length >= 1 ? "default" : "green")})
end
def getPRInfo(projectName)
user = "TODO"
password = "TODO"
group = "TODO"
url = "https://bitbucket.org/api/2.0/repositories/"+ group +"/"+ projectName +"/pullrequests"
auth = {:username => user, :password => password}
res = HTTParty.get(url, :basic_auth => auth)
pr_res = []
res["values"].to_a.each do |pullrequest|
author = pullrequest["author"]["display_name"]
prUrl = pullrequest["links"]["html"]["href"]
avatar_url = pullrequest["author"]["links"]["avatar"]["href"]
title = pullrequest["title"]
color = getPRColor(pullrequest["created_on"])
pr_res.push({projectName: projectName, author: author, title: title, link: prUrl, widget_class: color, avatar_url: avatar_url })
end
return pr_res
end
def getPRColor(creationDate)
created = Time.parse(creationDate)
yesterday = Time.new - (60 * 60 * 24)
beforeYesterday = Time.new - (60 * 60 * 24 * 2)
color = "ok"
if created < yesterday
color = "towatch"
if created < beforeYesterday
color = "late"
end
end
return color
end
class Dashing.Bitbucket_open_pr extends Dashing.Widget
onData: (data) ->
node = $(@node)
hotcss = switch
when data.hotness == "green" then "#00C176"
when data.hotness == "default" then "#333"
$(@node).css("background-color", hotcss)
<h1 class="title" data-bind="title"></h1>
<img class="background" src="/assets/bitbucket.png">
<ul class="items list-nostyle">
<li class="item" data-foreach-pr="projects" data-bind-class="pr.widget_class">
<span class="label project" data-bind="pr.projectName"></span>
<span class="label branch" data-bind="pr.title"></span>
<img class="avatar" data-bind-src="pr.avatar_url" />
<div class="clearfix" />
</li>
</ul>
<p class="updated-at" data-bind="updatedAtMessage"></p>
$background-color: #444;
$background-error-color: #A31F1F;
$background-towatch-color: #FABE28;
$background-ok-color: #47bbb3;
$title-color: rgba(255, 255, 255, 1);
$label-color: rgba(255, 255, 255, 0.7);
.widget.widget-bitbucket-open-pr{
background-color: $background-color;
padding: 0px;
vertical-align: top;
img.background {
width: 100% !important;
position: absolute;
left: 0;
top: 30px;
opacity: 0.1;
}
.title {
color: $title-color;
padding-top: 10px;
}
ol, ul {
margin: 0px;
text-align: left;
color: $label-color;
}
ol {
list-style-position: inside;
}
li {
margin-bottom: 5px;
}
.list-nostyle {
}
.items{
list-style: none;
li {
margin-top: 5px;
&.late {
background-color: $background-error-color;
}
&.towatch {
background-color: $background-towatch-color;
}
&.ok {
background-color: $background-ok-color;
}
.label {
display: block;
color: $label-color;
font-size: 20px;
word-wrap: break-word;
&.project {
font-weight: bold;
float: left;
text-align: left;
padding: 5px 0px 5px 10px;
}
&.branch {
float: left;
text-align: left;
padding-top: 10px;
font-size: 14px;
padding: 11px 0px 5px 5px;
}
}
.avatar {
float: right;
text-align: right;
width: 40px;
}
}
}
}
@cpoissonnier
Copy link

Petit détail pour que ça soit presque parfait : il manque l'image bitbucket.png ;)

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