Skip to content

Commit 8e29939

Browse files
committed
Load dependencies.md first, use license-report.md only as a fallback.
1 parent dbe0d8c commit 8e29939

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

js/oss-licenses.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
2-
* This is a JavaScript file which loads `license-report` md-files from the external repositories.
2+
* This is a JavaScript file which loads Markdown content from the dependency report files
3+
* via Spine public repositories.
34
*
4-
* Please see `/oss-licenses/index.html` for usage.
5+
* See `/oss-licenses/index.html` for usage.
56
*/
67
'use strict';
78

@@ -12,12 +13,19 @@ $(
1213
const repoAttr = 'repo';
1314
const repoName = 'repo-name';
1415

16+
// Spine repositories are migrated being migrated to listing their deps in this file.
17+
const reportFilePath = '/master/dependencies.md';
18+
19+
// Previously used report file path, as a fallback for non-migrated repos.
20+
const legacyFilePath = '/master/license-report.md';
21+
1522
/**
1623
* Loads the dependency report file from the repository.
1724
*
18-
* <p>There may be one of two report files present in the repo: `license-report.md`
19-
* or `dependencies.md`. The latter is a newer version of the report, so it is loaded
20-
* first. In case it is missing, `license-report.md` is loaded, as a fallback.
25+
* <p>There may be one of two report files present in the repo:
26+
* `license-report.md` or `dependencies.md`.
27+
* The latter is a newer version of the report, so it is loaded
28+
* as a priority. In case it is missing, `license-report.md` is loaded, as a fallback.
2129
* Eventually, all Spine repositories will migrate to having `dependencies.md`.
2230
*
2331
* <p>The report sections describing the terms of use for dual-licensed dependencies,
@@ -36,20 +44,25 @@ $(
3644

3745
if (loaded === 'false') {
3846
const repositoryUrl = clickedElement.attr(repoAttr);
39-
$.get(
40-
repositoryUrl + '/master/license-report.md',
41-
function (data) {
42-
const html = converter.makeHtml(data);
43-
mdDestinationEl.html(html);
44-
clickedElement.attr(loadedAttr, 'true');
45-
makeCollapsibleTitle(mdDestinationEl, clickedElRepoName);
46-
}
47-
);
47+
let processLoadedContent = function (data) {
48+
const html = converter.makeHtml(data);
49+
mdDestinationEl.html(html);
50+
clickedElement.attr(loadedAttr, 'true');
51+
makeCollapsibleTitle(mdDestinationEl, clickedElRepoName);
52+
};
53+
54+
let reportUrl = repositoryUrl + reportFilePath;
55+
let legacyReportUrl = repositoryUrl + legacyFilePath;
56+
57+
$.get(reportUrl, processLoadedContent)
58+
.fail(function () {
59+
$.get(legacyReportUrl, processLoadedContent)
60+
});
4861
}
4962
});
5063

5164
/**
52-
* Makes a `license-report` content collapsible.
65+
* Makes the report content collapsible.
5366
*
5467
* @param mdDestinationEl `div` with the markdown content
5568
* @param clickedElRepoName repository name from the link attribute

0 commit comments

Comments
 (0)