@@ -21072,22 +21072,32 @@ exports.getRepos = getRepos
2107221072
2107321073const core = __nccwpck_require__(272)
2107421074
21075- const updateNotionLink = async (linkId, link, { notion }) => {
21075+ const processRows = (data) => {
21076+ const parent = {}
21077+ data.results.forEach((row) => {
21078+ const name = row.properties.Name.title[0].plain_text.toLowerCase()
21079+ const url = row.properties.URL.url
21080+ if (name) parent[name] = { id: row.id, url }
21081+ })
21082+ return parent
21083+ }
21084+
21085+ const updateNotionLink = async (linkId, link, linkUrl, { notion }) => {
2107621086 try {
2107721087 await notion.pages.update({
2107821088 page_id: linkId,
2107921089 properties: {
2108021090 URL: {
21081- url: link.url
21091+ url: linkUrl
2108221092 }
2108321093 }
2108421094 })
2108521095 } catch (ex) {
21086- core.error(`Error updating notion link for ${link.title }: ${ex.message} ...`)
21096+ core.error(`Error updating notion link for ${link}: ${ex.message} ...`)
2108721097 }
2108821098}
2108921099
21090- const createNotionLink = async (linkDatabaseId, link, { notion }) => {
21100+ const createNotionLink = async (linkDatabaseId, link, linkUrl, { notion }) => {
2109121101 try {
2109221102 await notion.pages.create({
2109321103 parent: {
@@ -21098,13 +21108,13 @@ const createNotionLink = async (linkDatabaseId, link, { notion }) => {
2109821108 title: [
2109921109 {
2110021110 text: {
21101- content: link.title
21111+ content: link
2110221112 }
2110321113 }
2110421114 ]
2110521115 },
2110621116 URL: {
21107- url: link.url
21117+ url: linkUrl
2110821118 }
2110921119 }
2111021120 })
@@ -21114,22 +21124,23 @@ const createNotionLink = async (linkDatabaseId, link, { notion }) => {
2111421124}
2111521125
2111621126const updateLinks = async (linkDatabaseId, links, { notion }) => {
21117- for (const link of links) {
21127+ // First get all of the existing rows in one go
21128+ const existingLinkRows = await notion.databases.query({
21129+ database_id: linkDatabaseId
21130+ })
21131+ const existingLinks = processRows(existingLinkRows)
21132+ // Now scan for any that have changed or are new
21133+ const linkKeys = Object.keys(links)
21134+ for (const link of linkKeys) {
2111821135 // Lets see if we can find the row
21119- const search = await notion.databases.query({
21120- database_id: linkDatabaseId,
21121- filter: {
21122- property: 'Name',
21123- text: {
21124- equals: link.title
21125- }
21136+ if (existingLinks[link]) {
21137+ const linkId = existingLinks[link].id
21138+ const linkUrl = existingLinks[link].url
21139+ if (links[link] !== linkUrl) { // url has changed
21140+ await updateNotionLink(linkId, link, links[link], { notion })
2112621141 }
21127- })
21128- if (search.results.length > 0) {
21129- const linkId = search.results[0].id
21130- await updateNotionLink(linkId, link, { notion })
2113121142 } else {
21132- await createNotionLink(linkDatabaseId, link, { notion })
21143+ await createNotionLink(linkDatabaseId, link, links[link], { notion })
2113321144 }
2113421145 }
2113521146}
@@ -21350,14 +21361,14 @@ const updateNotionRow = async (repo, pageId, pageHash, { notion, database, syste
2135021361 page_id: pageId,
2135121362 properties
2135221363 })
21364+ if (repo.metadata?.links) {
21365+ await ensureLinks(pageId, repo.metadata.links, { notion })
21366+ }
2135321367 updatedServices++
2135421368 } else {
2135521369 core.debug(`Not updating notion info for ${repo._repo.name} as hash unchanged`)
2135621370 skippedServices++
2135721371 }
21358- if (repo.metadata?.links) {
21359- await ensureLinks(pageId, repo.metadata.links, { notion })
21360- }
2136121372 } catch (ex) {
2136221373 erroredServices++
2136321374 core.warning(`Error updating notion document for ${repo._repo.name}: ${ex.message} ...`)
@@ -21396,8 +21407,9 @@ const createProperties = (repo, pageHash, dependsOn, { systems, owners, structur
2139621407 properties[field.name] = mappingFn[field.name](repo, { dependsOn, systems, owners })
2139721408 }
2139821409 }
21399- // Always have to check the hash afterwards, excluding the hash and the key
21400- const newPageHash = hash(properties, {
21410+
21411+ // Always have to check the hash afterwards, excluding the hash and the key but including links
21412+ const newPageHash = hash({ links: repo.metadata.links, ...properties }, {
2140121413 excludeKeys: (key) => {
2140221414 return key === 'Hash' || key === 'Updated'
2140321415 }
0 commit comments