-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
354 lines (302 loc) · 13.1 KB
/
index.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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Jitsi Config Differ</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap-select.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/diff2html/bundles/css/diff2html.min.css"/>
<!-- <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/default.min.css">-->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/mustache.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap-select.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html-ui.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/diff.min.js"></script>
<!-- <script src="//cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>-->
<script src="hotdiffer.js"></script>
</head>
<body>
<div class="mt-3 text-center">
<h1>Jitsi Config Differ</h1>
<div class="d-none" id="start-over-container">
<div class="float-right mr-3 mt-1">
<button class="btn btn-sm btn-outline-secondary mb-1" id="start-over">Compare something else</button>
</div>
</div>
<div id="loading-tags" class="mt-5">
<div class="spinner-grow text-secondary" role="status">
<span class="sr-only"></span>
</div>
<div class="text-muted mt-2">
<small>Hold on. Loading tags...</small>
</div>
</div>
<div class="lead mt-5 d-none" id="select-tags">
Compare
<select data-live-search="true" id="fromTag">
</select>
with
<select data-live-search="true" id="toTag">
</select>
<button type="button" class="btn btn-outline-dark ml-2" id="select-go">Let's Go</button>
</div>
<div class="mt-5 container" id="tag-stable-info">
<small class="text-muted" id="tag-stable-message">
ⓘ
<em>Showing only stable tags.
Want to compare unstable tags too? <a href="#" id="load-unstable">Load unstable tags.</a></em>
</small>
<small class="text-muted d-none" id="tag-unstable-message">
ⓘ
<em>Unstable tags now included in options above. <a href="#" id="show-only-stable">Hide unstable tags.</a></em>
</small>
<div id="loading-unstable-tags" class="mt-5 d-none">
<div class="spinner-grow text-secondary" role="status">
<span class="sr-only"></span>
</div>
<div class="text-muted mt-2">
<small>Hold on. Loading unstable tags...</small>
</div>
</div>
</div>
</div>
<div id="body" class="mt-3"></div>
<script id="diffReportTemplate" type="x-tmpl-mustache">
<div class="container-fluid mb-5" id='container-{{ ident }}'>
<div class='border-bottom lead project-heading' id={{ anchor }}>
{{ project }}
<small>
(
<a href='https://github.com/{{ project }}/tree/{{ fromTag }}' target="_blank">{{ fromTag }}</a>
→
<a href='https://github.com/{{ project }}/tree/{{ toTag }}' target="_blank">{{ toTag }}</a>
)
<a href='{{ base_url }}?from={{ fromTag }}&to={{ toTag }}#{{ anchor }}' style='display:none' class='permalink'>#</a>
</small>
</div>
<div class="mt-3" id='pre-content-{{ ident }}'></div>
<div class="mt-3" id='content-{{ ident }}'></div>
</div>
</script>
<script>
let stableTagPairs, allTagPairs;
let preselect0, preselect1;
const reportTemplate = document.getElementById('diffReportTemplate').innerHTML;
const diffConfig = {
drawFileList: false,
// matching: 'lines',
outputFormat: 'side-by-side',
renderNothingWhenEmpty: true,
};
$(document).ready(function () {
// button handlers
$('#start-over').on('click', function (e) {
e.preventDefault();
window.location = window.location.pathname; // exclude params and hash if included
});
const params = getQueryParams();
if (params.from && params.to) {
if (!looksLikeValidTag(params.from)) {
console.error(`"${params.from}" does not look like a valid tag. Ignoring.`)
} else if (!looksLikeValidTag(params.to)) {
console.error(`"${params.to}" does not look like a valid tag. Ignoring.`)
} else {
$('#loading-tags').remove();
hideFormAndRenderDiffs(params.from, params.to);
return; // don't proceed with loading tags
}
}
// By default, drive everything off stable tags on jitsi-meet project
fetch('https://raw.githubusercontent.com/shawnchin/jitsi-repo-metadata/main/tags_stable_jitsi-meet.json')
.then(response => response.json())
.then(data => initPage(data));
});
function getQueryParams() {
let queryString = window.location.search;
let query = {};
let pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
for (let i = 0; i < pairs.length; i++) {
let pair = pairs[i].split('=');
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair.slice(1).join('=') || '');
}
return query;
}
function looksLikeValidTag(tag) {
return !!/(stable\/)?jitsi-meet_(\d+)/g.exec(tag);
}
function getStableAndUnstableTags(callback) {
if (allTagPairs) {
callback(allTagPairs);
} else {
const $spinner = $('#loading-unstable-tags').removeClass('d-none');
fetch('https://raw.githubusercontent.com/shawnchin/jitsi-repo-metadata/main/tags_unstable_jitsi-meet.json')
.then(response => response.json())
.then(data => {
const tagPairs = data.versions.map(version => [version, data.tags[version].tag]);
allTagPairs = stableTagPairs.concat(tagPairs).sort((a, b) => (a > b ? -1 : 1));
$spinner.remove();
callback(allTagPairs);
})
}
}
function maybeLoadAndAppendUnstableTags() {
getStableAndUnstableTags(function (tagPairs) {
renderTagSelectors(tagPairs, true);
$('#loading-unstable-tags').remove();
$('#tag-unstable-message').removeClass('d-none').show();
})
}
function hideFormAndRenderDiffs(fromTag, toTag) {
$('#select-tags').remove();
$('#tag-stable-info').remove();
renderUiAndGenerateDiffs(fromTag, toTag);
}
function initPage(tagData) {
console.log(tagData);
const tagPairs = tagData.versions.map(version => [version, tagData.tags[version].tag]);
const sortedTagPairs = tagPairs.sort((a, b) => (a > b ? -1 : 1)); // likely to already be reverse sorted
// Pre-select last two stable versions, storing in global, so we can reuse if re-rendering with unstable tags
preselect0 = sortedTagPairs[1][1];
preselect1 = sortedTagPairs[0][1];
stableTagPairs = sortedTagPairs; // storing in global, so we can reuse if re-rendering with unstable tags
renderTagSelectors(stableTagPairs);
$('#select-go').on('click', function (e) {
e.preventDefault();
const fromTag = $('#fromTag').val();
const toTag = $('#toTag').val();
hideFormAndRenderDiffs(fromTag, toTag);
})
$('#load-unstable').on('click', function (e) {
e.preventDefault();
$('#tag-stable-message').hide();
maybeLoadAndAppendUnstableTags();
});
$('#show-only-stable').on('click', function (e) {
e.preventDefault();
$('#tag-unstable-message').hide();
renderTagSelectors(stableTagPairs, true);
$('#tag-stable-message').show();
});
// toggle content
$('#loading-tags').remove();
$('#select-tags').removeClass('d-none');
}
function renderTagSelectors(tagPairs, isUpdate) {
const $selectFromTag = $('#fromTag').empty();
const $selectToTag = $('#toTag').empty();
$selectToTag.append($("<option>", {text: 'master', value: 'master'}))
$.map(tagPairs, function(tagPair, i) {
const [version, tag] = tagPair;
// format unstable tags a lttle differently
const optionClass = (!tag.startsWith('stable/')) ? 'text-muted': '';
const $from = $("<option>", {value: tag, text: tag, class: optionClass}).appendTo($selectFromTag);
const $to = $("<option>", {value: tag, text: tag, class: optionClass}).appendTo($selectToTag);
if (tag === preselect0) {
$from.attr('selected', true);
}
if (tag === preselect1) {
$to.attr('selected', true);
}
});
if (isUpdate) {
$('select').selectpicker('destroy').selectpicker();
// $('select').selectpicker('refresh'); // this is insufficient. 'selected' items not selected.
} else {
$('select').selectpicker();
}
}
function renderUiAndGenerateDiffs(fromTag, toTag) {
$('#start-over-container').removeClass('d-none');
Promise.all([
_renderFor({
project: 'jitsi/jitsi-meet',
paths: [
'/config.js',
'/interface_config.js',
'/doc/debian/jitsi-meet-prosody/prosody.cfg.lua-jvb.example',
'/doc/debian/jitsi-meet-turn/turnserver.conf',
],
fromTag: fromTag,
toTag: toTag,
}),
_renderFor({
project: 'jitsi/jitsi-videobridge',
paths: ['/jvb/src/main/resources/reference.conf'],
fromTag: fromTag,
toTag: toTag,
}),
_renderFor({
project: 'jitsi/jicofo',
paths: [
{
oldPath: '/src/main/resources/reference.conf',
newPath: '/jicofo-selector/src/main/resources/reference.conf',
movedAtVersion: 7802,
},
],
fromTag: fromTag,
toTag: toTag,
})
]).then(function () {
// Force scroll to id if URL includes a hash
const hash = window.location.hash;
if (hash) {
document.getElementById(hash.substring(1)).scrollIntoView();
}
// show/hide permalink
$('.project-heading').hover(function () {
$(this).find('a.permalink').show();
}, function () {
$(this).find('a.permalink').hide();
});
})
}
function _renderFor(params) {
const {project, paths, fromTag, toTag} = params;
const ident = randomIdent();
$('#body').append(Mustache.render(reportTemplate, {
base_url: window.location.pathname,
anchor: project.replace('/', '__'),
project,
ident,
fromTag,
toTag
}));
return fetchFilesAndCompare({
project: project,
tagOld: fromTag,
tagNew: toTag,
paths: paths,
}).then(result => {
if (result.diff) {
const targetElement = document.getElementById('content-' + ident);
const diff2htmlUi = new Diff2HtmlUI(targetElement, result.diff, diffConfig);
diff2htmlUi.draw();
// diff2htmlUi.highlightCode();
}
if (result.unchanged) {
_renderUnchanged(result.unchanged, ident);
}
}).catch(e => {
console.error(e);
$('#content-' + ident).html("<div class='text-danger'><small>" +
"☹ Failed to load files from project repo. Perhaps the tag does not exist on the project?" +
"</small></div>")
})
}
function _renderUnchanged(unchanged, ident) {
const $container = $('#pre-content-' + ident);
const $list = $('<ul>').appendTo($container);
$.map(unchanged, function (path) {
$("<li>", {html: `No changes for <code class="filename">${path}</code>`})
.addClass('no-change')
.appendTo($list);
});
}
</script>
</body>
</html>