-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (60 loc) · 1.83 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const fs = require("fs");
const path = require("path");
const ejs = require("ejs");
const prettier = require("prettier");
const { getInput, setFailed } = require("@actions/core");
const { getOctokit } = require("@actions/github");
const { NarkdownClient } = require("@narkdown/client");
const { NotionParser } = require("@narkdown/notion-parser");
const { extractIdFromUrl } = require("@narkdown/notion-utils");
try {
const notionAPIKey = getInput("notion_api_token");
const databaseUrl = getInput("notion_database_url");
const fileName = getInput("file_name");
const templateName = getInput("template_name");
const token = getInput("gist_token");
const gistId = getInput("gist_id");
const propertyOptions = {
date: {
timeZone: getInput("date_option_timezone"),
format: getInput("date_option_format"),
},
};
const sortOptions = [
{
timestamp: getInput("sort_option_timestamp"),
direction: getInput("sort_option_direction"),
},
];
(async () => {
const narkdown = new NarkdownClient({ auth: notionAPIKey });
const notionParser = new NotionParser({ propertyOptions });
const { results } = await narkdown.unlimited.databases.query({
database_id: extractIdFromUrl(databaseUrl),
sorts: sortOptions,
});
const rows = notionParser.database.getRows(results);
const template = await fs.promises.readFile(
path.resolve(`./templates/${templateName}`),
"utf8"
);
const content = prettier.format(
ejs.render(template, { rows, databaseUrl }),
{
parser: "markdown",
}
);
const octokit = getOctokit(token);
await octokit.rest.gists.update({
gist_id: gistId,
files: {
[fileName]: {
fileName,
content: content,
},
},
});
})();
} catch (error) {
setFailed(error.message);
}