generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.js
40 lines (31 loc) · 1.25 KB
/
action.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
const core = require('@actions/core');
const github = require('@actions/github');
const issues = require('./issues');
const milestones = require('./milestones');
const octokit = require('./octokit');
const setTimeout = require('node:timers/promises').setTimeout;
async function run() {
try {
const body = core.getInput('body', { required: true });
const milestone = parseInt(core.getInput('milestone'));
const state = core.getInput('state');
const token = core.getInput('token');
const client = await octokit(token);
const repo = github.context.repo;
const milestoneIssues = await milestones.listIssues(client, repo.owner, repo.repo, milestone, state);
await Promise.all(milestoneIssues.map(async issue => {
await issues.createComment(client, repo.owner, repo.repo, issue.number, body);
core.debug(`Waiting 2 seconds between requests: https://docs.github.com/en/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limits`);
await setTimeout(2000);
}));
const outputs = {
ids: milestoneIssues.map(issue => issue.number).join(','),
};
core.setOutput('ids', outputs.ids);
return outputs;
} catch (err) {
core.setFailed(err.message);
throw err;
}
}
module.exports = run;