-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcommon_landings.js
216 lines (186 loc) · 5.41 KB
/
common_landings.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
let onLoad = new Promise(function (resolve, reject) {
window.onload = resolve;
});
function dropdownDateToDaysDiff(val) {
if (val === "one day") {
return 1;
} else if (val === "two days") {
return 2;
} else if (val === "three days") {
return 3;
} else if (val === "a week") {
return 7;
}
throw new Exception("Unknown value " + val);
}
function dropdownBuildToVal(val) {
if (val === "one build") {
return 1;
} else if (val === "two builds") {
return 2;
} else if (val === "three builds") {
return 3;
}
throw new Exception("Unknown value " + val);
}
function betaBuildToTag(val) {
return "FIREFOX_" + val.replace(".", "_") + "_RELEASE";
}
function subtractFromBetaBuild(version, val) {
let major = version.substring(0, version.indexOf("b"));
let betaBuild = version.substring(version.indexOf("b") + 1);
return major + "b" + (Number(betaBuild) - val);
}
function checkIsBuildID(val) {
let isBuildID = true;
try {
let res = parseBuildID(val);
if (
isNaN(res.year) ||
isNaN(res.month) ||
isNaN(res.day) ||
isNaN(res.hour) ||
isNaN(res.minute) ||
isNaN(res.second) ||
res.year < 2000 ||
res.month < 0 ||
res.month > 12 ||
res.day < 0 ||
res.day > 31 ||
res.hour < 0 ||
res.hour > 24
) {
isBuildID = false;
}
} catch (ex) {
isBuildID = false;
}
return isBuildID;
}
function getPushlogLink(channel) {
let base;
if (channel === "nightly") {
base = "https://hg.mozilla.org/mozilla-central";
}
let firstAffected = document.getElementById(channel + "_first_affected")
.value;
if (firstAffected) {
let isBuildID = checkIsBuildID(firstAffected);
let startDateElem = document.getElementById(channel + "_days");
let startDate = dropdownDateToDaysDiff(
startDateElem.options[startDateElem.selectedIndex].value
);
let pushlogLinkElem = document.getElementById(channel + "_pushloglink");
return new Promise(function (resolve, reject) {
if (!isBuildID) {
resolve(firstAffected);
} else {
fromBuildIDtoChangeset(firstAffected, channel).then((changesetURL) =>
resolve(getRevFromChangeset(changesetURL, channel))
);
}
}).then((changeset) =>
getChangesetDate(changeset, channel).then((date) => {
date.setDate(date.getDate() - startDate);
let year = date.getFullYear();
let month = toTwoDigits(date.getMonth() + 1);
let day = toTwoDigits(date.getDate());
let pushlogLink =
base +
"/pushloghtml?startdate=" +
year +
"-" +
month +
"-" +
day +
"&tochange=" +
changeset;
pushlogLinkElem.textContent = pushlogLinkElem.href = pushlogLink;
return pushlogLink;
})
);
}
return null;
}
function getCommonLandings() {
let pushlog_link_promises = [];
// Nightly
let nightlyPushlogLink = getPushlogLink("nightly");
if (nightlyPushlogLink) {
pushlog_link_promises.push(nightlyPushlogLink);
}
// Beta
let betaFirstAffected = document.getElementById("beta_first_affected").value;
if (betaFirstAffected) {
let betaStartBuildElem = document.getElementById("beta_builds");
let betaStartBuild = subtractFromBetaBuild(
betaFirstAffected,
dropdownBuildToVal(
betaStartBuildElem.options[betaStartBuildElem.selectedIndex].value
)
);
let betaPushlogLink =
"https://hg.mozilla.org/releases/mozilla-beta/pushloghtml?fromchange=" +
betaBuildToTag(betaStartBuild) +
"&tochange=" +
betaBuildToTag(betaFirstAffected);
let betaPushlogLinkElem = document.getElementById("beta_pushloglink");
betaPushlogLinkElem.textContent = betaPushlogLinkElem.href = betaPushlogLink;
pushlog_link_promises.push(Promise.resolve(betaPushlogLink));
}
return Promise.all(
pushlog_link_promises.map((link_promise) =>
link_promise.then((link) =>
fetch(link)
.then((response) => response.text())
.then((html) => {
let bugs = [];
let result;
let re = /Bug ([0-9]+)/gi;
while ((result = re.exec(html)) !== null) {
bugs.push(result[1]);
}
return bugs;
})
)
)
)
.then((arrays) => {
if (arrays.length === 0) {
return [];
}
return arrays[0].filter((elem) => {
let is_everywhere = true;
for (let array of arrays.slice(1)) {
is_everywhere &= array.includes(elem);
}
return is_everywhere;
});
})
.then((bugs) => new Set(bugs));
}
onLoad.then(function () {
document.getElementById("getCommonLandings").onclick = function () {
// Clean old results.
let results = document.getElementById("results");
while (results.firstChild) {
results.removeChild(results.firstChild);
}
results.textContent = "";
getCommonLandings().then((bugs) => {
if (bugs.size === 0) {
results.textContent = "None";
return;
}
let a = document.createElement("a");
a.textContent = "List of common landings on Bugzilla";
a.href = "https://bugzilla.mozilla.org/buglist.cgi?bug_id=";
a.id = "buglist";
results.appendChild(a);
for (let bug of bugs) {
let a = document.getElementById("buglist");
a.href += bug + ",";
}
});
};
});