-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathclose-tooling-repo-issues.js
57 lines (47 loc) · 1.82 KB
/
close-tooling-repo-issues.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const Promise = require('bluebird');
const YAML = require('js-yaml');
const { setGithubIssueState } = require('../repo');
const { logger } = require('../util');
module.exports = async (data) => {
logger(__filename, 'closeToolingRepoIssues');
const filename = __filename.split('/').pop();
if (
!process.env.GH_API_TOKEN
|| !process.env.GH_API_USERNAME
|| !process.env.TOOLING_REPOSITORY_OWNER
|| !process.env.TOOLING_REPOSITORY_REPO_NAME
) {
throw new Error(`GH_API_TOKEN, GH_API_USERNAME, TOOLING_REPOSITORY_OWNER or TOOLING_REPOSITORY_REPO_NAME not set in environment when executing ${filename}`);
}
const concurrency = parseInt(process.env.GH_API_CONCURRENCY_LIMIT);
if (!concurrency || Number.isNaN(concurrency)) {
throw new Error('Concurrency limit is not set correctly or is not a number');
}
logger(`Concurrency limit for this run is set to ${concurrency} in ${filename}`);
const outputData = await Promise.all(
Promise.map(
YAML.load(data),
async (tool) => {
if ((tool.sourceIssueMetadata || {}).status === 'open') {
try {
await setGithubIssueState(
process.env.GH_API_USERNAME,
process.env.GH_API_TOKEN,
tool.sourceIssueMetadata.issueNumber,
process.env.TOOLING_REPOSITORY_OWNER,
process.env.TOOLING_REPOSITORY_REPO_NAME,
);
tool.sourceIssueMetadata.status = 'closed'; // eslint-disable-line no-param-reassign
} catch (err) {
// If closing the issue fails save data as is to ensure it gets reprocessed
// Open issues that have already been processed will get mopped up on the next run
return tool;
}
}
return tool;
},
{ concurrency },
),
);
return YAML.dump(outputData);
};