-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
51 lines (42 loc) · 1.32 KB
/
index.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
const helper = require('./helper.js');
const core = require('@actions/core');
const github = require('@actions/github');
const Redmine = require('node-redmine');
async function run() {
try {
const context = github.context;
const octokit = github.getOctokit(core.getInput('token'));
const hostname = core.getInput('redmine_host');
const config = {
apiKey: core.getInput('redmine_apikey')
};
if (config.apiKey == '') {
console.log("redmine apikey has not set. ignored");
process.eixtCode = 0;
return
}
const redmine = new Redmine(hostname, config);
const pr = await octokit.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
const redmine_issue_numbers = await helper.parse_redmine_issues(pr.data.body, hostname);
const message = await helper.build_message(pr.data, context)
const redmine_issue = {
"issue": {
"notes": message
}
};
redmine_issue_numbers.forEach(id => {
redmine.update_issue(id, redmine_issue, function(err, data) {
if (err) throw err;
console.log("update issue: " + JSON.stringify(redmine_issue));
});
});
} catch (error) {
console.error("error: " + error);
process.exitCode = 1;
}
}
run();