@opentermsarchive/engine 2.5.0 → 2.7.0
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/config/default.json +2 -1
- package/package.json +1 -1
- package/scripts/dataset/logger/index.js +5 -2
- package/scripts/dataset/publish/github/index.js +36 -0
- package/scripts/dataset/publish/gitlab/index.js +133 -0
- package/scripts/dataset/publish/index.js +11 -32
- package/src/collection-api/logger.js +6 -2
- package/src/index.js +9 -13
- package/src/logger/index.js +7 -13
- package/src/reporter/factory.js +13 -0
- package/src/reporter/{github.js → github/index.js} +14 -2
- package/src/reporter/{github.test.js → github/index.test.js} +1 -1
- package/src/reporter/{labels.test.js → github/labels.test.js} +1 -1
- package/src/reporter/gitlab/index.js +386 -0
- package/src/reporter/gitlab/index.test.js +527 -0
- package/src/reporter/gitlab/labels.json +77 -0
- package/src/reporter/gitlab/labels.test.js +30 -0
- package/src/reporter/index.js +54 -16
- package/src/reporter/index.test.js +63 -0
- /package/src/reporter/{labels.json → github/labels.json} +0 -0
package/src/reporter/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import mime from 'mime';
|
|
2
2
|
|
|
3
3
|
import { toISODateWithoutMilliseconds } from '../archivist/utils/date.js';
|
|
4
|
+
import logger from '../logger/index.js';
|
|
4
5
|
|
|
5
|
-
import
|
|
6
|
+
import { createReporter } from './factory.js';
|
|
6
7
|
|
|
7
8
|
const CONTRIBUTION_TOOL_URL = 'https://contribute.opentermsarchive.org/en/service';
|
|
8
9
|
const DOC_URL = 'https://docs.opentermsarchive.org';
|
|
@@ -33,28 +34,65 @@ function getLabelNameFromError(error) {
|
|
|
33
34
|
// In the following class, it is assumed that each issue is managed using its title as a unique identifier
|
|
34
35
|
export default class Reporter {
|
|
35
36
|
constructor(config) {
|
|
36
|
-
const
|
|
37
|
+
const normalizedConfig = Reporter.normalizeConfig(config);
|
|
37
38
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
Reporter.validateConfiguration(normalizedConfig.repositories);
|
|
40
|
+
|
|
41
|
+
this.reporter = createReporter(normalizedConfig);
|
|
42
|
+
this.repositories = normalizedConfig.repositories;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Support for legacy config format where reporter configuration was nested under `githubIssues`
|
|
47
|
+
* Example:
|
|
48
|
+
*
|
|
49
|
+
* ```json
|
|
50
|
+
* {
|
|
51
|
+
* "githubIssues": {
|
|
52
|
+
* "repositories": {
|
|
53
|
+
* "declarations": "OpenTermsArchive/sandbox-declarations"
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @deprecated
|
|
60
|
+
*/
|
|
61
|
+
static normalizeConfig(config) {
|
|
62
|
+
if (config.githubIssues) {
|
|
63
|
+
logger.warn('The "reporter.githubIssues" key is deprecated; please see configuration documentation for the new format: https://docs.opentermsarchive.org/#configuring');
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
type: 'github',
|
|
67
|
+
repositories: config.githubIssues.repositories,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static validateConfiguration(repositories) {
|
|
75
|
+
if (!repositories?.declarations) {
|
|
76
|
+
throw new Error('Required configuration key "reporter.repositories.declarations" was not found; issues on the declarations repository cannot be created');
|
|
42
77
|
}
|
|
43
78
|
|
|
44
|
-
|
|
45
|
-
|
|
79
|
+
for (const [ type, repo ] of Object.entries(repositories)) {
|
|
80
|
+
if (!repo.includes('/') || repo.includes('https://')) {
|
|
81
|
+
throw new Error(`Configuration entry "reporter.repositories.${type}" is expected to be a string in the format <owner>/<repo>, but received: "${repo}"`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
46
84
|
}
|
|
47
85
|
|
|
48
86
|
initialize() {
|
|
49
|
-
return this.
|
|
87
|
+
return this.reporter.initialize();
|
|
50
88
|
}
|
|
51
89
|
|
|
52
90
|
onTrackingStarted() {
|
|
53
|
-
return this.
|
|
91
|
+
return this.reporter.clearCache();
|
|
54
92
|
}
|
|
55
93
|
|
|
56
94
|
async onVersionRecorded(version) {
|
|
57
|
-
await this.
|
|
95
|
+
await this.reporter.closeIssueWithCommentIfExists({
|
|
58
96
|
title: Reporter.generateTitleID(version.serviceId, version.termsType),
|
|
59
97
|
comment: `### Tracking resumed
|
|
60
98
|
|
|
@@ -63,7 +101,7 @@ A new version has been recorded.`,
|
|
|
63
101
|
}
|
|
64
102
|
|
|
65
103
|
async onVersionNotChanged(version) {
|
|
66
|
-
await this.
|
|
104
|
+
await this.reporter.closeIssueWithCommentIfExists({
|
|
67
105
|
title: Reporter.generateTitleID(version.serviceId, version.termsType),
|
|
68
106
|
comment: `### Tracking resumed
|
|
69
107
|
|
|
@@ -76,7 +114,7 @@ No changes were found in the last run, so no new version has been recorded.`,
|
|
|
76
114
|
}
|
|
77
115
|
|
|
78
116
|
async onInaccessibleContent(error, terms) {
|
|
79
|
-
await this.
|
|
117
|
+
await this.reporter.createOrUpdateIssue({
|
|
80
118
|
title: Reporter.generateTitleID(terms.service.id, terms.type),
|
|
81
119
|
description: this.generateDescription({ error, terms }),
|
|
82
120
|
label: getLabelNameFromError(error),
|
|
@@ -97,9 +135,9 @@ No changes were found in the last run, so no new version has been recorded.`,
|
|
|
97
135
|
});
|
|
98
136
|
const contributionToolUrl = `${CONTRIBUTION_TOOL_URL}?${contributionToolParams}`;
|
|
99
137
|
|
|
100
|
-
const latestDeclarationLink = `[Latest declaration](
|
|
101
|
-
const latestVersionLink = `[Latest version](
|
|
102
|
-
const snapshotsBaseUrl =
|
|
138
|
+
const latestDeclarationLink = `[Latest declaration](${this.reporter.generateDeclarationURL(terms.service.name)})`;
|
|
139
|
+
const latestVersionLink = `[Latest version](${this.reporter.generateVersionURL(terms.service.name, terms.type)})`;
|
|
140
|
+
const snapshotsBaseUrl = this.reporter.generateSnapshotsBaseUrl(terms.service.name, terms.type);
|
|
103
141
|
const latestSnapshotsLink = terms.hasMultipleSourceDocuments
|
|
104
142
|
? `Latest snapshots:\n - ${terms.sourceDocuments.map(sourceDocument => `[${sourceDocument.id}](${snapshotsBaseUrl}.%20#${sourceDocument.id}.${mime.getExtension(sourceDocument.mimeType)})`).join('\n - ')}`
|
|
105
143
|
: `[Latest snapshot](${snapshotsBaseUrl}.${mime.getExtension(terms.sourceDocuments[0].mimeType)})`;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
|
|
3
|
+
import Reporter from './index.js';
|
|
4
|
+
|
|
5
|
+
describe('Reporter', () => {
|
|
6
|
+
describe('#normalizeConfig', () => {
|
|
7
|
+
context('with current config format', () => {
|
|
8
|
+
it('returns the config as is', () => {
|
|
9
|
+
const config = { repositories: { declarations: 'owner/repo' } };
|
|
10
|
+
const normalizedConfig = Reporter.normalizeConfig(config);
|
|
11
|
+
|
|
12
|
+
expect(normalizedConfig).to.deep.equal(config);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
context('with old config format where githubIssues is nested under reporter', () => {
|
|
17
|
+
it('returns a normalized config', () => {
|
|
18
|
+
const config = { githubIssues: { repositories: { declarations: 'owner/repo' } } };
|
|
19
|
+
const expectedConfig = {
|
|
20
|
+
type: 'github',
|
|
21
|
+
repositories: { declarations: 'owner/repo' },
|
|
22
|
+
};
|
|
23
|
+
const normalizedConfig = Reporter.normalizeConfig(config);
|
|
24
|
+
|
|
25
|
+
expect(normalizedConfig).to.deep.equal(expectedConfig);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('#validateConfiguration', () => {
|
|
31
|
+
context('with valid configuration', () => {
|
|
32
|
+
it('does not throw an error', () => {
|
|
33
|
+
const repositories = { declarations: 'owner/repo' };
|
|
34
|
+
|
|
35
|
+
expect(() => {
|
|
36
|
+
Reporter.validateConfiguration(repositories);
|
|
37
|
+
}).not.to.throw();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
context('with invalid configuration', () => {
|
|
42
|
+
context('when declarations key is missing', () => {
|
|
43
|
+
it('throws an error', () => {
|
|
44
|
+
const repositories = {};
|
|
45
|
+
|
|
46
|
+
expect(() => {
|
|
47
|
+
Reporter.validateConfiguration(repositories);
|
|
48
|
+
}).to.throw().and.have.property('message').that.match(/Required configuration key.*was not found/);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
context('when repository format is incorrect', () => {
|
|
53
|
+
it('throws an error', () => {
|
|
54
|
+
const repositories = { declarations: 'invalidFormat' };
|
|
55
|
+
|
|
56
|
+
expect(() => {
|
|
57
|
+
Reporter.validateConfiguration(repositories);
|
|
58
|
+
}).to.throw('Configuration entry "reporter.repositories.declarations" is expected to be a string in the format <owner>/<repo>, but received: "invalidFormat"');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
File without changes
|