@@ -20453,9 +20453,57 @@ const getRepos = async () => {
2045320453 const owner = core.getInput('github_owner')
2045420454 const catalogFile = core.getInput('catalog_file') || 'catalog-info.yaml'
2045520455 const repositoryFilterRegex = new RegExp(repositoryFilter)
20456-
2045720456 const octokit = new Octokit({ auth: GITHUB_TOKEN })
2045820457
20458+ const parseServiceDefinition = async (repo, path, pushMissing) => {
20459+ const repoData = []
20460+ core.debug(`Processing ${path} ...`)
20461+ try {
20462+ const { data } = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
20463+ owner: repo.full_name.split('/')[0],
20464+ repo: repo.name,
20465+ path
20466+ })
20467+ if (data) {
20468+ const base64content = Buffer.from(data.content, 'base64')
20469+ const serviceDefinition = YAML.parse(base64content.toString('utf8'))
20470+ if (serviceDefinition.kind?.toLowerCase() === 'location') {
20471+ repoData.push(...await parseLocationFile(serviceDefinition, repo, path))
20472+ } else {
20473+ serviceDefinition._catalog_file = data.html_url
20474+ serviceDefinition._repo = repo
20475+ serviceDefinition.status = 'OK'
20476+ repoData.push(serviceDefinition)
20477+ }
20478+ }
20479+ } catch (ex) {
20480+ if (pushMissing) {
20481+ repoData.push({
20482+ status: `${catalogFile} missing`,
20483+ _repo: repo
20484+ })
20485+ } else {
20486+ core.warning(`Unable to find ${path} in ${repo.name}, not processing`)
20487+ }
20488+ }
20489+ return repoData
20490+ }
20491+
20492+ const parseLocationFile = async (serviceDefinition, repo, path) => {
20493+ const repoData = []
20494+ const targets = serviceDefinition.spec?.targets
20495+ if (targets && targets.length > 0) {
20496+ for (const target of targets) {
20497+ const pushMissing = false
20498+ const targetDefinition = await parseServiceDefinition(repo, target, pushMissing)
20499+ repoData.push(...targetDefinition)
20500+ }
20501+ } else {
20502+ core.warning(`Location file in ${repo._repo.name} at ${path} specified without valid spec.targets, will be skipped`)
20503+ }
20504+ return repoData
20505+ }
20506+
2045920507 const repos = await octokit.paginate('GET /orgs/{owner}/repos',
2046020508 {
2046120509 owner: owner,
@@ -20468,25 +20516,8 @@ const getRepos = async () => {
2046820516 const repoData = []
2046920517 for (const repo of repos) {
2047020518 if (repo.name.match(repositoryFilterRegex)) {
20471- try {
20472- const { data } = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
20473- owner: repo.full_name.split('/')[0],
20474- repo: repo.name,
20475- path: catalogFile
20476- })
20477- if (data) {
20478- const base64content = Buffer.from(data.content, 'base64')
20479- const serviceDefinition = YAML.parse(base64content.toString('utf8'))
20480- serviceDefinition._repo = repo
20481- serviceDefinition.status = 'OK'
20482- repoData.push(serviceDefinition)
20483- }
20484- } catch (ex) {
20485- repoData.push({
20486- status: `${catalogFile} missing`,
20487- _repo: repo
20488- })
20489- }
20519+ const pushMissing = true
20520+ repoData.push(...await parseServiceDefinition(repo, catalogFile, pushMissing))
2049020521 }
2049120522 }
2049220523
@@ -20625,12 +20656,13 @@ const { getDependsOn } = __nccwpck_require__(4154)
2062520656const updateServices = async (repositories, { notion, database, systems, owners }) => {
2062620657 for (const repo of repositories) {
2062720658 // Lets see if we can find the row
20659+ const repoName = repo.metadata?.name || repo._repo.name
2062820660 const search = await notion.databases.query({
2062920661 database_id: database,
2063020662 filter: {
2063120663 property: 'Name',
2063220664 text: {
20633- equals: repo._repo.name
20665+ equals: repoName
2063420666 }
2063520667 }
2063620668 })
@@ -20640,8 +20672,10 @@ const updateServices = async (repositories, { notion, database, systems, owners
2064020672 // Lets just update the first one to not make the problem worse
2064120673 if (search.results.length > 0) {
2064220674 const pageId = search.results[0].id
20675+ core.debug(`Updating notion info for ${repoName}`)
2064320676 await updateNotionRow(repo, pageId, { notion, database, systems, owners })
2064420677 } else {
20678+ core.debug(`Creating notion info for ${repoName}`)
2064520679 await createNotionRow(repo, { notion, database, systems, owners })
2064620680 }
2064720681 }
@@ -20661,7 +20695,7 @@ const updateNotionRow = async (repo, pageId, { notion, database, systems, owners
2066120695 await ensureLinks(pageId, repo.metadata.links, { notion })
2066220696 }
2066320697 } catch (ex) {
20664- core.error (`Error updating notion document for ${repo._repo.name}: ${ex.message} ...`)
20698+ core.warning (`Error updating notion document for ${repo._repo.name}: ${ex.message} ...`)
2066520699 }
2066620700}
2066720701
@@ -20681,7 +20715,7 @@ const createNotionRow = async (repo, { notion, database, systems, owners }) => {
2068120715 await ensureLinks(page.id, repo.metadata.links, { notion })
2068220716 }
2068320717 } catch (ex) {
20684- core.error (`Error creating notion document for ${repo._repo.name}: ${ex.message} ... `)
20718+ core.warning (`Error creating notion document for ${repo._repo.name}: ${ex.message}`)
2068520719 }
2068620720}
2068720721
@@ -20722,12 +20756,15 @@ const createProperties = (repo, dependsOn, { systems, owners }) => {
2072220756 }
2072320757 }
2072420758
20759+ // We can use the catalog file location to locate the right path within the repo
20760+ const htmlUrl = repo._catalog_file ? repo._catalog_file.substring(0, repo._catalog_file.lastIndexOf('/')) : repo._repo.html_url
20761+
2072520762 return {
2072620763 Name: {
2072720764 title: [
2072820765 {
2072920766 text: {
20730- content: repo._repo.name
20767+ content: repo.metadata?.name || repo. _repo.name
2073120768 }
2073220769 }
2073320770 ]
@@ -20747,7 +20784,7 @@ const createProperties = (repo, dependsOn, { systems, owners }) => {
2074720784 }
2074820785 },
2074920786 URL: {
20750- url: repo._repo.html_url
20787+ url: htmlUrl
2075120788 },
2075220789 Owner: owner,
2075320790 System: system,
0 commit comments