-
Notifications
You must be signed in to change notification settings - Fork 0
/
redmine_githubot.js
87 lines (79 loc) · 3.14 KB
/
redmine_githubot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var app={};
app.token='**token**';
app.apiDomain = 'https://api.github.com';
app.username="**username**";
app.userinfo="/users/" + app.username;
app.repos="/repos/" + app.username+ "/**repository**/";
app.pulls=app.repos+"pulls";
app.branch=app.repos+"branches/";
app.color=['#B52E2E','#008103'];
app.single={};
app.single.page='**active_url_single**';
app.multi={};
app.multi.page='**active_url_multi**';
app.popup="<div class='github_popup' style='position:absolute; left:35%; top:15%; background-color:rgba(0,0,0,.7); color:#fff; padding:30px; font-size:20px;'>Loading Github Pull Requests</div>"
$('body').append(app.popup);
if (window.location.href.indexOf(app.single.page)>-1){
app.page="single";
}
if (window.location.href.indexOf(app.multi.page)>-1){
app.page="multi";
}
getUrl();
function getUrl(giturl){
if (!giturl) giturl=app.apiDomain+app.pulls+'?callback='+app.page+'&access_token='+app.token+'&state=all&per_page=50';
$.ajax({
url:giturl,
dataType:'script'
});
}
function isMerged(info){
return info == null ? 0 : 1;
}
function single(e){
console.log ("-> Single",e);
// var found=false;
app.single.title = $('#content h2').first().text().toLowerCase().split(' ');
app.single.ticket=app.single.title[2].split('#')[1];
$('#content .issue p.author').first().css('padding-bottom',10)
$(e.data).each(function(i,pull){
// console.log(pull)
if (pull.head.label.indexOf(app.single.ticket)>-1){
console.log('-> pull request #'+pull.number+' state:'+pull.state+' title:'+pull.title)
var user=pull.user.html_url.split('/').pop();
var assignee=(pull.assignee)?pull.assignee.html_url.split('/').pop():"no one";
if (!app.titleChanged) {
$('.subject h3').html("<span style='color:"+app.color[isMerged(pull.merged_at)]+"'>"+$('.subject h3').text()+"</span>")
app.titleChanged=true;
}
$('#content .issue p.author').last().after('<p class="author gitpull"><a href='+pull.html_url+' style="color:'+app.color[isMerged(pull.merged_at)]+'">#'+pull.number+' ['+pull.state+(isMerged(pull.merged_at)?' - merged':' - not merged')+'] - '+pull.title+'</a> by <a href='+pull.user.html_url+'>'+user+'</a> assigned to '+(pull.assignee?'<a href='+pull.assignee.html_url+'>':'')+assignee+'</a></p>');
// found=true;
}
})
if (/*!found && */e.meta.Link[0][1].rel=='next'){
getUrl(e.meta.Link[0][0])
}else{
$('.github_popup').remove()
}
}
function multi(e){
// console.log ("-> Multi",e);
app.issue={};
$('.issues .id').each(function(i,v){
$(e.data).each(function(i,pull){
// console.log(pull)
if (pull.head.label.indexOf($(v).text())>-1){
console.log('-> pull request #'+pull.number+' state:'+pull.state+' title:'+pull.title);
var user=pull.user.html_url.split('/').pop();
var assignee=(pull.assignee)?pull.assignee.html_url.split('/').pop():"no one";
$(v).find('a').css({'color':app.color[isMerged(pull.merged_at)], 'font-weight':'bold'}).attr('title','#'+pull.number+' ['+pull.state+(isMerged(pull.merged_at)?' - merged':' - not merged')+'] - '+pull.title+' by '+user+' assigned to '+assignee);
return false
}
})
})
if (e.meta.Link[0][1].rel=='next'){
getUrl(e.meta.Link[0][0])
}else{
$('.github_popup').remove()
}
}