@@ -27185,11 +27185,12 @@ try {
2718527185 const GITHUB_TOKEN = core.getInput('github_token')
2718627186 const database = core.getInput('database')
2718727187 const systemDb = core.getInput('system_database')
27188- const segmentDb = core.getInput('segment_database')
27189- const teamDb = core.getInput('team_database')
27188+ const ownerDb = core.getInput('owner_database')
2719027189 const owner = core.getInput('github_owner')
2719127190 const catalogFile = core.getInput('catalog_file') || 'catalog-info.yaml'
2719227191 const repositoryType = core.getInput('repository_type') || 'all'
27192+ const repositoryFilter = core.getInput('repository_filter') || '.*'
27193+ const repositoryFilterRegex = new RegExp(repositoryFilter)
2719327194
2719427195 core.debug('Creating notion client ...')
2719527196 const notion = new Client({
@@ -27207,66 +27208,53 @@ try {
2720727208 sort: 'full_name',
2720827209 per_page: 100
2720927210 })
27210- core.info(`Found ${repos.length} github repositories, now getting service data ...`)
27211+ core.info(`Using repository filter: ${repositoryFilter}`)
27212+ core.info(`Found ${repos.length} github repositories, now getting service data for those that match the filter ...`)
2721127213 const repoData = []
2721227214 for (const repo of repos) {
27213- try {
27214- const { data } = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
27215- owner: repo.full_name.split('/')[0],
27216- repo: repo.name,
27217- path: catalogFile
27218- })
27219- if (data) {
27220- const base64content = Buffer.from(data.content, 'base64')
27221- const serviceDefinition = YAML.parse(base64content.toString('utf8'))
27222- serviceDefinition._repo = repo
27223- serviceDefinition.status = 'OK'
27224- repoData.push(serviceDefinition)
27215+ if (repo.name.match(repositoryFilterRegex)) {
27216+ try {
27217+ const { data } = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
27218+ owner: repo.full_name.split('/')[0],
27219+ repo: repo.name,
27220+ path: catalogFile
27221+ })
27222+ if (data) {
27223+ const base64content = Buffer.from(data.content, 'base64')
27224+ const serviceDefinition = YAML.parse(base64content.toString('utf8'))
27225+ serviceDefinition._repo = repo
27226+ serviceDefinition.status = 'OK'
27227+ repoData.push(serviceDefinition)
27228+ }
27229+ } catch (ex) {
27230+ repoData.push({
27231+ status: `${catalogFile} missing`,
27232+ _repo: repo
27233+ })
2722527234 }
27226- } catch (ex) {
27227- repoData.push({
27228- status: `${catalogFile} missing`,
27229- _repo: repo
27230- })
2723127235 }
2723227236 }
27237+ core.info(`Processed ${repoData.length} matching repositories`)
2723327238 return repoData
2723427239 }
2723527240
27236- const createProperties = (repo, { systems, segments, teams }) => {
27237- let segment, team, system
27238- const segmentAnnotation = repo?.metadata?.annotations?.segment
27239- const systemAnnotation = repo?.metadata?.annotations?.system
27240- const teamAnnotation = repo?.metadata?.annotations?.team
27241+ const createProperties = (repo, { systems, owners }) => {
27242+ let owner, system
27243+ const ownerSpec = repo?.spec?.owner
27244+ const systemSpec = repo?.spec?.system
2724127245
27242- if (segments ) {
27243- // Segments are a relation
27244- segment = {
27246+ if (owners ) {
27247+ // Owners are a relation
27248+ owner = {
2724527249 relation: [
27246- { id: segments[segmentAnnotation ?.toLowerCase()] || segments .unknown }
27250+ { id: owners[ownerSpec ?.toLowerCase()] || owners .unknown }
2724727251 ]
2724827252 }
2724927253 } else {
27250- // Segments are a tag
27251- segment = {
27254+ // owners are a tag
27255+ owner = {
2725227256 select: {
27253- name: segmentAnnotation || 'Unknown'
27254- }
27255- }
27256- }
27257-
27258- if (teams) {
27259- // Teams are a relation
27260- team = {
27261- relation: [
27262- { id: teams[teamAnnotation?.toLowerCase()] || teams.unknown }
27263- ]
27264- }
27265- } else {
27266- // Teams are a tag
27267- team = {
27268- select: {
27269- name: teamAnnotation || 'Unknown'
27257+ name: ownerSpec || 'Unknown'
2727027258 }
2727127259 }
2727227260 }
@@ -27275,14 +27263,14 @@ try {
2727527263 // Segments are a relation
2727627264 system = {
2727727265 relation: [
27278- { id: systems[systemAnnotation ?.toLowerCase()] || systems.unknown }
27266+ { id: systems[systemSpec ?.toLowerCase()] || systems.unknown }
2727927267 ]
2728027268 }
2728127269 } else {
2728227270 // Segments are a tag
2728327271 system = {
2728427272 select: {
27285- name: systemAnnotation || 'Unknown'
27273+ name: systemSpec || 'Unknown'
2728627274 }
2728727275 }
2728827276 }
@@ -27314,8 +27302,7 @@ try {
2731427302 URL: {
2731527303 url: repo._repo.html_url
2731627304 },
27317- Segment: segment,
27318- Team: team,
27305+ Owner: owner,
2731927306 System: system,
2732027307 Visibility: {
2732127308 select: {
@@ -27343,31 +27330,31 @@ try {
2734327330 }
2734427331 }
2734527332
27346- const updateNotionRow = async (repo, pageId, { systems, segments, teams }) => {
27333+ const updateNotionRow = async (repo, pageId, { systems, owners }) => {
2734727334 try {
2734827335 await notion.pages.update({
2734927336 page_id: pageId,
27350- properties: createProperties(repo, { systems, segments, teams })
27337+ properties: createProperties(repo, { systems, owners })
2735127338 })
2735227339 } catch (ex) {
2735327340 core.error(`Error updating notion document for ${repo._repo.name}: ${ex.message} ...`)
2735427341 }
2735527342 }
2735627343
27357- const createNotionRow = async (repo, { systems, segments, teams }) => {
27344+ const createNotionRow = async (repo, { systems, owners }) => {
2735827345 try {
2735927346 await notion.pages.create({
2736027347 parent: {
2736127348 database_id: database
2736227349 },
27363- properties: createProperties(repo, { systems, segments, teams })
27350+ properties: createProperties(repo, { systems, owners })
2736427351 })
2736527352 } catch (ex) {
2736627353 core.error(`Error creating notion document for ${repo._repo.name}: ${ex.message} ...`)
2736727354 }
2736827355 }
2736927356
27370- const updateNotion = async (repositories, { systems, segments, teams }) => {
27357+ const updateNotion = async (repositories, { systems, owners }) => {
2737127358 for (const repo of repositories) {
2737227359 // Lets see if we can find the row
2737327360 const search = await notion.databases.query({
@@ -27385,9 +27372,9 @@ try {
2738527372 // Lets just update the first one to not make the problem worse
2738627373 if (search.results.length > 0) {
2738727374 const pageId = search.results[0].id
27388- await updateNotionRow(repo, pageId, { systems, segments, teams })
27375+ await updateNotionRow(repo, pageId, { systems, owners })
2738927376 } else {
27390- await createNotionRow(repo, { systems, segments, teams })
27377+ await createNotionRow(repo, { systems, owners })
2739127378 }
2739227379 }
2739327380 }
@@ -27402,38 +27389,27 @@ try {
2740227389 return parent
2740327390 }
2740427391
27405- let systemRows, segmentRows, teamRows
27392+ let systemRows, ownerRows
2740627393
2740727394 if (systemDb) {
2740827395 systemRows = await notion.databases.query({
2740927396 database_id: systemDb
2741027397 })
2741127398 }
2741227399
27413- if (segmentDb) {
27414- segmentRows = await notion.databases.query({
27415- database_id: segmentDb
27416- })
27417- }
27418-
27419- if (teamDb) {
27420- teamRows = await notion.databases.query({
27421- database_id: teamDb
27400+ if (ownerDb) {
27401+ ownerRows = await notion.databases.query({
27402+ database_id: ownerDb
2742227403 })
2742327404 }
2742427405
2742527406 const systems = processRows(systemRows) || null
27426- const teams = processRows(teamRows) || null
27427- const segments = processRows(segmentRows) || null
27407+ const owners = processRows(ownerRows) || null
2742827408 let error = false
2742927409
27430- if (segmentDb && !segments.unknown) {
27431- error = true
27432- core.error('Your segment table does not contain an "unknown" row!')
27433- }
27434- if (teamDb && !teams.unknown) {
27410+ if (ownerDb && !owners.unknown) {
2743527411 error = true
27436- core.error('Your team table does not contain an "unknown" row!')
27412+ core.error('Your owner table does not contain an "unknown" row!')
2743727413 }
2743827414 if (systemDb && !systems.unknown) {
2743927415 error = true
@@ -27446,23 +27422,21 @@ try {
2744627422
2744727423 return {
2744827424 systems,
27449- segments,
27450- teams
27425+ owners
2745127426 }
2745227427 }
2745327428
2745427429 const refreshData = async () => {
27455- core.startGroup('Loading systems, segments and teams ')
27456- const { systems, segments, teams } = await loadData()
27430+ core.startGroup('Loading systems and owners ... ')
27431+ const { systems, owners } = await loadData()
2745727432 core.info(`Loaded ${Object.keys(systems || {}).length} systems`)
27458- core.info(`Loaded ${Object.keys(segments || {}).length} segments`)
27459- core.info(`Loaded ${Object.keys(teams || {}).length} teams`)
27433+ core.info(`Loaded ${Object.keys(owners || {}).length} owners`)
2746027434 core.endGroup()
2746127435 core.startGroup('🌀 Getting github repositories')
2746227436 const repositories = await getRepos()
2746327437 core.endGroup()
2746427438 core.startGroup(`✨ Updating notion with ${repositories.length} services ...`)
27465- await updateNotion(repositories, { systems, segments, teams })
27439+ await updateNotion(repositories, { systems, owners })
2746627440 core.endGroup()
2746727441 }
2746827442
0 commit comments