-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
58 lines (45 loc) · 1.55 KB
/
main.ts
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
52
53
54
55
56
57
58
/*
** This module is the action's main entry point.
*/
import * as core from "@actions/core";
import * as github from "@actions/github";
import * as path from "path";
import { Liquid } from "liquidjs";
export async function run()
{
try
{
// Gather and validate input:
const token = core.getInput("github-token");
const issueNumber = Number.parseInt(core.getInput("issue-number"));
const result = core.getInput("result");
const templatePath = core.getInput("template-path");
const octokit = github.getOctokit(token);
const liquid = new Liquid({
root: [
process.env.GITHUB_WORKSPACE, // Firstly look relative to workspace/repo
path.join(__dirname, "../templates") // Secondly look among built-in templates
]
});
core.debug(`Rendering template '${templatePath}'...`);
const json = JSON.parse(result);
const markdown = await liquid.renderFile(templatePath, json);
core.debug("Template rendered successfully.");
const repositoryParts = process.env.GITHUB_REPOSITORY.split("/");
const repositoryOwner = repositoryParts[0];
const repositoryName = repositoryParts[1];
core.debug(`Posting comment on issue ${issueNumber} in repository '${repositoryOwner}/${repositoryName}'...`);
await octokit.rest.issues.createComment({
owner: repositoryOwner,
repo: repositoryName,
issue_number: issueNumber,
body: markdown,
});
core.debug("Comment posted successfully.");
}
catch (error)
{
core.setFailed(error.message);
}
}
run();