11import * as core from '@actions/core' ;
22import { NotionEndpoints } from '@nishans/endpoints' ;
3- import { ICollection , ICollectionBlock } from '@nishans/types' ;
3+ import { ICollection , TCollectionBlock } from '@nishans/types' ;
44import fs from 'fs' ;
55import { checkForSections } from './utils/checkForSections' ;
66import { commitFile } from './utils/commitFile' ;
77import { constructCategoriesMap } from './utils/constructCategoriesMap' ;
88import { constructNewContents } from './utils/constructNewContents' ;
9+ import { fetchData } from './utils/fetchData' ;
910import { getSchemaEntries } from './utils/getSchemaEntries' ;
1011import { modifyRows } from './utils/modifyRows' ;
1112
1213async function main ( ) {
1314 try {
14- const databaseId = core . getInput ( 'database_id' ) ;
1515 const NOTION_TOKEN_V2 = core . getInput ( 'token_v2' ) ;
16+ const databaseId = core . getInput ( 'database_id' ) ;
1617
17- const collectionViewData = await NotionEndpoints . Queries . syncRecordValues (
18- {
19- requests : [
20- {
21- id : databaseId ,
22- table : 'block' ,
23- version : - 1
24- }
25- ]
26- } ,
27- {
28- token : NOTION_TOKEN_V2 ,
29- user_id : ''
30- }
18+ const collectionView = await fetchData < TCollectionBlock > (
19+ databaseId ,
20+ 'block'
3121 ) ;
32-
3322 core . info ( 'Fetched database' ) ;
3423
35- const collectionView = collectionViewData . recordMap . block ! [ databaseId ]
36- . value as ICollectionBlock ;
37-
38- // If a database with the passed id doesn't exist
39- if ( ! collectionView ) {
40- return core . setFailed (
41- `Either your NOTION_TOKEN_V2 has expired or a database with id:${ databaseId } doesn't exist`
42- ) ;
43- }
44-
4524 const collection_id = collectionView . collection_id ;
46- const collectionData = await NotionEndpoints . Queries . syncRecordValues (
47- {
48- requests : [
49- {
50- id : collection_id ,
51- table : 'collection' ,
52- version : - 1
53- }
54- ]
55- } ,
56- {
57- token : NOTION_TOKEN_V2 ,
58- user_id : ''
59- }
25+ const collection = await fetchData < ICollection > (
26+ collection_id ,
27+ 'collection'
6028 ) ;
6129
6230 core . info ( 'Fetched collection' ) ;
@@ -80,9 +48,6 @@ async function main() {
8048 ) ;
8149
8250 core . info ( 'Fetched rows' ) ;
83-
84- const collection = collectionData . recordMap . collection ! [ collection_id ]
85- . value as ICollection ;
8651 const { schema } = collection ;
8752 const [ category_schema_entry , color_schema_entry ] = getSchemaEntries (
8853 schema
@@ -124,11 +89,11 @@ async function main() {
12489 try {
12590 await commitFile ( ) ;
12691 } catch ( err ) {
127- return core . setFailed ( err . message ) ;
92+ core . setFailed ( err . message ) ;
12893 }
12994 }
13095 } catch ( error ) {
131- return core . setFailed ( error . message ) ;
96+ core . setFailed ( error . message ) ;
13297 }
13398}
13499
0 commit comments