-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (38 loc) · 1.19 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
const core = require("@actions/core");
const github = require("@actions/github");
const fs = require("fs");
async function run() {
const content = core.getInput("content", { required: true });
const contentIsFilePath = core.getInput("contentIsFilePath");
const regex = core.getInput("regex") || "---.*";
const regexFlags = core.getInput("regexFlags") || "";
const token = core.getInput("token", { required: true });
const [repoOwner, repoName] = process.env.GITHUB_REPOSITORY.split("/");
const prNumber = github.context.payload.issue.number;
const octokit = github.getOctokit(token);
const { data } = await octokit.rest.pulls.get({
owner: repoOwner,
repo: repoName,
pull_number: prNumber,
});
body = data.body;
let output = content;
if (contentIsFilePath && contentIsFilePath === "true") {
output = fs.readFileSync(content).toString("utf-8");
}
const re = RegExp(regex, regexFlags);
if (body && body.match(re)) {
body = body.replace(re, output);
} else if (body) {
body += output;
} else {
body = output;
}
await octokit.rest.pulls.update({
owner: repoOwner,
repo: repoName,
body: body,
pull_number: prNumber,
});
}
run();