-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.html
83 lines (66 loc) · 1.97 KB
/
background.html
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
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="fancy-settings/source/lib/store.js"></script>
<script>
var MS_PER_DAY = 1000 * 60 * 60 * 24;
var settings = new Store("settings", {
"enterprise_host": '',
"repos_to_watch": '',
"polling_interval_sec": 60
});
function processPulls(pulls_by_repo) {
var total_pulls = 0;
var found_old = false;
for (var repo_url in pulls_by_repo) {
pulls = pulls_by_repo[repo_url];
total_pulls += pulls.length;
for (var pull in pulls) {
var created_at = new Date(pull.created_at);
var elapsed_ms = Date.now() - created_at;
var elapsed_days = elapsed_ms / MS_PER_DAY;
if (elapsed_days > 1) {
found_old = true;
}
}
}
if (found_old)
{
chrome.browserAction.setBadgeBackgroundColor({color:[0xC4, 0, 0x22, 255]});
}
else
{
chrome.browserAction.setBadgeBackgroundColor({color:[0x8F, 0xBC, 0x8F, 255]});
}
var badge_text = (total_pulls == 0 ? '' : total_pulls.toString());
chrome.browserAction.setBadgeText({text: badge_text});
}
function fetchPullRequests(repo_paths, onResult) {
fetchPullRequestsHelper(repo_paths, {}, onResult);
}
function fetchPullRequestsHelper(repo_paths, result, onResult) {
if (repo_paths.length == 0)
{
onResult(result)
return;
}
repo_path = repo_paths[repo_paths.length - 1];
if (repo_path[0] == '/')
{
repo_path = repo_path.substr(1);
}
pulls_url = "https://" + settings.get("enterprise_host") + '/api/v3/repos/' + repo_path + '/pulls'
$.ajax({
url: pulls_url,
success: function(pulls) {
result[pulls_url] = pulls;
fetchPullRequestsHelper(repo_paths.slice(0, repo_paths.length - 1), result, onResult);
}
});
}
function think() {
fetchPullRequests(settings.get("repos_to_watch").split(";"), processPulls);
setTimeout("think()", 1000 * settings.get("polling_interval_sec"));
}
$(document).ready(function() {
think();
})
</script>