Skip to content

Commit eb24e39

Browse files
committed
Link feed entries to GitHub commits
1 parent 54e0e1d commit eb24e39

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/collection-api/routes/feed.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,18 @@ function buildEntryId(collection, version) {
6666
}
6767

6868
function buildEntry(collection, baseUrl, version) {
69+
const apiLink = buildVersionLink(baseUrl, version);
70+
const githubCommitLink = collection.metadata?.versions && `${collection.metadata.versions}/commit/${version.id}`;
71+
72+
const links = [{ _attributes: { rel: 'alternate', type: 'text/html', href: githubCommitLink || apiLink } }];
73+
74+
if (githubCommitLink) {
75+
links.push({ _attributes: { rel: 'related', type: 'text/html', href: apiLink } });
76+
}
77+
6978
return {
7079
id: { _text: buildEntryId(collection, version) },
71-
link: { _attributes: {
72-
rel: 'alternate',
73-
type: 'text/html',
74-
href: buildVersionLink(baseUrl, version),
75-
} },
80+
link: links,
7681
title: { _text: buildEntryTitle(version) },
7782
updated: { _text: version.fetchDate.toISOString() },
7883
category: [

src/collection-api/routes/feed.test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,15 @@ describe('Feed API', () => {
159159
expect(firstEntry).to.include(`<id>${expected}</id>`);
160160
});
161161

162-
it('has an alternate link to the version API endpoint', () => {
162+
it('has an alternate link to the GitHub commit', async () => {
163+
const collection = await getCollection();
163164
const href = firstEntry.match(/<link[^>]*rel="alternate"[^>]*href="([^"]+)"/)[1];
165+
166+
expect(href).to.equal(`${collection.metadata.versions}/commit/${savedVersions.technicalUpgradeRecord.id}`);
167+
});
168+
169+
it('has a related link to the version API endpoint', () => {
170+
const href = firstEntry.match(/<link[^>]*rel="related"[^>]*href="([^"]+)"/)[1];
164171
const expectedPathFragment = `/version/${encodeURIComponent('service-2')}/${encodeURIComponent('Privacy Policy')}/${encodeURIComponent(toISODateWithoutMilliseconds(FETCH_DATE_UPGRADE))}`;
165172

166173
expect(href).to.include(expectedPathFragment);
@@ -399,8 +406,8 @@ describe('Feed API', () => {
399406
expect(href).to.not.include('Service B!');
400407
});
401408

402-
it('URL-encodes spaces and special characters in entry alternate links', () => {
403-
const href = response.text.match(/<link[^>]*rel="alternate"[^>]*href="([^"]+)"/)[1];
409+
it('URL-encodes spaces and special characters in entry related links', () => {
410+
const href = response.text.match(/<link[^>]*rel="related"[^>]*href="([^"]+)"/)[1];
404411

405412
expect(href).to.include('Service%20B!');
406413
expect(href).to.include('Privacy%20Policy');

0 commit comments

Comments
 (0)