Skip to content

Commit 4b4167c

Browse files
authored
fix: input json handling (#10)
1 parent 5a44bdd commit 4b4167c

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

dist/index.js

Lines changed: 10 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,40 @@ const { Client } = require("@notionhq/client");
33

44
async function run() {
55
try {
6-
const secretToken = core.getInput("notion_secret");
6+
const secretToken = core.getInput("notion_secret", { required: true });
77

88
const notion = new Client({
99
auth: secretToken,
1010
});
1111

12-
const pageUpdateProperties = core.getInput("notion_page_update_body");
13-
console.log(pageUpdateProperties);
12+
const pageUpdateProperties = core.getInput("notion_page_update_properties", { required: true });
1413

15-
let pageId = core.getInput("notion_page_id");
16-
const databaseId = core.getInput("notion_database_id");
17-
const databaseQueryFilter = core.getInput("notion_database_query_filter");
14+
let pageId = core.getInput("notion_page_id", { required: false });
15+
const databaseId = core.getInput("notion_database_id", { required: false });
16+
const databaseQueryFilter = core.getInput("notion_database_query_filter", { required: false });
1817

1918
if (pageId === "") {
2019
if (databaseId === "" || databaseQueryFilter === "") {
21-
core.setFailed("either pageId or (databaseId and databaseQueryFilter) must be provided");
20+
throw new Error("Either a page ID or a database ID and query filter must be provided");
2221
}
2322

2423
const databaseQueryResults = (
2524
await await notion.databases.query({
2625
database_id: databaseId,
27-
filter: databaseQueryFilter,
26+
filter: JSON.parse(databaseQueryFilter),
2827
})
2928
).results;
3029

3130
if (databaseQueryResults.length === 0) {
32-
core.setFailed("page doesn't exist");
33-
}
31+
throw new Error("Could not find pages with filter: " + databaseQueryFilter);
32+
}
3433

3534
pageId = databaseQueryResults[0].id;
3635
}
3736

3837
await notion.pages.update({
3938
page_id: pageId,
40-
properties: pageUpdateProperties,
39+
properties: JSON.parse(pageUpdateProperties),
4140
});
4241
} catch (error) {
4342
core.setFailed(error.message);

0 commit comments

Comments
 (0)