volunteer-contributions-fetch 3.1.1 → 3.1.2
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/.github/workflows/release.yml +11 -7
- package/.github/workflows/test.yml +5 -4
- package/.husky/pre-commit +1 -0
- package/README.md +8 -1
- package/lib/bugzilla.js +13 -19
- package/lib/bugzilla.test.js +18 -32
- package/lib/community-portal.js +8 -15
- package/lib/community-portal.test.js +14 -20
- package/lib/discourse.js +10 -15
- package/lib/discourse.test.js +12 -16
- package/lib/github.js +25 -19
- package/lib/github.test.js +11 -6
- package/lib/osm.js +6 -15
- package/lib/osm.test.js +9 -4
- package/lib/validator.js +18 -13
- package/lib/validator.test.js +24 -33
- package/lib/wiki.js +9 -0
- package/package.json +13 -12
|
@@ -13,15 +13,19 @@ jobs:
|
|
|
13
13
|
id-token: write
|
|
14
14
|
issues: write
|
|
15
15
|
steps:
|
|
16
|
-
-
|
|
17
|
-
|
|
16
|
+
- name: Checkout
|
|
17
|
+
uses: actions/checkout@v5
|
|
18
|
+
- name: Setup Node
|
|
19
|
+
uses: actions/setup-node@v6
|
|
18
20
|
with:
|
|
19
|
-
node-version:
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
-
|
|
21
|
+
node-version: 24
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: npm ci
|
|
24
|
+
- name: Lint
|
|
25
|
+
run: npm run eslint
|
|
26
|
+
- name: Test
|
|
27
|
+
run: npm test
|
|
23
28
|
- name: Release
|
|
24
29
|
env:
|
|
25
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
26
30
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
27
31
|
run: npx semantic-release
|
|
@@ -6,11 +6,12 @@ jobs:
|
|
|
6
6
|
test:
|
|
7
7
|
runs-on: ubuntu-latest
|
|
8
8
|
steps:
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
- name: Checkout
|
|
10
|
+
uses: actions/checkout@v5
|
|
11
|
+
- name: Setup Node
|
|
12
|
+
uses: actions/setup-node@v6
|
|
12
13
|
with:
|
|
13
|
-
node-version:
|
|
14
|
+
node-version: 24
|
|
14
15
|
- name: Install Dependencies
|
|
15
16
|
run: npm ci
|
|
16
17
|
- name: Linting
|
package/.husky/pre-commit
CHANGED
package/README.md
CHANGED
|
@@ -245,7 +245,6 @@ npm ci
|
|
|
245
245
|
### Tests
|
|
246
246
|
|
|
247
247
|
```bash
|
|
248
|
-
npm run eslint
|
|
249
248
|
npm test
|
|
250
249
|
```
|
|
251
250
|
|
|
@@ -259,6 +258,14 @@ cp .env.example .env
|
|
|
259
258
|
|
|
260
259
|
You then can use `npm run example` which uses `fetchAll` if you would like to test changes within this project. The configuration for this can be adjusted in `example/index.js`. A full sample config can be found in the configuration section above. Please make sure to not include testing config file changes when committing! The file is not ignored to make it so that new checkouts do not have to copy around a file first.
|
|
261
260
|
|
|
261
|
+
### Linting
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
npm run eslint
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Note that due to the AirBnB config we are still using ESLint 8.
|
|
268
|
+
|
|
262
269
|
### Deployments
|
|
263
270
|
|
|
264
271
|
Please use [Angular Commit Message Conventions](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-format) when contributing to this project, as depending on the commit message the GitHub Action will directly publish a new version of the package.
|
package/lib/bugzilla.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Debug from 'debug';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
|
|
3
4
|
import { getPadded } from './utils.js';
|
|
4
5
|
|
|
@@ -13,25 +14,18 @@ const TYPE_COMMENTED = 'Commented on a Bug Report';
|
|
|
13
14
|
const RESULTS_PER_PAGE = 500;
|
|
14
15
|
const FETCH_TIMEOUT = 120000;
|
|
15
16
|
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
throw new Error('Bugzilla: username is required');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (config && config.enabled && !config.stopDate) {
|
|
32
|
-
throw new Error('Bugzilla: stopDate is required');
|
|
33
|
-
}
|
|
34
|
-
}
|
|
17
|
+
export const bugzillaSchema = z.object({
|
|
18
|
+
enabled: z.boolean(),
|
|
19
|
+
baseUrl: z.string().min(1),
|
|
20
|
+
username: z.string().min(1),
|
|
21
|
+
stopDate: z.string(),
|
|
22
|
+
types: z
|
|
23
|
+
.object({
|
|
24
|
+
createdType: z.string().optional(),
|
|
25
|
+
commentedType: z.string().optional(),
|
|
26
|
+
})
|
|
27
|
+
.optional(),
|
|
28
|
+
});
|
|
35
29
|
|
|
36
30
|
export async function gather({ bugzilla }, existingContributions = []) {
|
|
37
31
|
if (!bugzilla || (bugzilla && !bugzilla.enabled)) {
|
package/lib/bugzilla.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { afterEach, beforeEach, expect, test, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { gather,
|
|
3
|
+
import { gather, bugzillaSchema } from './bugzilla.js';
|
|
4
4
|
|
|
5
5
|
const config = {
|
|
6
6
|
bugzilla: {
|
|
@@ -72,43 +72,29 @@ afterEach(() => {
|
|
|
72
72
|
vi.restoreAllMocks();
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
test('
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('should validate config - missing completely', () => {
|
|
80
|
-
const emptyConfig = {};
|
|
81
|
-
expect(() => validate(emptyConfig)).not.toThrow();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('should validate config - missing baseUrl', () => {
|
|
85
|
-
const failConfig = {
|
|
75
|
+
test('Bugzilla schema - valid config', () => {
|
|
76
|
+
const validConfig = {
|
|
86
77
|
enabled: true,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
test('should validate config - missing username', () => {
|
|
95
|
-
const failConfig = {
|
|
96
|
-
enabled: true,
|
|
97
|
-
baseUrl: 'A',
|
|
98
|
-
stopDate: new Date(),
|
|
78
|
+
baseUrl: 'https://bugzilla.test',
|
|
79
|
+
username: 'testuser',
|
|
80
|
+
stopDate: '2023-01-01',
|
|
81
|
+
types: {
|
|
82
|
+
createdType: 'Created a Test Bug',
|
|
83
|
+
commentedType: 'Commented on a Test Bug',
|
|
84
|
+
},
|
|
99
85
|
};
|
|
100
|
-
|
|
101
|
-
expect(
|
|
86
|
+
const result = bugzillaSchema.parse(validConfig);
|
|
87
|
+
expect(result).toBeDefined();
|
|
102
88
|
});
|
|
103
89
|
|
|
104
|
-
test('
|
|
105
|
-
const
|
|
90
|
+
test('Bugzilla schema - invalid config', () => {
|
|
91
|
+
const invalidConfig = {
|
|
106
92
|
enabled: true,
|
|
107
|
-
baseUrl: '
|
|
108
|
-
username: '
|
|
93
|
+
baseUrl: 'https://example.com',
|
|
94
|
+
username: '',
|
|
95
|
+
stopDate: '2024-01-01',
|
|
109
96
|
};
|
|
110
|
-
|
|
111
|
-
expect(() => validate(failConfig)).toThrow();
|
|
97
|
+
expect(() => bugzillaSchema.parse(invalidConfig)).toThrow();
|
|
112
98
|
});
|
|
113
99
|
|
|
114
100
|
test('should fetch', async () => {
|
package/lib/community-portal.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Debug from 'debug';
|
|
2
2
|
import { JSDOM } from 'jsdom';
|
|
3
|
+
import { z } from 'zod';
|
|
3
4
|
|
|
4
5
|
const debug = Debug('contributions:community-portal');
|
|
5
6
|
|
|
@@ -9,21 +10,13 @@ export const CAMPAIGNS_CATEGORY = 'community-portal-campaigns';
|
|
|
9
10
|
const TYPE_PARTICIPATION = 'Participated in an event';
|
|
10
11
|
const TYPE_CAMPAIGN = 'Participated in a campaign';
|
|
11
12
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (config && config.enabled && !config.baseUrl) {
|
|
20
|
-
throw new Error('Community Portal: baseUrl is required');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (config && config.enabled && !config.username) {
|
|
24
|
-
throw new Error('Community Portal: username is required');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
13
|
+
export const communityPortalSchema = z.object({
|
|
14
|
+
enabled: z.boolean(),
|
|
15
|
+
baseUrl: z.string().min(1),
|
|
16
|
+
username: z.string().min(1),
|
|
17
|
+
participationType: z.string().optional(),
|
|
18
|
+
campaignType: z.string().optional(),
|
|
19
|
+
});
|
|
27
20
|
|
|
28
21
|
export async function gather({ communityPortal }) {
|
|
29
22
|
if (!communityPortal || (communityPortal && !communityPortal.enabled)) {
|
|
@@ -2,7 +2,7 @@ import { JSDOM } from 'jsdom';
|
|
|
2
2
|
import { afterEach, beforeEach, expect, test, vi } from 'vitest';
|
|
3
3
|
|
|
4
4
|
import * as fixtures from '../fixtures/community-portal.js';
|
|
5
|
-
import { gather,
|
|
5
|
+
import { gather, communityPortalSchema } from './community-portal.js';
|
|
6
6
|
|
|
7
7
|
const config = {
|
|
8
8
|
communityPortal: {
|
|
@@ -20,31 +20,25 @@ afterEach(() => {
|
|
|
20
20
|
vi.restoreAllMocks();
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
test('
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('should validate config - missing completely', () => {
|
|
28
|
-
const emptyConfig = {};
|
|
29
|
-
expect(() => validate(emptyConfig)).not.toThrow();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('should validate config - missing baseUrl', () => {
|
|
33
|
-
const failConfig = {
|
|
23
|
+
test('Community Portal schema - valid config', () => {
|
|
24
|
+
const validConfig = {
|
|
34
25
|
enabled: true,
|
|
35
|
-
|
|
26
|
+
baseUrl: 'https://community.mozilla.org',
|
|
27
|
+
username: 'testuser',
|
|
28
|
+
participationType: 'Test Event',
|
|
29
|
+
campaignType: 'Test Campaign',
|
|
36
30
|
};
|
|
37
|
-
|
|
38
|
-
expect(
|
|
31
|
+
const result = communityPortalSchema.parse(validConfig);
|
|
32
|
+
expect(result).toBeDefined();
|
|
39
33
|
});
|
|
40
34
|
|
|
41
|
-
test('
|
|
42
|
-
const
|
|
35
|
+
test('Community Portal schema - invalid config', () => {
|
|
36
|
+
const invalidConfig = {
|
|
43
37
|
enabled: true,
|
|
44
|
-
baseUrl: '
|
|
38
|
+
baseUrl: '',
|
|
39
|
+
username: 'testuser',
|
|
45
40
|
};
|
|
46
|
-
|
|
47
|
-
expect(() => validate(failConfig)).toThrow();
|
|
41
|
+
expect(() => communityPortalSchema.parse(invalidConfig));
|
|
48
42
|
});
|
|
49
43
|
|
|
50
44
|
test('should fetch', async () => {
|
package/lib/discourse.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import Debug from 'debug';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
2
4
|
import { ensureUniqueContributions } from './contributions.js';
|
|
3
5
|
|
|
4
6
|
const debug = Debug('contributions:discourse');
|
|
@@ -10,21 +12,14 @@ export const POSTS_CATEGORY = 'discourse-posts';
|
|
|
10
12
|
const TYPE_TOPIC = 'Created Discourse Topic';
|
|
11
13
|
const TYPE_POST = 'Posted on Discourse Topic';
|
|
12
14
|
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
throw new Error('Discourse: baseUrl is required');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (config && config.enabled && !config.username) {
|
|
25
|
-
throw new Error('Discourse: username is required');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
15
|
+
export const discourseSchema = z.object({
|
|
16
|
+
enabled: z.boolean(),
|
|
17
|
+
baseUrl: z.string().min(1),
|
|
18
|
+
username: z.string().min(1),
|
|
19
|
+
topicType: z.string().optional(),
|
|
20
|
+
postType: z.string().optional(),
|
|
21
|
+
keepDeletedPost: z.boolean().default(false),
|
|
22
|
+
});
|
|
28
23
|
|
|
29
24
|
export async function gather({ discourse }, existingContributions = []) {
|
|
30
25
|
if (!discourse || (discourse && !discourse.enabled)) {
|
package/lib/discourse.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { afterEach, beforeEach, expect, test, vi } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { gather,
|
|
3
|
+
import { gather, discourseSchema } from './discourse.js';
|
|
4
4
|
|
|
5
5
|
const TOPICS = {
|
|
6
6
|
topic_list: {
|
|
@@ -79,27 +79,23 @@ afterEach(() => {
|
|
|
79
79
|
vi.resetAllMocks();
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
test('
|
|
83
|
-
const
|
|
84
|
-
expect(() => validate(emptyConfig)).not.toThrow();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('should validate config - missing baseUrl', () => {
|
|
88
|
-
const failConfig = {
|
|
82
|
+
test('Discourse schema - valid config', () => {
|
|
83
|
+
const validConfig = {
|
|
89
84
|
enabled: true,
|
|
90
|
-
|
|
85
|
+
baseUrl: 'https://discourse.test',
|
|
86
|
+
username: 'testuser',
|
|
91
87
|
};
|
|
92
|
-
|
|
93
|
-
expect(
|
|
88
|
+
const result = discourseSchema.parse(validConfig);
|
|
89
|
+
expect(result).toBeDefined();
|
|
94
90
|
});
|
|
95
91
|
|
|
96
|
-
test('
|
|
97
|
-
const
|
|
92
|
+
test('Discourse schema - invalid config', () => {
|
|
93
|
+
const invalidConfig = {
|
|
98
94
|
enabled: true,
|
|
99
|
-
baseUrl: '
|
|
95
|
+
baseUrl: '',
|
|
96
|
+
username: 'testuser',
|
|
100
97
|
};
|
|
101
|
-
|
|
102
|
-
expect(() => validate(failConfig)).toThrow();
|
|
98
|
+
expect(() => discourseSchema.parse(invalidConfig)).toThrow();
|
|
103
99
|
});
|
|
104
100
|
|
|
105
101
|
test('should fetch', async () => {
|
package/lib/github.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Debug from 'debug';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import {
|
|
3
4
|
listComments,
|
|
4
5
|
listReviews,
|
|
@@ -30,25 +31,30 @@ const TYPE_CHANGES_REQUESTED_PR = 'Requested changes on a Pull Request';
|
|
|
30
31
|
const TYPE_REVIEWED_PR = 'Reviewed a Pull Request';
|
|
31
32
|
const TYPE_COMMENTED = 'Commented on an Issue';
|
|
32
33
|
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
export const githubSchema = z.object({
|
|
35
|
+
enabled: z.boolean(),
|
|
36
|
+
allowPrivate: z.boolean().default(false),
|
|
37
|
+
commentsEnabled: z.boolean().default(true),
|
|
38
|
+
commitsEnabled: z.boolean().default(true),
|
|
39
|
+
issuesEnabled: z.boolean().default(true),
|
|
40
|
+
reviewsEnabled: z.boolean().default(true),
|
|
41
|
+
username: z.string().min(1),
|
|
42
|
+
stopDate: z.string(),
|
|
43
|
+
filter: z.string(),
|
|
44
|
+
types: z
|
|
45
|
+
.object({
|
|
46
|
+
commit: z.string().optional(),
|
|
47
|
+
privateCommit: z.string().optional(),
|
|
48
|
+
createdPR: z.string().optional(),
|
|
49
|
+
createdIssue: z.string().optional(),
|
|
50
|
+
commentedPR: z.string().optional(),
|
|
51
|
+
approvedPR: z.string().optional(),
|
|
52
|
+
changesRequestedPR: z.string().optional(),
|
|
53
|
+
reviewedPR: z.string().optional(),
|
|
54
|
+
})
|
|
55
|
+
.optional(),
|
|
56
|
+
delayMsPerRequest: z.number().default(2000),
|
|
57
|
+
});
|
|
52
58
|
|
|
53
59
|
export async function gather({ github }, existingContributions = []) {
|
|
54
60
|
if (!github || (github && !github.enabled)) {
|
package/lib/github.test.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { afterEach, beforeEach, expect, test, vi } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import * as fetcher from './github-fetcher.js';
|
|
4
|
-
import { gather,
|
|
4
|
+
import { gather, githubSchema } from './github.js';
|
|
5
5
|
|
|
6
6
|
const config = {
|
|
7
7
|
github: {
|
|
8
8
|
enabled: true,
|
|
9
9
|
username: 'user',
|
|
10
|
-
stopDate:
|
|
10
|
+
stopDate: '2022-01-01',
|
|
11
11
|
filter: '',
|
|
12
12
|
delayMsPerRequest: 0,
|
|
13
13
|
},
|
|
@@ -36,9 +36,14 @@ afterEach(() => {
|
|
|
36
36
|
vi.restoreAllMocks();
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
+
test('should validate valid config', () => {
|
|
40
|
+
const result = githubSchema.parse(config.github);
|
|
41
|
+
expect(result).toBeDefined();
|
|
42
|
+
});
|
|
43
|
+
|
|
39
44
|
test('should validate config - missing completely', () => {
|
|
40
45
|
const emptyConfig = {};
|
|
41
|
-
expect(() =>
|
|
46
|
+
expect(() => githubSchema.parse(emptyConfig)).toThrow();
|
|
42
47
|
});
|
|
43
48
|
|
|
44
49
|
test('should validate config - missing filter', () => {
|
|
@@ -48,7 +53,7 @@ test('should validate config - missing filter', () => {
|
|
|
48
53
|
stopDate: new Date('2022-01-01'),
|
|
49
54
|
};
|
|
50
55
|
|
|
51
|
-
expect(() =>
|
|
56
|
+
expect(() => githubSchema.parse(failConfig)).toThrow();
|
|
52
57
|
});
|
|
53
58
|
|
|
54
59
|
test('should validate config - missing username', () => {
|
|
@@ -58,7 +63,7 @@ test('should validate config - missing username', () => {
|
|
|
58
63
|
filter: '',
|
|
59
64
|
};
|
|
60
65
|
|
|
61
|
-
expect(() =>
|
|
66
|
+
expect(() => githubSchema.parse(failConfig)).toThrow();
|
|
62
67
|
});
|
|
63
68
|
|
|
64
69
|
test('should validate config - missing stopDate', () => {
|
|
@@ -68,7 +73,7 @@ test('should validate config - missing stopDate', () => {
|
|
|
68
73
|
filter: '',
|
|
69
74
|
};
|
|
70
75
|
|
|
71
|
-
expect(() =>
|
|
76
|
+
expect(() => githubSchema.parse(failConfig)).toThrow();
|
|
72
77
|
});
|
|
73
78
|
|
|
74
79
|
test('should not fetch if disabled - by enable property', async () => {
|
package/lib/osm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Debug from 'debug';
|
|
2
2
|
import { parseString } from 'xml2js';
|
|
3
3
|
import { promisify } from 'util';
|
|
4
|
+
import { z } from 'zod';
|
|
4
5
|
|
|
5
6
|
const debug = Debug('contributions:openstreetmaps');
|
|
6
7
|
const parseStringAsync = promisify(parseString);
|
|
@@ -11,21 +12,11 @@ const TYPE_EDIT = 'OpenStreetMaps Edit';
|
|
|
11
12
|
|
|
12
13
|
const MAX_EDITS_PER_PAGE = 100;
|
|
13
14
|
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (config && config.enabled && !config.displayName) {
|
|
22
|
-
throw new Error('OSM: displayName is required');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (config && config.enabled && !config.stopDate) {
|
|
26
|
-
throw new Error('OSM: stopDate is required');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
15
|
+
export const osmSchema = z.object({
|
|
16
|
+
enabled: z.boolean(),
|
|
17
|
+
displayName: z.string().min(1),
|
|
18
|
+
stopDate: z.string(),
|
|
19
|
+
});
|
|
29
20
|
|
|
30
21
|
export async function gather({ osm }) {
|
|
31
22
|
if (!osm || (osm && !osm.enabled)) {
|
package/lib/osm.test.js
CHANGED
|
@@ -7,7 +7,7 @@ const config = {
|
|
|
7
7
|
osm: {
|
|
8
8
|
enabled: true,
|
|
9
9
|
displayName: 'user',
|
|
10
|
-
stopDate:
|
|
10
|
+
stopDate: '2021-11-01',
|
|
11
11
|
},
|
|
12
12
|
};
|
|
13
13
|
|
|
@@ -23,9 +23,14 @@ afterEach(() => {
|
|
|
23
23
|
vi.restoreAllMocks();
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
+
test('should validate valid config', () => {
|
|
27
|
+
const result = osm.osmSchema.parse(config.osm);
|
|
28
|
+
expect(result).toBeDefined();
|
|
29
|
+
});
|
|
30
|
+
|
|
26
31
|
test('should validate config - missing completely', () => {
|
|
27
32
|
const emptyConfig = {};
|
|
28
|
-
expect(() => osm.
|
|
33
|
+
expect(() => osm.osmSchema.parse(emptyConfig)).toThrow();
|
|
29
34
|
});
|
|
30
35
|
|
|
31
36
|
test('should validate config - missing displayName', () => {
|
|
@@ -34,7 +39,7 @@ test('should validate config - missing displayName', () => {
|
|
|
34
39
|
stopDate: new Date(),
|
|
35
40
|
};
|
|
36
41
|
|
|
37
|
-
expect(() => osm.
|
|
42
|
+
expect(() => osm.osmSchema.parse(failConfig)).toThrow();
|
|
38
43
|
});
|
|
39
44
|
|
|
40
45
|
test('should validate config - missing stopDate', () => {
|
|
@@ -43,7 +48,7 @@ test('should validate config - missing stopDate', () => {
|
|
|
43
48
|
displayName: 'user',
|
|
44
49
|
};
|
|
45
50
|
|
|
46
|
-
expect(() => osm.
|
|
51
|
+
expect(() => osm.osmSchema.parse(failConfig)).toThrow();
|
|
47
52
|
});
|
|
48
53
|
|
|
49
54
|
test('should fetch', async () => {
|
package/lib/validator.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import Debug from 'debug';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { communityPortalSchema } from './community-portal.js';
|
|
5
|
+
import { discourseSchema } from './discourse.js';
|
|
6
|
+
import { githubSchema } from './github.js';
|
|
7
|
+
import { mediaWikiSchema } from './wiki.js';
|
|
8
|
+
import { bugzillaSchema } from './bugzilla.js';
|
|
9
|
+
import { osmSchema } from './osm.js';
|
|
7
10
|
|
|
8
11
|
const debug = Debug('contributions:validator');
|
|
9
12
|
|
|
13
|
+
export const configSchema = z.object({
|
|
14
|
+
outputFile: z.string().optional(),
|
|
15
|
+
communityPortal: communityPortalSchema.optional(),
|
|
16
|
+
discourse: discourseSchema.optional(),
|
|
17
|
+
mediaWiki: mediaWikiSchema.optional(),
|
|
18
|
+
github: githubSchema.optional(),
|
|
19
|
+
bugzilla: bugzillaSchema.optional(),
|
|
20
|
+
osm: osmSchema.optional(),
|
|
21
|
+
});
|
|
22
|
+
|
|
10
23
|
export function validateConfig(config) {
|
|
11
24
|
debug('Validating config..');
|
|
12
|
-
|
|
13
|
-
if (!config) {
|
|
14
|
-
throw new Error('No config passed!');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
validateCommunityPortal(config.communityPortal);
|
|
18
|
-
validateDiscourse(config.discourse);
|
|
19
|
-
validateWiki(config.mediaWiki);
|
|
20
|
-
validateGithub(config.github);
|
|
25
|
+
configSchema.parse(config);
|
|
21
26
|
}
|
package/lib/validator.test.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import * as communityPortal from './community-portal.js';
|
|
4
|
-
import * as discourse from './discourse.js';
|
|
5
|
-
import * as github from './github.js';
|
|
6
|
-
import * as wiki from './wiki.js';
|
|
1
|
+
import { expect, test } from 'vitest';
|
|
7
2
|
|
|
8
3
|
import { validateConfig } from './validator.js';
|
|
9
4
|
|
|
@@ -11,17 +6,6 @@ const config = {
|
|
|
11
6
|
outputFile: 'file',
|
|
12
7
|
};
|
|
13
8
|
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
vi.spyOn(communityPortal, 'validate');
|
|
16
|
-
vi.spyOn(discourse, 'validate');
|
|
17
|
-
vi.spyOn(github, 'validate');
|
|
18
|
-
vi.spyOn(wiki, 'validate');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
vi.resetAllMocks();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
9
|
test('should validate config - all ok', () => {
|
|
26
10
|
expect(() => validateConfig(config)).not.toThrow();
|
|
27
11
|
});
|
|
@@ -31,29 +15,36 @@ test('should throw when missing config', () => {
|
|
|
31
15
|
});
|
|
32
16
|
|
|
33
17
|
test('should throw when community portal validation fails', () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
expect(() => validateConfig(
|
|
18
|
+
const failConfig = {
|
|
19
|
+
communityPortal: {},
|
|
20
|
+
};
|
|
21
|
+
expect(() => validateConfig(failConfig)).toThrow();
|
|
38
22
|
});
|
|
39
23
|
|
|
40
24
|
test('should throw when discourse validation fails', () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
expect(() => validateConfig(
|
|
25
|
+
const failConfig = {
|
|
26
|
+
discourse: {},
|
|
27
|
+
};
|
|
28
|
+
expect(() => validateConfig(failConfig)).toThrow();
|
|
45
29
|
});
|
|
46
30
|
|
|
47
31
|
test('should throw when github validation fails', () => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
expect(() => validateConfig(
|
|
32
|
+
const failConfig = {
|
|
33
|
+
github: {},
|
|
34
|
+
};
|
|
35
|
+
expect(() => validateConfig(failConfig)).toThrow();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('should throw when osm validation fails', () => {
|
|
39
|
+
const failConfig = {
|
|
40
|
+
osm: {},
|
|
41
|
+
};
|
|
42
|
+
expect(() => validateConfig(failConfig)).toThrow();
|
|
52
43
|
});
|
|
53
44
|
|
|
54
45
|
test('should throw when wiki validation fails', () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
expect(() => validateConfig(
|
|
46
|
+
const failConfig = {
|
|
47
|
+
mediaWiki: {},
|
|
48
|
+
};
|
|
49
|
+
expect(() => validateConfig(failConfig)).toThrow();
|
|
59
50
|
});
|
package/lib/wiki.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Debug from 'debug';
|
|
2
2
|
import { parseString } from 'xml2js';
|
|
3
3
|
import { promisify } from 'util';
|
|
4
|
+
import { z } from 'zod';
|
|
4
5
|
|
|
5
6
|
const debug = Debug('contributions:wiki');
|
|
6
7
|
const parseStringAsync = promisify(parseString);
|
|
@@ -9,6 +10,14 @@ export const WIKI_CATEGORY = 'wiki';
|
|
|
9
10
|
|
|
10
11
|
const TYPE_EDIT = 'Wiki Edit';
|
|
11
12
|
|
|
13
|
+
export const mediaWikiSchema = z.object({
|
|
14
|
+
enabled: z.boolean(),
|
|
15
|
+
baseUrl: z.string().min(1),
|
|
16
|
+
username: z.string().min(1),
|
|
17
|
+
editType: z.string(),
|
|
18
|
+
stopDate: z.string(),
|
|
19
|
+
});
|
|
20
|
+
|
|
12
21
|
export function validate(config) {
|
|
13
22
|
debug('Validating Wiki config');
|
|
14
23
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volunteer-contributions-fetch",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Library to fetch volunteer contributions from several sources such as GitHub",
|
|
5
5
|
"author": "Michael Kohler",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,23 +11,24 @@
|
|
|
11
11
|
"main": "index.js",
|
|
12
12
|
"type": "module",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@octokit/rest": "^
|
|
15
|
-
"debug": "^4.3
|
|
16
|
-
"jsdom": "^
|
|
17
|
-
"xml2js": "^0.6.2"
|
|
14
|
+
"@octokit/rest": "^22.0.0",
|
|
15
|
+
"debug": "^4.4.3",
|
|
16
|
+
"jsdom": "^27.0.0",
|
|
17
|
+
"xml2js": "^0.6.2",
|
|
18
|
+
"zod": "^4.1.12"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
|
-
"@commitlint/cli": "^
|
|
21
|
-
"@commitlint/config-angular": "^
|
|
22
|
-
"@vitest/coverage-v8": "^2.
|
|
21
|
+
"@commitlint/cli": "^20.1.0",
|
|
22
|
+
"@commitlint/config-angular": "^20.0.0",
|
|
23
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
23
24
|
"eslint": "^8.47.0",
|
|
24
25
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
25
26
|
"eslint-config-prettier": "^9.0.0",
|
|
26
|
-
"eslint-plugin-prettier": "^5.
|
|
27
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
27
28
|
"husky": "^9.1.7",
|
|
28
|
-
"prettier": "^3.
|
|
29
|
-
"semantic-release": "^
|
|
30
|
-
"vitest": "^2.
|
|
29
|
+
"prettier": "^3.6.2",
|
|
30
|
+
"semantic-release": "^25.0.1-beta.1",
|
|
31
|
+
"vitest": "^3.2.4"
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|
|
33
34
|
"prepare": "husky",
|