Created
February 20, 2014 16:31
-
-
Save scottdriscoll/9117760 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Adds Metadata on Github Pull Request | |
// @namespace http://github.com/richardfullmer | |
// @include https://github.com/*/*/pulls* | |
// @version 3 | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js | |
// ==/UserScript== | |
$(function() { | |
var access_token = "your_token"; | |
$(".pulls-list .list-group-item h4").each(function() { | |
var pull_request = this; | |
$(pull_request).addClass("issues-list"); | |
//var issue_href = $("a:first", pull_request).attr("href").replace('/pull/', '/issues/'); | |
//$.getJSON("https://api.github.com/repos" + issue_href + "?access_token=" + access_token, function(issue) { | |
// $.each(issue.labels, function(l_i, label) { | |
// var label_html = $('<span class="labels"><span style="background-color: #' + label.color + ' !important; color: #333 !important" data-name="' + label.name + '" class="label">' + label.name + '</span></span>'); | |
// $(pull_request).append(label_html); | |
// }); | |
//}); | |
var pr_href = $("a:first", pull_request).attr("href").replace('/pull/', '/pulls/'); | |
$.getJSON("https://api.github.com/repos" + pr_href + "?access_token=" + access_token, function(pr) { | |
var pr_target_html = $('<span style="margin-left: 0; margin-right: 4px;" class="labels"><span style="background-color: #EEEEEE !important; color: #333 !important" class="label" title="Target branch">' + pr.base.ref + '</span></span>'); | |
$(pull_request).prepend(pr_target_html); | |
if (pr.mergeable) { | |
var pr_mergeable_html = $('<span class="labels"><span style="background-color: #d8f5cd !important; color: #333 !important" class="label">mergeable</span></span>'); | |
} else { | |
var pr_mergeable_html = $('<span class="labels"><span style="background-color: #f7c6c7 !important; color: #333 !important" class="label">rebase</span></span>'); | |
} | |
$(pull_request).append(pr_mergeable_html); | |
$.getJSON(pr._links.statuses.href + "?access_token=" + access_token, function(statuses) { | |
if (statuses.length > 0) { | |
var current_status = statuses[0]; | |
var color = '#ececec'; | |
switch (current_status.state) { | |
case 'pending': | |
color = '#f8eec7'; | |
break; | |
case 'success': | |
color = '#d8f5cd'; | |
break; | |
case 'error': | |
color = '#eeeeee'; | |
break; | |
case 'failure': | |
color = '#f7c6c7'; | |
break; | |
} | |
var current_status_html = $('<span class="labels"><span style="background-color: ' + color + ' !important; color: #333 !important" class="label" title="' + current_status.description + '">' + current_status.state + '</span></span>'); | |
$(pull_request).append(current_status_html); | |
} | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment