@opentermsarchive/engine 16.1.0 → 16.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentermsarchive/engine",
3
- "version": "16.1.0",
3
+ "version": "16.1.1",
4
4
  "description": "Tracks and makes visible changes to the terms of online services",
5
5
  "homepage": "https://opentermsarchive.org",
6
6
  "bugs": {
@@ -4,9 +4,9 @@ import GitLab from './gitlab/index.js';
4
4
  export function createReporter(config) {
5
5
  switch (config.type) {
6
6
  case 'github':
7
- return new GitHub(config.repositories.declarations);
7
+ return new GitHub(config.repositories);
8
8
  case 'gitlab':
9
- return new GitLab(config.repositories.declarations, config.baseURL, config.apiBaseURL);
9
+ return new GitLab(config.repositories, config.baseURL, config.apiBaseURL);
10
10
  default:
11
11
  throw new Error(`Unsupported reporter type: ${config.type}`);
12
12
  }
@@ -13,7 +13,7 @@ export default class GitHub {
13
13
  static ISSUE_STATE_ALL = 'all';
14
14
  static MAX_LABEL_DESCRIPTION_LENGTH = 100;
15
15
 
16
- constructor(repository) {
16
+ constructor(repositories) {
17
17
  const { version } = require('../../../package.json');
18
18
 
19
19
  this.octokit = new Octokit({
@@ -25,7 +25,9 @@ export default class GitHub {
25
25
  },
26
26
  });
27
27
 
28
- const [ owner, repo ] = repository.split('/');
28
+ this.repositories = repositories; // Each generated link points into its own repository, while the issues live in the declarations one
29
+
30
+ const [ owner, repo ] = repositories.declarations.split('/');
29
31
 
30
32
  this.commonParams = { owner, repo };
31
33
 
@@ -272,14 +274,14 @@ export default class GitHub {
272
274
  }
273
275
 
274
276
  generateDeclarationURL(serviceName) {
275
- return `https://github.com/${this.commonParams.owner}/${this.commonParams.repo}/blob/main/declarations/${encodeURIComponent(serviceName)}.json`;
277
+ return `https://github.com/${this.repositories.declarations}/blob/main/declarations/${encodeURIComponent(serviceName)}.json`;
276
278
  }
277
279
 
278
280
  generateVersionURL(serviceName, termsType) {
279
- return `https://github.com/${this.commonParams.owner}/${this.commonParams.repo}/blob/main/${encodeURIComponent(serviceName)}/${encodeURIComponent(termsType)}.md`;
281
+ return `https://github.com/${this.repositories.versions}/blob/main/${encodeURIComponent(serviceName)}/${encodeURIComponent(termsType)}.md`;
280
282
  }
281
283
 
282
284
  generateSnapshotsBaseUrl(serviceName, termsType) {
283
- return `https://github.com/${this.commonParams.owner}/${this.commonParams.repo}/blob/main/${encodeURIComponent(serviceName)}/${encodeURIComponent(termsType)}`;
285
+ return `https://github.com/${this.repositories.snapshots}/blob/main/${encodeURIComponent(serviceName)}/${encodeURIComponent(termsType)}`;
284
286
  }
285
287
  }
@@ -10,12 +10,13 @@ describe('GitHub', function () {
10
10
 
11
11
  let MANAGED_LABELS;
12
12
  let github;
13
+ const REPOSITORIES = { declarations: 'owner/repo', versions: 'owner/versions-repo', snapshots: 'owner/snapshots-repo' };
13
14
  const EXISTING_OPEN_ISSUE = { number: 1, title: 'Opened issue', description: 'Issue description', state: GitHub.ISSUE_STATE_OPEN, labels: [{ name: LABELS.HTTP_403.name }] };
14
15
  const EXISTING_CLOSED_ISSUE = { number: 2, title: 'Closed issue', description: 'Issue description', state: GitHub.ISSUE_STATE_CLOSED, labels: [{ name: LABELS.EMPTY_CONTENT.name }] };
15
16
 
16
17
  before(async () => {
17
18
  MANAGED_LABELS = Object.values(LABELS);
18
- github = new GitHub('owner/repo');
19
+ github = new GitHub(REPOSITORIES);
19
20
  nock('https://api.github.com')
20
21
  .get('/repos/owner/repo/issues')
21
22
  .query(true)
@@ -518,4 +519,18 @@ describe('GitHub', function () {
518
519
  });
519
520
  });
520
521
  });
522
+
523
+ describe('URL generation', () => {
524
+ it('links the declaration into the declarations repository', () => {
525
+ expect(github.generateDeclarationURL('Service A')).to.equal('https://github.com/owner/repo/blob/main/declarations/Service%20A.json');
526
+ });
527
+
528
+ it('links the version into the versions repository', () => {
529
+ expect(github.generateVersionURL('Service A', 'Terms of Service')).to.equal('https://github.com/owner/versions-repo/blob/main/Service%20A/Terms%20of%20Service.md');
530
+ });
531
+
532
+ it('links the snapshots into the snapshots repository', () => {
533
+ expect(github.generateSnapshotsBaseUrl('Service A', 'Terms of Service')).to.equal('https://github.com/owner/snapshots-repo/blob/main/Service%20A/Terms%20of%20Service');
534
+ });
535
+ });
521
536
  });
@@ -14,8 +14,8 @@ export default class GitLab {
14
14
  static ISSUE_STATE_ALL = 'all';
15
15
  static MAX_LABEL_DESCRIPTION_LENGTH = 255;
16
16
 
17
- constructor(repository, baseURL = BASE_URL, apiBaseURL = API_BASE_URL) {
18
- this.repositoryPath = repository;
17
+ constructor(repositories, baseURL = BASE_URL, apiBaseURL = API_BASE_URL) {
18
+ this.repositories = repositories; // Each generated link points into its own repository, while the issues live in the declarations one
19
19
  this.projectId = null;
20
20
  this.baseURL = baseURL;
21
21
  this.apiBaseURL = apiBaseURL;
@@ -26,7 +26,7 @@ export default class GitLab {
26
26
 
27
27
  try {
28
28
  const response = await nodeFetch(
29
- `${this.apiBaseURL}/projects/${encodeURIComponent(this.repositoryPath)}`,
29
+ `${this.apiBaseURL}/projects/${encodeURIComponent(this.repositories.declarations)}`,
30
30
  options,
31
31
  );
32
32
 
@@ -478,15 +478,15 @@ export default class GitLab {
478
478
  }
479
479
 
480
480
  generateDeclarationURL(serviceName) {
481
- return `${this.baseURL}/${this.repositoryPath}/-/blob/main/declarations/${encodeURIComponent(serviceName)}.json`;
481
+ return `${this.baseURL}/${this.repositories.declarations}/-/blob/main/declarations/${encodeURIComponent(serviceName)}.json`;
482
482
  }
483
483
 
484
484
  generateVersionURL(serviceName, termsType) {
485
- return `${this.baseURL}/${this.repositoryPath}/-/blob/main/${encodeURIComponent(serviceName)}/${encodeURIComponent(termsType)}.md`;
485
+ return `${this.baseURL}/${this.repositories.versions}/-/blob/main/${encodeURIComponent(serviceName)}/${encodeURIComponent(termsType)}.md`;
486
486
  }
487
487
 
488
488
  generateSnapshotsBaseUrl(serviceName, termsType) {
489
- return `${this.baseURL}/${this.repositoryPath}/-/blob/main/${encodeURIComponent(serviceName)}/${encodeURIComponent(termsType)}`;
489
+ return `${this.baseURL}/${this.repositories.snapshots}/-/blob/main/${encodeURIComponent(serviceName)}/${encodeURIComponent(termsType)}`;
490
490
  }
491
491
 
492
492
  // GitLab API responses are not cached unlike GitHub, so this method only exists to satisfy the Reporter interface contract
@@ -11,10 +11,11 @@ describe('GitLab', function () {
11
11
  let MANAGED_LABELS;
12
12
  let gitlab;
13
13
  const PROJECT_ID = '4';
14
+ const REPOSITORIES = { declarations: 'owner/repo', versions: 'owner/versions-repo', snapshots: 'owner/snapshots-repo' };
14
15
 
15
16
  before(() => {
16
17
  MANAGED_LABELS = Object.values(LABELS);
17
- gitlab = new GitLab('owner/repo');
18
+ gitlab = new GitLab(REPOSITORIES);
18
19
  });
19
20
 
20
21
  describe('#initialize', () => {
@@ -767,4 +768,26 @@ describe('GitLab', function () {
767
768
  });
768
769
  });
769
770
  });
771
+
772
+ describe('URL generation', () => {
773
+ it('links the declaration into the declarations repository', () => {
774
+ expect(gitlab.generateDeclarationURL('Service A')).to.equal('https://gitlab.com/owner/repo/-/blob/main/declarations/Service%20A.json');
775
+ });
776
+
777
+ it('links the version into the versions repository', () => {
778
+ expect(gitlab.generateVersionURL('Service A', 'Terms of Service')).to.equal('https://gitlab.com/owner/versions-repo/-/blob/main/Service%20A/Terms%20of%20Service.md');
779
+ });
780
+
781
+ it('links the snapshots into the snapshots repository', () => {
782
+ expect(gitlab.generateSnapshotsBaseUrl('Service A', 'Terms of Service')).to.equal('https://gitlab.com/owner/snapshots-repo/-/blob/main/Service%20A/Terms%20of%20Service');
783
+ });
784
+
785
+ context('with a custom base URL', () => {
786
+ it('links into the custom instance', () => {
787
+ const customGitlab = new GitLab(REPOSITORIES, 'https://gitlab.example.test');
788
+
789
+ expect(customGitlab.generateVersionURL('Service A', 'Terms of Service')).to.equal('https://gitlab.example.test/owner/versions-repo/-/blob/main/Service%20A/Terms%20of%20Service.md');
790
+ });
791
+ });
792
+ });
770
793
  });
@@ -64,7 +64,7 @@ describe('Reporter', () => {
64
64
  describe('#generateDescription', () => {
65
65
  const buildReporter = () => new Reporter({
66
66
  type: 'github',
67
- repositories: { declarations: 'OpenTermsArchive/test-declarations', snapshots: 'OpenTermsArchive/test-snapshots' },
67
+ repositories: { declarations: 'OpenTermsArchive/test-declarations', versions: 'OpenTermsArchive/test-versions', snapshots: 'OpenTermsArchive/test-snapshots' },
68
68
  });
69
69
 
70
70
  const buildTerms = ({ sourceCount = 1, hasSnapshots = true, withoutSnapshotIndexes = [] } = {}) => {
@@ -159,5 +159,32 @@ describe('Reporter', () => {
159
159
  expect(description.length).to.be.lessThan(65000);
160
160
  });
161
161
  });
162
+
163
+ context('references links', () => {
164
+ it('links the latest version into the versions repository', () => {
165
+ const description = buildReporter().generateDescription({ error, terms: buildTerms() });
166
+
167
+ expect(description).to.include('github.com/OpenTermsArchive/test-versions/blob/main/TestService/Terms%20of%20Service.md');
168
+ });
169
+
170
+ it('links the latest snapshots into the snapshots repository', () => {
171
+ const description = buildReporter().generateDescription({ error, terms: buildTerms() });
172
+
173
+ expect(description).to.include('github.com/OpenTermsArchive/test-snapshots/blob/main/TestService/Terms%20of%20Service');
174
+ expect(description).to.not.include('test-declarations/blob/main/TestService/Terms%20of%20Service'); // A version or snapshot link into the declarations repository is the regression this guards against
175
+ });
176
+
177
+ context('when only the declarations repository is configured', () => {
178
+ it('omits the version and snapshots links instead of generating broken ones', () => {
179
+ const reporter = new Reporter({ type: 'github', repositories: { declarations: 'OpenTermsArchive/test-declarations' } });
180
+
181
+ const description = reporter.generateDescription({ error, terms: buildTerms() });
182
+
183
+ expect(description).to.not.include('Latest version');
184
+ expect(description).to.not.include('Latest snapshot');
185
+ expect(description).to.not.include('undefined');
186
+ });
187
+ });
188
+ });
162
189
  });
163
190
  });