88 const GITHUB_TOKEN = core . getInput ( 'github_token' )
99 const database = core . getInput ( 'database' )
1010 const systemDb = core . getInput ( 'system_database' )
11- const segmentDb = core . getInput ( 'segment_database' )
12- const teamDb = core . getInput ( 'team_database' )
11+ const ownerDb = core . getInput ( 'owner_database' )
1312 const owner = core . getInput ( 'github_owner' )
1413 const catalogFile = core . getInput ( 'catalog_file' ) || 'catalog-info.yaml'
1514 const repositoryType = core . getInput ( 'repository_type' ) || 'all'
@@ -56,40 +55,23 @@ try {
5655 return repoData
5756 }
5857
59- const createProperties = ( repo , { systems, segments, teams } ) => {
60- let segment , team , system
61- const segmentAnnotation = repo ?. metadata ?. annotations ?. segment
62- const systemAnnotation = repo ?. metadata ?. annotations ?. system
63- const teamAnnotation = repo ?. metadata ?. annotations ?. team
58+ const createProperties = ( repo , { systems, owners } ) => {
59+ let owner , system
60+ const ownerSpec = repo ?. spec ?. owner
61+ const systemSpec = repo ?. spec ?. system
6462
65- if ( segments ) {
66- // Segments are a relation
67- segment = {
68- relation : [
69- { id : segments [ segmentAnnotation ?. toLowerCase ( ) ] || segments . unknown }
70- ]
71- }
72- } else {
73- // Segments are a tag
74- segment = {
75- select : {
76- name : segmentAnnotation || 'Unknown'
77- }
78- }
79- }
80-
81- if ( teams ) {
82- // Teams are a relation
83- team = {
63+ if ( owners ) {
64+ // Owners are a relation
65+ owner = {
8466 relation : [
85- { id : teams [ teamAnnotation ?. toLowerCase ( ) ] || teams . unknown }
67+ { id : owners [ ownerSpec ?. toLowerCase ( ) ] || owners . unknown }
8668 ]
8769 }
8870 } else {
89- // Teams are a tag
90- team = {
71+ // owners are a tag
72+ owner = {
9173 select : {
92- name : teamAnnotation || 'Unknown'
74+ name : ownerSpec || 'Unknown'
9375 }
9476 }
9577 }
@@ -98,14 +80,14 @@ try {
9880 // Segments are a relation
9981 system = {
10082 relation : [
101- { id : systems [ systemAnnotation ?. toLowerCase ( ) ] || systems . unknown }
83+ { id : systems [ systemSpec ?. toLowerCase ( ) ] || systems . unknown }
10284 ]
10385 }
10486 } else {
10587 // Segments are a tag
10688 system = {
10789 select : {
108- name : systemAnnotation || 'Unknown'
90+ name : systemSpec || 'Unknown'
10991 }
11092 }
11193 }
@@ -137,8 +119,7 @@ try {
137119 URL : {
138120 url : repo . _repo . html_url
139121 } ,
140- Segment : segment ,
141- Team : team ,
122+ Owner : owner ,
142123 System : system ,
143124 Visibility : {
144125 select : {
@@ -166,31 +147,31 @@ try {
166147 }
167148 }
168149
169- const updateNotionRow = async ( repo , pageId , { systems, segments , teams } ) => {
150+ const updateNotionRow = async ( repo , pageId , { systems, owners } ) => {
170151 try {
171152 await notion . pages . update ( {
172153 page_id : pageId ,
173- properties : createProperties ( repo , { systems, segments , teams } )
154+ properties : createProperties ( repo , { systems, owners } )
174155 } )
175156 } catch ( ex ) {
176157 core . error ( `Error updating notion document for ${ repo . _repo . name } : ${ ex . message } ...` )
177158 }
178159 }
179160
180- const createNotionRow = async ( repo , { systems, segments , teams } ) => {
161+ const createNotionRow = async ( repo , { systems, owners } ) => {
181162 try {
182163 await notion . pages . create ( {
183164 parent : {
184165 database_id : database
185166 } ,
186- properties : createProperties ( repo , { systems, segments , teams } )
167+ properties : createProperties ( repo , { systems, owners } )
187168 } )
188169 } catch ( ex ) {
189170 core . error ( `Error creating notion document for ${ repo . _repo . name } : ${ ex . message } ...` )
190171 }
191172 }
192173
193- const updateNotion = async ( repositories , { systems, segments , teams } ) => {
174+ const updateNotion = async ( repositories , { systems, owners } ) => {
194175 for ( const repo of repositories ) {
195176 // Lets see if we can find the row
196177 const search = await notion . databases . query ( {
@@ -208,9 +189,9 @@ try {
208189 // Lets just update the first one to not make the problem worse
209190 if ( search . results . length > 0 ) {
210191 const pageId = search . results [ 0 ] . id
211- await updateNotionRow ( repo , pageId , { systems, segments , teams } )
192+ await updateNotionRow ( repo , pageId , { systems, owners } )
212193 } else {
213- await createNotionRow ( repo , { systems, segments , teams } )
194+ await createNotionRow ( repo , { systems, owners } )
214195 }
215196 }
216197 }
@@ -225,38 +206,27 @@ try {
225206 return parent
226207 }
227208
228- let systemRows , segmentRows , teamRows
209+ let systemRows , ownerRows
229210
230211 if ( systemDb ) {
231212 systemRows = await notion . databases . query ( {
232213 database_id : systemDb
233214 } )
234215 }
235216
236- if ( segmentDb ) {
237- segmentRows = await notion . databases . query ( {
238- database_id : segmentDb
239- } )
240- }
241-
242- if ( teamDb ) {
243- teamRows = await notion . databases . query ( {
244- database_id : teamDb
217+ if ( ownerDb ) {
218+ ownerRows = await notion . databases . query ( {
219+ database_id : ownerDb
245220 } )
246221 }
247222
248- const systems = processRows ( systemRows ) || null
249- const teams = processRows ( teamRows ) || null
250- const segments = processRows ( segmentRows ) || null
223+ const systems = processRows ( systemRows ) || null
224+ const owners = processRows ( ownerRows ) || null
251225 let error = false
252226
253- if ( segmentDb && ! segments . unknown ) {
254- error = true
255- core . error ( 'Your segment table does not contain an "unknown" row!' )
256- }
257- if ( teamDb && ! teams . unknown ) {
227+ if ( ownerDb && ! owners . unknown ) {
258228 error = true
259- core . error ( 'Your team table does not contain an "unknown" row!' )
229+ core . error ( 'Your owner table does not contain an "unknown" row!' )
260230 }
261231 if ( systemDb && ! systems . unknown ) {
262232 error = true
@@ -269,23 +239,21 @@ try {
269239
270240 return {
271241 systems,
272- segments,
273- teams
242+ owners
274243 }
275244 }
276245
277246 const refreshData = async ( ) => {
278- core . startGroup ( 'Loading systems, segments and teams ' )
279- const { systems, segments , teams } = await loadData ( )
247+ core . startGroup ( 'Loading systems and owners ... ' )
248+ const { systems, owners } = await loadData ( )
280249 core . info ( `Loaded ${ Object . keys ( systems || { } ) . length } systems` )
281- core . info ( `Loaded ${ Object . keys ( segments || { } ) . length } segments` )
282- core . info ( `Loaded ${ Object . keys ( teams || { } ) . length } teams` )
250+ core . info ( `Loaded ${ Object . keys ( owners || { } ) . length } owners` )
283251 core . endGroup ( )
284252 core . startGroup ( '🌀 Getting github repositories' )
285253 const repositories = await getRepos ( )
286254 core . endGroup ( )
287255 core . startGroup ( `✨ Updating notion with ${ repositories . length } services ...` )
288- await updateNotion ( repositories , { systems, segments , teams } )
256+ await updateNotion ( repositories , { systems, owners } )
289257 core . endGroup ( )
290258 }
291259
0 commit comments