-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
42 lines (34 loc) · 1.33 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
const core = require('@actions/core');
const github = require('@actions/github');
const mustache = require('mustache');
async function run(){
try {
// requires GitHub Token to allow PR updates
const ghToken = core.getInput('token', {required: true})
// Get the JSON webhook payload for the event that triggered the workflow
const payload = JSON.stringify(github.context.payload, undefined, 2)
//core.info(`The event payload: ${payload}`);
// Show PR details
const pr = github.context.payload.pull_request;
core.info(`Pull request body: ${pr.body}`);
core.info(`Pull request title: ${pr.title}`);
// update PR body
const octokit = github.getOctokit(ghToken);
const request = {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: github.context.payload.pull_request.number,
body: mustache.render(pr.body, pr),
title: mustache.render(pr.title, pr),
}
core.info(`update request: ${request}`);
const response = await octokit.rest.pulls.update(request);
core.info(`Response: ${response.status}`);
if (response.status !== 200) {
core.error(`Updating the pull request has failed: ${response.text}`);
}
} catch (error) {
core.setFailed(error.message);
}
}
run();