Skip to content

Commit f19e7f6

Browse files
committed
Align more with Backstage to make more generic
1 parent 1c7aaa7 commit f19e7f6

4 files changed

Lines changed: 50 additions & 86 deletions

File tree

readme.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ This action expects a Notion database with the following properties, this will b
1616
- Description: text
1717
- Kind: select
1818
- URL: url
19-
- Segment: select
20-
- Team: select
19+
- Owner: select
20+
- System: select
2121
- Tags: multi_select
2222
- Visibility: select
2323
- Language: select
@@ -34,14 +34,14 @@ It looks like this after it has run:
3434

3535
You have an option to provide additional 'lookup' databases to convert some of the above selects into relations:
3636

37-
### Segment, Team, System
37+
### Owner, System
3838

3939
1. Create a database that has *at least* a `Name` column that is unique, all other columns are up to you.
4040
2. Create an 'Unknown' row - this is what services that cannot be mapped go to (this name matters).
41-
3. In the config of the action, provide the input variable `segment_database` pointing to this database.
42-
4. In the main service catalogue table convert the `Segment` column to a relation, pointing at the above database.
41+
3. In the config of the action, provide the input variable `owner_database` pointing to this database.
42+
4. In the main service catalogue table convert the `Owner` column to a relation, pointing at the above database.
4343

44-
This can be repeated for `Team` and `System`. The full config is below in the usage.
44+
This can be repeated for `System`. The full config is below in the usage.
4545

4646
## Service Descriptor Format
4747

@@ -70,8 +70,7 @@ jobs:
7070
github_token: ${{ secrets.PAT_GITHUB_TOKEN }}
7171
notion_token: ${{ secrets.NOTION_TOKEN }}
7272
database: 2b26b4290cc84d95ad3e93c3255277a1
73-
segment_database: 7943615f4dba43b3a3b0f991f4f7136d
74-
team_database: c11736fe61b941149de098676bde8d92
73+
owner_database: 7943615f4dba43b3a3b0f991f4f7136d
7574
system_database: 121534684fe840a1953500e603c2b602
7675
repository_type: all
7776
catalog_file: catalog-info.yaml

src/index.js

Lines changed: 35 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ try {
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

src/index.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ test('complete input should succeed with default inputs', () => {
1010
process.env.INPUT_GITHUB_TOKEN = process.env.GITHUB_TOKEN
1111
process.env.INPUT_REPOSITORY_TYPE = 'public'
1212
process.env.INPUT_GITHUB_OWNER = 'infinitaslearning'
13-
process.env.INPUT_SEGMENT_DATABASE = '7943615f4dba43b3a3b0f991f4f7136d'
14-
process.env.INPUT_TEAM_DATABASE = 'c11736fe61b941149de098676bde8d92'
13+
process.env.INPUT_OWNER_DATABASE = '7943615f4dba43b3a3b0f991f4f7136d'
1514
process.env.INPUT_SYSTEM_DATABASE = '121534684fe840a1953500e603c2b602'
1615

1716
const ip = path.join(__dirname, 'index.js')

src/local.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ process.env.INPUT_GITHUB_TOKEN = process.env.GITHUB_TOKEN
77
process.env.INPUT_REPOSITORY_TYPE = 'public'
88
process.env.INPUT_GITHUB_OWNER = 'infinitaslearning'
99

10-
// process.env.INPUT_DATABASE = 'cecaf0beb15945158d155866ff9acce8' // '2b26b4290cc84d95ad3e93c3255277a1'
11-
// process.env.INPUT_SEGMENT_DATABASE = '7943615f4dba43b3a3b0f991f4f7136d'
12-
// process.env.INPUT_TEAM_DATABASE = 'c11736fe61b941149de098676bde8d92'
13-
// process.env.INPUT_SYSTEM_DATABASE = '121534684fe840a1953500e603c2b602'
14-
15-
process.env.INPUT_DATABASE = '2b26b4290cc84d95ad3e93c3255277a1' // '2b26b4290cc84d95ad3e93c3255277a1'
16-
process.env.INPUT_SEGMENT_DATABASE = '3ee0d01944924634990b42b44253d370'
17-
process.env.INPUT_TEAM_DATABASE = '9baf04c267054f0294aeab25026ce74f'
18-
process.env.INPUT_SYSTEM_DATABASE = 'c721d8f0e6e34961ba037c67ad632585'
10+
process.env.INPUT_DATABASE = 'cecaf0beb15945158d155866ff9acce8' // '2b26b4290cc84d95ad3e93c3255277a1'
11+
process.env.INPUT_OWNER_DATABASE = '7943615f4dba43b3a3b0f991f4f7136d'
12+
process.env.INPUT_SYSTEM_DATABASE = '121534684fe840a1953500e603c2b602'
13+
14+
// process.env.INPUT_DATABASE = '2b26b4290cc84d95ad3e93c3255277a1' // '2b26b4290cc84d95ad3e93c3255277a1'
15+
// process.env.INPUT_OWNER_DATABASE = '3ee0d01944924634990b42b44253d370'
16+
// process.env.INPUT_SYSTEM_DATABASE = 'c721d8f0e6e34961ba037c67ad632585'
1917

2018
const ip = path.join(__dirname, 'index.js')
2119
const options = {

0 commit comments

Comments
 (0)