@@ -3,41 +3,40 @@ const { Client } = require("@notionhq/client");
3
3
4
4
async function run ( ) {
5
5
try {
6
- const secretToken = core . getInput ( "notion_secret" ) ;
6
+ const secretToken = core . getInput ( "notion_secret" , { required : true } ) ;
7
7
8
8
const notion = new Client ( {
9
9
auth : secretToken ,
10
10
} ) ;
11
11
12
- const pageUpdateProperties = core . getInput ( "notion_page_update_body" ) ;
13
- console . log ( pageUpdateProperties ) ;
12
+ const pageUpdateProperties = core . getInput ( "notion_page_update_properties" , { required : true } ) ;
14
13
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 } ) ;
18
17
19
18
if ( pageId === "" ) {
20
19
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") ;
22
21
}
23
22
24
23
const databaseQueryResults = (
25
24
await await notion . databases . query ( {
26
25
database_id : databaseId ,
27
- filter : databaseQueryFilter ,
26
+ filter : JSON . parse ( databaseQueryFilter ) ,
28
27
} )
29
28
) . results ;
30
29
31
30
if ( databaseQueryResults . length === 0 ) {
32
- core . setFailed ( "page doesn't exist" ) ;
33
- }
31
+ throw new Error ( "Could not find pages with filter: " + databaseQueryFilter ) ;
32
+ }
34
33
35
34
pageId = databaseQueryResults [ 0 ] . id ;
36
35
}
37
36
38
37
await notion . pages . update ( {
39
38
page_id : pageId ,
40
- properties : pageUpdateProperties ,
39
+ properties : JSON . parse ( pageUpdateProperties ) ,
41
40
} ) ;
42
41
} catch ( error ) {
43
42
core . setFailed ( error . message ) ;
0 commit comments