volunteer-contributions-fetch 3.1.1 → 3.1.3
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/dependabot.yml +27 -0
- package/.github/workflows/release.yml +11 -7
- package/.github/workflows/test.yml +5 -4
- package/.husky/pre-commit +1 -0
- package/README.md +6 -1
- package/eslint.config.mjs +44 -0
- package/example/index.js +0 -1
- package/lib/bugzilla.js +13 -22
- package/lib/bugzilla.test.js +19 -33
- package/lib/community-portal.js +8 -15
- package/lib/community-portal.test.js +15 -21
- package/lib/discourse.js +12 -17
- package/lib/discourse.test.js +12 -16
- package/lib/github-fetcher.js +0 -1
- package/lib/github.js +26 -20
- package/lib/github.test.js +25 -20
- package/lib/osm.js +6 -16
- package/lib/osm.test.js +10 -5
- package/lib/validator.js +18 -13
- package/lib/validator.test.js +24 -33
- package/lib/wiki.js +9 -0
- package/lib/wiki.test.js +1 -1
- package/package.json +17 -15
- package/.eslintrc +0 -23
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: 'github-actions'
|
|
4
|
+
directory: '/'
|
|
5
|
+
schedule:
|
|
6
|
+
interval: 'daily'
|
|
7
|
+
- package-ecosystem: 'npm'
|
|
8
|
+
directory: '/'
|
|
9
|
+
schedule:
|
|
10
|
+
interval: 'weekly'
|
|
11
|
+
cooldown:
|
|
12
|
+
default-days: 7
|
|
13
|
+
semver-major-days: 14
|
|
14
|
+
semver-minor-days: 7
|
|
15
|
+
semver-patch-days: 7
|
|
16
|
+
groups:
|
|
17
|
+
production-dependencies:
|
|
18
|
+
dependency-type: 'production'
|
|
19
|
+
update-types:
|
|
20
|
+
- 'minor'
|
|
21
|
+
- 'patch'
|
|
22
|
+
development-dependencies:
|
|
23
|
+
dependency-type: 'development'
|
|
24
|
+
update-types:
|
|
25
|
+
- 'major'
|
|
26
|
+
- 'minor'
|
|
27
|
+
- 'patch'
|
|
@@ -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@v6
|
|
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@v6
|
|
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,12 @@ 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
|
+
|
|
262
267
|
### Deployments
|
|
263
268
|
|
|
264
269
|
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.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { defineConfig, globalIgnores } from 'eslint/config';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import js from '@eslint/js';
|
|
5
|
+
import { FlatCompat } from '@eslint/eslintrc';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
const compat = new FlatCompat({
|
|
10
|
+
baseDirectory: __dirname,
|
|
11
|
+
recommendedConfig: js.configs.recommended,
|
|
12
|
+
allConfig: js.configs.all,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export default defineConfig([
|
|
16
|
+
globalIgnores(['.nyc_output/**/*', 'coverage/**/*', 'node_modules']),
|
|
17
|
+
{
|
|
18
|
+
extends: compat.extends('plugin:prettier/recommended'),
|
|
19
|
+
|
|
20
|
+
languageOptions: {
|
|
21
|
+
ecmaVersion: 2022,
|
|
22
|
+
sourceType: 'module',
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
settings: {
|
|
26
|
+
'import/resolver': {
|
|
27
|
+
node: {
|
|
28
|
+
paths: ['lib'],
|
|
29
|
+
extensions: ['.js', '.d.ts'],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
rules: {
|
|
35
|
+
'arrow-body-style': 0,
|
|
36
|
+
'comma-dangle': 0,
|
|
37
|
+
'import/extensions': 0,
|
|
38
|
+
'import/prefer-default-export': 0,
|
|
39
|
+
'no-plusplus': 0,
|
|
40
|
+
'no-restricted-syntax': 0,
|
|
41
|
+
'no-use-before-define': 0,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
]);
|
package/example/index.js
CHANGED
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)) {
|
|
@@ -87,11 +81,9 @@ async function* bugPageGenerator(bugzilla, stopDate) {
|
|
|
87
81
|
const query = `quicksearch=ALL%20commenter:${bugzilla.username}&limit=${RESULTS_PER_PAGE}&offset=${offset}&last_change_time=${stop}`;
|
|
88
82
|
const bugsUrl = `${bugzilla.baseUrl}/rest/bug?${query}`;
|
|
89
83
|
debug(`Fetching from ${bugsUrl}`);
|
|
90
|
-
// eslint-disable-next-line no-await-in-loop
|
|
91
84
|
const response = await fetch(bugsUrl, {
|
|
92
85
|
signal: AbortSignal.timeout(FETCH_TIMEOUT),
|
|
93
86
|
});
|
|
94
|
-
// eslint-disable-next-line no-await-in-loop
|
|
95
87
|
const data = await response.json();
|
|
96
88
|
debug(`Got ${data.bugs.length} bugs results`);
|
|
97
89
|
// If we have less results than the max result, we're at the end
|
|
@@ -110,7 +102,6 @@ async function* getComments(bugzilla, bugs, titleMap) {
|
|
|
110
102
|
for await (const bug of bugs) {
|
|
111
103
|
const commentsUrl = `${bugzilla.baseUrl}/rest/bug/${bug.id}/comment`;
|
|
112
104
|
debug(`Fetching from ${commentsUrl}`);
|
|
113
|
-
// eslint-disable-next-line no-await-in-loop
|
|
114
105
|
const response = await fetch(commentsUrl, {
|
|
115
106
|
signal: AbortSignal.timeout(FETCH_TIMEOUT),
|
|
116
107
|
});
|
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: {
|
|
@@ -69,46 +69,32 @@ beforeEach(() => {
|
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
afterEach(() => {
|
|
72
|
-
vi.
|
|
72
|
+
vi.resetAllMocks();
|
|
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: {
|
|
@@ -17,34 +17,28 @@ beforeEach(() => {
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
afterEach(() => {
|
|
20
|
-
vi.
|
|
20
|
+
vi.resetAllMocks();
|
|
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)) {
|
|
@@ -109,7 +104,7 @@ async function* topicPageGenerator(baseUrl, username) {
|
|
|
109
104
|
while (true) {
|
|
110
105
|
debug(`Getting page ${page}`);
|
|
111
106
|
const url = `${baseUrl}/topics/created-by/${username}.json?page=${page}`;
|
|
112
|
-
const results = await getDiscourseData(url);
|
|
107
|
+
const results = await getDiscourseData(url);
|
|
113
108
|
page++;
|
|
114
109
|
yield results;
|
|
115
110
|
}
|
|
@@ -121,7 +116,7 @@ async function* postPageGenerator(baseUrl, username) {
|
|
|
121
116
|
debug(`Getting page ${page}`);
|
|
122
117
|
const offset = page * RESULTS_PER_PAGE;
|
|
123
118
|
const url = `${baseUrl}/user_actions.json?username=${username}&filter=5&offset=${offset}`;
|
|
124
|
-
const results = await getDiscourseData(url);
|
|
119
|
+
const results = await getDiscourseData(url);
|
|
125
120
|
page++;
|
|
126
121
|
yield results;
|
|
127
122
|
}
|
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-fetcher.js
CHANGED
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)) {
|
|
@@ -361,7 +367,7 @@ async function* pageGenerator(github, period, cb, { skipProcessing } = {}) {
|
|
|
361
367
|
let page = 1;
|
|
362
368
|
while (hasMoreToFetch) {
|
|
363
369
|
debug(`Getting data for period between ${period[1]} and ${period[0]}`);
|
|
364
|
-
const results = await cb(period, page);
|
|
370
|
+
const results = await cb(period, page);
|
|
365
371
|
|
|
366
372
|
if (!Array.isArray(results)) {
|
|
367
373
|
return;
|
package/lib/github.test.js
CHANGED
|
@@ -1,44 +1,49 @@
|
|
|
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
|
},
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
vi.mock('./github-fetcher.js', async () => {
|
|
17
|
+
return {
|
|
18
|
+
PRIVATE_SCOPE_ERROR: 'PRIVATE_SCOPE',
|
|
19
|
+
RESULTS_PER_PAGE: 100,
|
|
20
|
+
searchCommits: vi.fn().mockResolvedValue([]),
|
|
21
|
+
searchIssues: vi.fn().mockResolvedValue([]),
|
|
22
|
+
listReviews: vi.fn().mockResolvedValue([]),
|
|
23
|
+
listComments: vi.fn().mockResolvedValue([]),
|
|
24
|
+
throwIfTokenHasPrivateRepoScope: vi.fn(),
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
|
|
16
28
|
beforeEach(() => {
|
|
17
29
|
vi.useFakeTimers();
|
|
18
30
|
vi.setSystemTime(new Date('2022-03-02'));
|
|
19
31
|
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
PRIVATE_SCOPE_ERROR: 'PRIVATE_SCOPE',
|
|
23
|
-
RESULTS_PER_PAGE: 100,
|
|
24
|
-
searchCommits: vi.fn().mockResolvedValue([]),
|
|
25
|
-
searchIssues: vi.fn().mockResolvedValue([]),
|
|
26
|
-
listReviews: vi.fn().mockResolvedValue([]),
|
|
27
|
-
listComments: vi.fn().mockResolvedValue([]),
|
|
28
|
-
throwIfTokenHasPrivateRepoScope: vi.fn(),
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
vi.stubEnv('GITHUB_TOKEN', 'some_test_token');
|
|
32
|
+
process.env.GITHUB_TOKEN = 'some_test_token';
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
afterEach(() => {
|
|
36
|
-
vi.
|
|
36
|
+
vi.resetAllMocks();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('should validate valid config', () => {
|
|
40
|
+
const result = githubSchema.parse(config.github);
|
|
41
|
+
expect(result).toBeDefined();
|
|
37
42
|
});
|
|
38
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)) {
|
|
@@ -46,7 +37,6 @@ async function processEdits({ displayName, stopDate }) {
|
|
|
46
37
|
let createdBefore = new Date().toISOString();
|
|
47
38
|
|
|
48
39
|
while (hasMoreData) {
|
|
49
|
-
// eslint-disable-next-line no-await-in-loop
|
|
50
40
|
const edits = await getPage(displayName, stopDate, createdBefore);
|
|
51
41
|
debug(`Got ${edits.length} results to filter`);
|
|
52
42
|
const processed = processEntities(edits);
|
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
|
|
|
@@ -20,12 +20,17 @@ beforeEach(() => {
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
afterEach(() => {
|
|
23
|
-
vi.
|
|
23
|
+
vi.resetAllMocks();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('should validate valid config', () => {
|
|
27
|
+
const result = osm.osmSchema.parse(config.osm);
|
|
28
|
+
expect(result).toBeDefined();
|
|
24
29
|
});
|
|
25
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/lib/wiki.test.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volunteer-contributions-fetch",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
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,25 @@
|
|
|
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": "^29.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
|
-
"@
|
|
23
|
-
"eslint": "^
|
|
24
|
-
"
|
|
25
|
-
"eslint
|
|
26
|
-
"eslint-
|
|
21
|
+
"@commitlint/cli": "^20.5.0",
|
|
22
|
+
"@commitlint/config-angular": "^20.5.0",
|
|
23
|
+
"@eslint/eslintrc": "^3.3.5",
|
|
24
|
+
"@eslint/js": "^10.0.1",
|
|
25
|
+
"@vitest/coverage-v8": "^4.1.0",
|
|
26
|
+
"eslint": "^10.0.3",
|
|
27
|
+
"eslint-config-prettier": "^10.1.8",
|
|
28
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
27
29
|
"husky": "^9.1.7",
|
|
28
|
-
"prettier": "^3.4
|
|
29
|
-
"semantic-release": "^
|
|
30
|
-
"vitest": "^
|
|
30
|
+
"prettier": "^3.7.4",
|
|
31
|
+
"semantic-release": "^25.0.1-beta.1",
|
|
32
|
+
"vitest": "^4.1.0"
|
|
31
33
|
},
|
|
32
34
|
"scripts": {
|
|
33
35
|
"prepare": "husky",
|
package/.eslintrc
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["airbnb-base", "plugin:prettier/recommended"],
|
|
3
|
-
"settings": {
|
|
4
|
-
"import/resolver": {
|
|
5
|
-
"node": {
|
|
6
|
-
"paths": ["lib"],
|
|
7
|
-
"extensions": [".js", ".ts", ".d.ts", ".tsx"]
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
"parserOptions": {
|
|
12
|
-
"ecmaVersion": 2022
|
|
13
|
-
},
|
|
14
|
-
"rules": {
|
|
15
|
-
"arrow-body-style": 0,
|
|
16
|
-
"comma-dangle": 0,
|
|
17
|
-
"import/extensions": 0,
|
|
18
|
-
"import/prefer-default-export": 0,
|
|
19
|
-
"no-plusplus": 0,
|
|
20
|
-
"no-restricted-syntax": 0,
|
|
21
|
-
"no-use-before-define": 0
|
|
22
|
-
}
|
|
23
|
-
}
|