Skip to content

Commit ffcdd62

Browse files
committed
Refactor out into separate files, add support for links
1 parent ca6d096 commit ffcdd62

8 files changed

Lines changed: 756 additions & 485 deletions

File tree

dist/index.js

Lines changed: 388 additions & 241 deletions
Large diffs are not rendered by default.

readme.md

Lines changed: 7 additions & 2 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-
- Owner: select
20-
- System: select
19+
- Owner: select|relation
20+
- System: select|relation
2121
- Tags: multi_select
2222
- Visibility: select
2323
- Language: select
@@ -30,6 +30,11 @@ It looks like this after it has run:
3030

3131
<img width="1451" alt="Screenshot 2021-12-19 at 12 55 39" src="https://user-images.githubusercontent.com/239305/146673989-01187d53-d2fd-42ba-9968-31442b8cc92d.png">
3232

33+
34+
### Embedded Data
35+
36+
If your descriptor file contains links, these are added to an embedded database within the service page called `Links`.
37+
3338
## Relation Databases
3439

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

src/data.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const core = require('@actions/core')
2+
3+
const loadData = async ({ notion }) => {
4+
const systemDb = core.getInput('system_database')
5+
const ownerDb = core.getInput('owner_database')
6+
7+
const processRows = (data) => {
8+
const parent = {}
9+
data.results.forEach((row) => {
10+
const name = row.properties.Name.title[0].plain_text.toLowerCase()
11+
if (name) parent[name] = row.id
12+
})
13+
return parent
14+
}
15+
16+
let systemRows, ownerRows
17+
18+
if (systemDb) {
19+
systemRows = await notion.databases.query({
20+
database_id: systemDb
21+
})
22+
}
23+
24+
if (ownerDb) {
25+
ownerRows = await notion.databases.query({
26+
database_id: ownerDb
27+
})
28+
}
29+
30+
const systems = processRows(systemRows) || null
31+
const owners = processRows(ownerRows) || null
32+
let error = false
33+
34+
if (ownerDb && !owners.unknown) {
35+
error = true
36+
core.error('Your owner table does not contain an "unknown" row!')
37+
}
38+
if (systemDb && !systems.unknown) {
39+
error = true
40+
core.error('Your system table does not contain an "unknown" row!')
41+
}
42+
43+
if (error) {
44+
process.exit(1)
45+
}
46+
47+
return {
48+
systems,
49+
owners
50+
}
51+
}
52+
53+
exports.loadData = loadData

src/github.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const { Octokit } = require('octokit')
2+
const YAML = require('yaml')
3+
const core = require('@actions/core')
4+
5+
const getRepos = async () => {
6+
const GITHUB_TOKEN = core.getInput('github_token')
7+
const repositoryType = core.getInput('repository_type') || 'all'
8+
const repositoryFilter = core.getInput('repository_filter') || '.*'
9+
const owner = core.getInput('github_owner')
10+
const catalogFile = core.getInput('catalog_file') || 'catalog-info.yaml'
11+
const repositoryFilterRegex = new RegExp(repositoryFilter)
12+
13+
const octokit = new Octokit({ auth: GITHUB_TOKEN })
14+
15+
const repos = await octokit.paginate('GET /orgs/{owner}/repos',
16+
{
17+
owner: owner,
18+
type: repositoryType,
19+
sort: 'full_name',
20+
per_page: 100
21+
})
22+
core.info(`Using repository filter: ${repositoryFilter}`)
23+
core.info(`Found ${repos.length} github repositories, now getting service data for those that match the filter ...`)
24+
const repoData = []
25+
for (const repo of repos) {
26+
if (repo.name.match(repositoryFilterRegex)) {
27+
try {
28+
const { data } = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
29+
owner: repo.full_name.split('/')[0],
30+
repo: repo.name,
31+
path: catalogFile
32+
})
33+
if (data) {
34+
const base64content = Buffer.from(data.content, 'base64')
35+
const serviceDefinition = YAML.parse(base64content.toString('utf8'))
36+
serviceDefinition._repo = repo
37+
serviceDefinition.status = 'OK'
38+
repoData.push(serviceDefinition)
39+
}
40+
} catch (ex) {
41+
repoData.push({
42+
status: `${catalogFile} missing`,
43+
_repo: repo
44+
})
45+
}
46+
}
47+
}
48+
core.info(`Processed ${repoData.length} matching repositories`)
49+
return repoData
50+
}
51+
52+
exports.getRepos = getRepos

0 commit comments

Comments
 (0)