@@ -5,91 +5,77 @@ import fs from 'fs';
55import { ActionUtils } from './utils' ;
66
77export async function action ( ) {
8- try {
9- const NOTION_TOKEN_V2 = core . getInput ( 'token_v2' ) ;
10- const databaseId = core . getInput ( 'database_id' ) ;
8+ const NOTION_TOKEN_V2 = core . getInput ( 'token_v2' ) ;
9+ const databaseId = core . getInput ( 'database_id' ) ;
1110
12- const collectionView = await ActionUtils . fetchData < TCollectionBlock > (
13- databaseId ,
14- 'block'
15- ) ;
16- core . info ( 'Fetched database' ) ;
11+ const collectionView = await ActionUtils . fetchData < TCollectionBlock > (
12+ databaseId ,
13+ 'block'
14+ ) ;
15+ core . info ( 'Fetched database' ) ;
1716
18- const collection_id = collectionView . collection_id ;
19- const collection = await ActionUtils . fetchData < ICollection > (
20- collection_id ,
21- 'collection'
22- ) ;
17+ const collection_id = collectionView . collection_id ;
18+ const collection = await ActionUtils . fetchData < ICollection > (
19+ collection_id ,
20+ 'collection'
21+ ) ;
2322
24- core . info ( 'Fetched collection' ) ;
23+ core . info ( 'Fetched collection' ) ;
2524
26- const { recordMap } = await NotionEndpoints . Queries . queryCollection (
27- {
28- collectionId : collection_id ,
29- collectionViewId : '' ,
30- query : { } ,
31- loader : {
32- type : 'table' ,
33- loadContentCover : false ,
34- limit : 10000 ,
35- userTimeZone : ''
36- }
37- } ,
38- {
39- token : NOTION_TOKEN_V2 ,
40- user_id : ''
25+ const { recordMap } = await NotionEndpoints . Queries . queryCollection (
26+ {
27+ collectionId : collection_id ,
28+ collectionViewId : '' ,
29+ query : { } ,
30+ loader : {
31+ type : 'table' ,
32+ loadContentCover : false ,
33+ limit : 10000 ,
34+ userTimeZone : ''
4135 }
42- ) ;
43-
44- core . info ( 'Fetched rows' ) ;
45- const { schema } = collection ;
46- const [
47- category_schema_entry ,
48- color_schema_entry
49- ] = ActionUtils . getSchemaEntries ( schema ) ;
50-
51- const rows = ActionUtils . modifyRows ( recordMap , databaseId ) ;
36+ } ,
37+ {
38+ token : NOTION_TOKEN_V2 ,
39+ user_id : ''
40+ }
41+ ) ;
5242
53- if ( rows . length === 0 ) return core . error ( 'No database rows detected' ) ;
54- else {
55- const categories_map = ActionUtils . constructCategoriesMap (
56- category_schema_entry [ 1 ]
57- ) ;
58- rows . forEach ( ( row ) => {
59- const category = row . properties [ category_schema_entry [ 0 ] ] [ 0 ] [ 0 ] ;
60- if ( ! category ) throw new Error ( 'Each row must have a category value' ) ;
61- const category_value = categories_map . get ( category ) ;
62- category_value ! . items . push ( row . properties ) ;
63- } ) ;
43+ core . info ( 'Fetched rows' ) ;
44+ const { schema } = collection ;
45+ const [
46+ category_schema_entry ,
47+ color_schema_entry
48+ ] = ActionUtils . getSchemaEntries ( schema ) ;
6449
65- const README_PATH = `${ process . env . GITHUB_WORKSPACE } /README.md` ;
66- core . info ( `Reading from ${ README_PATH } ` ) ;
50+ const rows = ActionUtils . modifyRows ( recordMap , databaseId ) ;
51+ const categories_map = ActionUtils . constructCategoriesMap (
52+ category_schema_entry [ 1 ]
53+ ) ;
54+ ActionUtils . populateCategoriesMapItems (
55+ rows ,
56+ category_schema_entry [ 0 ] ,
57+ categories_map
58+ ) ;
6759
68- const readmeLines = fs . readFileSync ( README_PATH , 'utf-8' ) . split ( '\n' ) ;
60+ const README_PATH = `${ process . env . GITHUB_WORKSPACE } /README.md` ;
61+ core . info ( `Reading from ${ README_PATH } ` ) ;
6962
70- const [ startIdx , endIdx ] = ActionUtils . checkForSections ( readmeLines ) ;
71- const newLines = ActionUtils . constructNewContents (
72- categories_map ,
73- color_schema_entry [ 0 ]
74- ) ;
63+ const readmeLines = fs . readFileSync ( README_PATH , 'utf-8' ) . split ( '\n' ) ;
7564
76- const finalLines = [
77- ... readmeLines . slice ( 0 , startIdx + 1 ) ,
78- ... newLines ,
79- ... readmeLines . slice ( endIdx )
80- ] ;
65+ const [ startIdx , endIdx ] = ActionUtils . checkForSections ( readmeLines ) ;
66+ const newLines = ActionUtils . constructNewContents (
67+ categories_map ,
68+ color_schema_entry [ 0 ]
69+ ) ;
8170
82- core . info ( `Writing to ${ README_PATH } ` ) ;
71+ const finalLines = [
72+ ...readmeLines . slice ( 0 , startIdx + 1 ) ,
73+ ...newLines ,
74+ ...readmeLines . slice ( endIdx )
75+ ] ;
8376
84- fs . writeFileSync ( README_PATH , finalLines . join ( '\n' ) , 'utf-8' ) ;
77+ core . info ( `Writing to ${ README_PATH } ` ) ;
8578
86- try {
87- await ActionUtils . commitFile ( ) ;
88- } catch ( err ) {
89- core . setFailed ( err . message ) ;
90- }
91- }
92- } catch ( error ) {
93- core . setFailed ( error . message ) ;
94- }
79+ fs . writeFileSync ( README_PATH , finalLines . join ( '\n' ) , 'utf-8' ) ;
80+ await ActionUtils . commitFile ( ) ;
9581}
0 commit comments