@@ -20820,42 +20820,49 @@ const core = __nccwpck_require__(272)
2082020820const loadData = async ({ notion }) => {
2082120821 const systemDb = core.getInput('system_database')
2082220822 const ownerDb = core.getInput('owner_database')
20823- const database = core.getInput('database')
20823+ const serviceDb = core.getInput('database')
2082420824
20825- const processRows = (data) => {
20826- const parent = {}
20827- data.results.forEach((row) => {
20828- const name = row.properties.Name?.title[0]?.plain_text?.toLowerCase()
20829- if (name) parent[name] = row.id
20830- })
20831- return parent
20825+ const getDatabaseRows = async (databaseId, rowFunction, startCursor) => {
20826+ try {
20827+ const pageRows = await notion.databases.query({
20828+ database_id: databaseId,
20829+ start_cursor: startCursor
20830+ })
20831+ pageRows.results.forEach(rowFunction)
20832+ if (pageRows.has_more) {
20833+ return await getDatabaseRows(databaseId, rowFunction, pageRows.next_cursor)
20834+ }
20835+ } catch (ex) {
20836+ error = true
20837+ core.error(`Failed to retrieve data: ${ex.message}`)
20838+ }
2083220839 }
2083320840
2083420841 // Get core DB structure
2083520842 const dbStructure = await notion.databases.retrieve({
20836- database_id: database
20843+ database_id: serviceDb
2083720844 })
2083820845 const structure = Object.keys(dbStructure.properties).map((property) => {
2083920846 return { name: dbStructure.properties[property].name, type: dbStructure.properties[property].type }
2084020847 })
2084120848
2084220849 // Get the system and owner db
20843- let systemRows, ownerRows
20844-
20850+ const systems = {}
2084520851 if (systemDb) {
20846- systemRows = await notion.databases.query({
20847- database_id: systemDb
20852+ await getDatabaseRows(systemDb, (row) => {
20853+ const name = row.properties.Name?.title[0]?.plain_text?.toLowerCase()
20854+ if (name) systems[name] = row.id
2084820855 })
2084920856 }
2085020857
20858+ const owners = {}
2085120859 if (ownerDb) {
20852- ownerRows = await notion.databases.query({
20853- database_id: ownerDb
20860+ await getDatabaseRows(ownerDb, (row) => {
20861+ const name = row.properties.Name?.title[0]?.plain_text?.toLowerCase()
20862+ if (name) owners[name] = row.id
2085420863 })
2085520864 }
2085620865
20857- const systems = processRows(systemRows) || null
20858- const owners = processRows(ownerRows) || null
2085920866 let error = false
2086020867
2086120868 if (ownerDb && !owners.unknown) {
@@ -20869,22 +20876,12 @@ const loadData = async ({ notion }) => {
2086920876
2087020877 // Get the current service matrix and hashes in bulk to speed up updates
2087120878 const services = {}
20872- const getDatabaseRows = async (startCursor) => {
20873- const pageRows = await notion.databases.query({
20874- database_id: database,
20875- start_cursor: startCursor
20876- })
20877- pageRows.results.forEach((item) => {
20878- const pageId = item.id
20879- const pageHash = item.properties?.Hash?.rich_text[0]?.text?.content
20880- const pageName = item.properties?.Name?.title[0]?.text?.content
20881- services[pageName] = { pageId, pageHash }
20882- })
20883- if (pageRows.has_more) {
20884- return await getDatabaseRows(pageRows.next_cursor)
20885- }
20886- }
20887- await getDatabaseRows()
20879+ await getDatabaseRows(serviceDb, (item) => {
20880+ const pageId = item.id
20881+ const pageHash = item.properties?.Hash?.rich_text[0]?.text?.content
20882+ const pageName = item.properties?.Name?.title[0]?.text?.content
20883+ services[pageName] = { pageId, pageHash }
20884+ })
2088820885
2088920886 if (error) {
2089020887 process.exit(1)
0 commit comments