Skip to content

Commit 709018b

Browse files
committed
Refactor and add additional fields from backstage file
1 parent 51efd1c commit 709018b

3 files changed

Lines changed: 74 additions & 94 deletions

File tree

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This action expects a Notion database with the following properties:
1414

1515
- Name: text
1616
- Description: text
17+
- Kind: select
1718
- URL: url
1819
- Segment: select
1920
- Team: select
@@ -49,6 +50,7 @@ jobs:
4950
notion_token: ${{ secrets.NOTION_TOKEN }}
5051
database: 2b26b4290cc84d95ad3e93c3255277a1
5152
repository_type: all
53+
catalog_file: catalog-info.yaml
5254

5355
```
5456

src/index.js

Lines changed: 71 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ try {
4141
})
4242
if (data) {
4343
const base64content = Buffer.from(data.content, 'base64')
44-
const serviceDefintion = YAML.parse(base64content.toString('utf8'))
45-
serviceDefintion._repo = repo
46-
serviceDefintion.status = 'OK'
47-
repoData.push(serviceDefintion)
44+
const serviceDefinition = YAML.parse(base64content.toString('utf8'))
45+
serviceDefinition._repo = repo
46+
serviceDefinition.status = 'OK'
47+
repoData.push(serviceDefinition)
4848
}
4949
} catch (ex) {
5050
repoData.push({
51-
segment: 'Unknown',
52-
team: 'Unknown',
5351
status: `${catalogFile} missing`,
5452
_repo: repo
5553
})
@@ -58,63 +56,75 @@ try {
5856
return repoData
5957
}
6058

61-
const updateNotionRow = async (repo, pageId) => {
62-
try {
63-
await notion.pages.update({
64-
page_id: pageId,
65-
properties: {
66-
Name: {
67-
title: [
68-
{
69-
text: {
70-
content: repo._repo.name
71-
}
72-
}
73-
]
74-
},
75-
Description: {
76-
rich_text: [
77-
{
78-
text: {
79-
content: repo._repo.description || repo._repo.name
80-
}
81-
}
82-
]
83-
},
84-
URL: {
85-
url: repo._repo.html_url
86-
},
87-
Segment: {
88-
select: {
89-
name: repo.segment
90-
}
91-
},
92-
Team: {
93-
select: {
94-
name: repo.team
95-
}
96-
},
97-
Visibility: {
98-
select: {
99-
name: repo._repo.visibility
100-
}
101-
},
102-
Language: {
103-
select: {
104-
name: repo._repo.language || 'Unknown'
105-
}
106-
},
107-
Status: {
108-
select: {
109-
name: repo.status
59+
const createProperties = (repo) => {
60+
return {
61+
Name: {
62+
title: [
63+
{
64+
text: {
65+
content: repo._repo.name
11066
}
111-
},
112-
Updated: {
113-
date: {
114-
start: new Date().toISOString()
67+
}
68+
]
69+
},
70+
Description: {
71+
rich_text: [
72+
{
73+
text: {
74+
content: repo.metadata?.description || repo._repo.description || repo._repo.name
11575
}
11676
}
77+
]
78+
},
79+
Kind: {
80+
select: {
81+
name: repo.kind || 'Unknown'
82+
}
83+
},
84+
URL: {
85+
url: repo._repo.html_url
86+
},
87+
Segment: {
88+
select: {
89+
name: repo?.metadata?.annotations?.segment || 'Unknown'
90+
}
91+
},
92+
Team: {
93+
select: {
94+
name: repo?.metadata?.annotations?.team || 'Unknown'
95+
}
96+
},
97+
Visibility: {
98+
select: {
99+
name: repo._repo.visibility
100+
}
101+
},
102+
Language: {
103+
select: {
104+
name: repo._repo.language || 'Unknown'
105+
}
106+
},
107+
Status: {
108+
select: {
109+
name: repo.status
110+
}
111+
},
112+
Tags: {
113+
multi_select: repo.metadata?.tags ? repo.metadata.tags.flatMap(tag => { return { name: tag } }) : []
114+
},
115+
Updated: {
116+
date: {
117+
start: new Date().toISOString()
117118
}
119+
}
120+
}
121+
}
122+
123+
const updateNotionRow = async (repo, pageId) => {
124+
try {
125+
await notion.pages.update({
126+
page_id: pageId,
127+
properties: createProperties(repo)
118128
})
119129
} catch(ex) {
120130
core.error(`Error updating notion document for ${repo._repo.name}: ${ex.message} ...`);
@@ -127,40 +137,7 @@ try {
127137
parent: {
128138
database_id: database
129139
},
130-
properties: {
131-
Name: {
132-
title: [
133-
{
134-
text: {
135-
content: repo._repo.name
136-
}
137-
}
138-
]
139-
},
140-
URL: {
141-
url: repo._repo.html_url
142-
},
143-
Segment: {
144-
select: {
145-
name: repo.segment
146-
}
147-
},
148-
Team: {
149-
select: {
150-
name: repo.team
151-
}
152-
},
153-
Status: {
154-
select: {
155-
name: repo.status
156-
}
157-
},
158-
Updated: {
159-
date: {
160-
start: new Date().toISOString()
161-
}
162-
}
163-
}
140+
properties: createProperties(repo)
164141
})
165142
} catch(ex) {
166143
core.error(`Error creating notion document for ${repo._repo.name}: ${ex.message} ...`);
@@ -199,6 +176,7 @@ try {
199176
core.startGroup(`✨ Updating notion with ${repositories.length} services ...`)
200177
updateNotion(repositories)
201178
core.endGroup()
179+
core.setFailed(error.message)
202180
}
203181

204182
refreshData()

src/local.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { spawn } = require('child_process')
22
const path = require('path')
33
const process = require('process')
44

5-
process.env.INPUT_DATABASE = 'cecaf0beb15945158d155866ff9acce8' //'2b26b4290cc84d95ad3e93c3255277a1'
5+
process.env.INPUT_DATABASE = '2b26b4290cc84d95ad3e93c3255277a1' //'cecaf0beb15945158d155866ff9acce8'
66
process.env.INPUT_NOTION_TOKEN = process.env.NOTION_TOKEN
77
process.env.INPUT_GITHUB_TOKEN = process.env.GITHUB_TOKEN
88
process.env.INPUT_REPOSITORY_TYPE = 'public'

0 commit comments

Comments
 (0)