This repository has been archived by the owner on Nov 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
trains.js
176 lines (164 loc) · 5.36 KB
/
trains.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*global gapi,XDomainRequest,moment */
var URL = "https://product-details.mozilla.org/1.0/firefox_versions.json";
// To store the JSON content
var jsonContent = {};
var BRANCHES = [
["release", "LATEST_FIREFOX_VERSION"],
["beta", "LATEST_FIREFOX_DEVEL_VERSION"],
["nightly", "FIREFOX_NIGHTLY"],
["esr", "FIREFOX_ESR", "ESR"],
["esr_next", "FIREFOX_ESR_NEXT", "Next ESR"],
];
var RELEASE_CALENDAR = "mozilla.com_2d37383433353432352d3939@resource.calendar.google.com";
var versions = {};
function getVersion(jsonContent, keyJSON) {
return jsonContent[keyJSON].replace(/[ab]\d+$/, '').replace(/esr$/, '');
}
function populateVersionInfo(jsonContent) {
for (var i = 0; i < BRANCHES.length; i++) {
var branch = BRANCHES[i][0];
var key = BRANCHES[i][1];
var description = BRANCHES[i][2];
appendVersionInfo(branch, getVersion(jsonContent, key), description);
}
}
function fetchData() {
if (window.XDomainRequest) {
var xdr = new XDomainRequest();
xdr.open("GET", URL);
xdr.onload = function() {
jsonContent = JSON.parse(xdr.responseText);
populateVersionInfo(jsonContent);
};
xdr.send();
}
else {
var req = new XMLHttpRequest();
req.onreadystatechange = function(ev) {
if (req.readyState == 4 && req.status == 200) {
jsonContent = JSON.parse(req.responseText);
populateVersionInfo(jsonContent);
}
};
req.open("GET", URL, true);
req.send(null);
}
}
function fixupReleaseVersion(release_version, beta_version) {
if (release_version != beta_version) {
return release_version;
}
// They shouldn't be the same, this must be uplift week.
return (parseInt(release_version) - 1) + ".0";
}
function appendVersionInfo(branch, version, description, h2) {
console.log("appendVersionInfo(%s, %s, %s)", branch, version, description);
if (branch == "esr_next") {
if (version == "") {
// In the context of ESR_NEXT, version can be empty
// In this case, don't do anything
return;
} else {
// Special case for ESR, add it to the header
makeHeader(branch, description);
}
}
versions[branch] = version;
h2 = h2 || document.getElementById(branch);
if (!h2)
return;
branch = description || branch[0].toUpperCase() + branch.slice(1);
var div_branch = document.createElement("div");
div_branch.classList.add('branch');
var div_version = document.createElement("div");
div_version.classList.add('vernum');
div_branch.textContent = branch;
div_version.textContent = version;
h2.appendChild(div_version);
h2.appendChild(div_branch);
}
function makeHeader(branch, description) {
var h2 = document.createElement("h2");
h2.id = branch;
h2.className = "version";
if (branch in versions) {
appendVersionInfo(branch, versions[branch], description, h2);
}
document.getElementById("flex-container").appendChild(h2);
}
function init() {
// the - 1 in the loop declaration is a workaround for esr_next
// because sometime, this variable is empty (when we manage only one ESR)
for (var i = 0; i < BRANCHES.length - 1; i++) {
var branch = BRANCHES[i];
makeHeader(branch[0], branch[2]);
}
if (window.location.search === '?tv') {
document.querySelector('.github-fork-ribbon-wrapper').style.display = 'none';
}
}
function setNextUplift(date, link, when) {
var h2 = document.createElement("h2");
h2.id = "uplift";
var span = document.createElement("span");
span.textContent = "Next merge day: ";
var a = document.createElement("a");
a.textContent = date;
a.href = link;
a.title = "Google calendar event";
span.appendChild(a);
h2.appendChild(span);
var s2 = document.createElement("span");
s2.textContent = " (" + when + ")";
h2.appendChild(s2);
document.body.appendChild(h2);
}
function loadCalendar() {
var request = gapi.client.calendar.events.list({
calendarId: RELEASE_CALENDAR,
singleEvents: true,
orderBy: "startTime",
q: "MERGE"
//"timeMin": "xxx"
});
request.execute(function (r) {
var now = moment();
if (!r.items) {
console.warn('Got no Google calendar data!');
return;
}
for (var i=0; i < r.items.length; i++) {
var item = r.items[i];
if (item.summary.substr(0, 6) == "MERGE:") {
var then;
var date;
if (item.start.date === undefined) {
// recent all day events show up with a start/end time 24 hours apart
// in some time zone that depends on who schedules them; parse using a
// tz to the east of all likely users so we get the right day
// instead of the day before
then = moment.tz(item.start.dateTime, "Europe/Paris");
date = then.format("YYYY-MM-DD");
} else {
then = moment.tz(item.start.date, "YYYY-MM-DD", "America/Los_Angeles");
date = item.start.date;
}
console.log(date, item.summary);
if (now.isBefore(then)) {
setNextUplift(date, item.htmlLink, then.fromNow());
break;
} else if (now.isSame(then, "day")) {
setNextUplift(date, item.htmlLink, "TODAY!");
break;
}
}
}
});
}
function gapi_init() {
gapi.client.setApiKey("AIzaSyCfLN9nQUWw4_GM1BHAx2S-laAOvDwvMg4");
gapi.client.load("calendar", "v3").then(loadCalendar);
}
document.addEventListener("DOMContentLoaded", init, false);
// Start fetching data before the page finishes loading.
fetchData();