forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoChangelog.js
42 lines (34 loc) · 1.2 KB
/
autoChangelog.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
import { parseChangelog } from "./changelogParser.js";
const safeYml = (string) =>
string.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n");
export function changelogToYml(changelog, login) {
const author = changelog.author || login;
const ymlLines = [];
ymlLines.push(`author: "${safeYml(author)}"`);
ymlLines.push(`delete-after: True`);
ymlLines.push(`changes:`);
for (const change of changelog.changes) {
ymlLines.push(
` - ${change.type.changelogKey}: "${safeYml(change.description)}"`
);
}
return ymlLines.join("\n");
}
export async function processAutoChangelog({ github, context }) {
const changelog = parseChangelog(context.payload.pull_request.body);
if (!changelog || changelog.changes.length === 0) {
console.log("no changelog found");
return;
}
const yml = changelogToYml(
changelog,
context.payload.pull_request.user.login
);
github.rest.repos.createOrUpdateFileContents({
owner: context.repo.owner,
repo: context.repo.repo,
path: `html/changelogs/AutoChangeLog-pr-${context.payload.pull_request.number}.yml`,
message: `Automatic changelog for PR #${context.payload.pull_request.number} [ci skip]`,
content: Buffer.from(yml).toString("base64"),
});
}