Skip to content

Commit 63663db

Browse files
committed
Improve logging, make push_missing configurable
1 parent e17a98c commit 63663db

7 files changed

Lines changed: 31 additions & 23 deletions

File tree

action.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,25 @@ inputs:
1616
database:
1717
description: 'Parent database to add to'
1818
required: true
19+
push_missing:
20+
description: 'Push services that miss a `catalog-info.yaml` file or not'
21+
required: true
1922
system_database:
2023
description: 'Database ID to read systems from'
2124
owner_database:
2225
description: 'Database ID to read segments from'
2326
repository_type:
2427
description: 'Github repository type (e.g. all|private|internal), defaults to `all`'
28+
default: 'all'
2529
repository_filter:
2630
description: 'Regex string to filter repository name by, defaults to .*'
31+
default: '.*'
2732
repository_batch_size:
2833
description: 'How many github repos to request in parallel, defaults to 10'
34+
default: '10'
2935
catalog_file:
30-
description: 'Catalog file name to look for in the root of repo, defaults to `catalog_file.yaml`'
36+
description: 'Catalog file name to look for in the root of repo, defaults to `catalog-file.yaml`'
37+
default: 'catalog-file.yaml'
3138
outputs:
3239
status:
3340
description: 'The status of the scan'

dist/index.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20955,14 +20955,14 @@ const getRepos = async () => {
2095520955
const repositoryType = core.getInput('repository_type') || 'all'
2095620956
const repositoryFilter = core.getInput('repository_filter') || '.*'
2095720957
const repositoryBatchSize = parseInt(core.getInput('repository_batch_size') || '10')
20958+
const pushMissing = core.getBooleanInput('push_missing')
2095820959
const owner = core.getInput('github_owner')
2095920960
const catalogFile = core.getInput('catalog_file') || 'catalog-info.yaml'
2096020961
const repositoryFilterRegex = new RegExp(repositoryFilter)
2096120962
const octokit = new Octokit({ auth: GITHUB_TOKEN })
2096220963

20963-
const parseServiceDefinition = async (repo, path, pushMissing) => {
20964+
const parseServiceDefinition = async (repo, path) => {
2096420965
const repoData = []
20965-
core.debug(`Processing ${path} in ${repo.name} ...`)
2096620966
try {
2096720967
const { data } = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
2096820968
owner: repo.full_name.split('/')[0],
@@ -20981,14 +20981,16 @@ const getRepos = async () => {
2098120981
repoData.push(serviceDefinition)
2098220982
}
2098320983
}
20984+
core.debug(`🌟 Processed ${path} in ${repo.name} ...`)
2098420985
} catch (ex) {
2098520986
if (pushMissing) {
2098620987
repoData.push({
2098720988
status: `${catalogFile} missing`,
2098820989
_repo: repo
2098920990
})
20991+
core.debug(`- Loaded basic service data for ${repo.name} as no ${path} found`)
2099020992
} else {
20991-
core.warning(`Unable to find ${path} in ${repo.name}, not processing`)
20993+
core.debug(`✋ Unable to find ${path} in ${repo.name}, not processing as 'push_missing' is false`)
2099220994
}
2099320995
}
2099420996
return repoData
@@ -20999,14 +21001,13 @@ const getRepos = async () => {
2099921001
const targets = serviceDefinition.spec?.targets
2100021002
if (targets && targets.length > 0) {
2100121003
for (const target of targets) {
21002-
const pushMissing = false
21003-
const targetDefinition = await parseServiceDefinition(repo, target, pushMissing)
21004+
const targetDefinition = await parseServiceDefinition(repo, target)
2100421005
targetDefinition.fromLocation = true
2100521006
repoData.push(...targetDefinition)
2100621007
monoRepoCount++
2100721008
}
2100821009
} else {
21009-
core.warning(`Location file in ${repo._repo.name} at ${path} specified without valid spec.targets, will be skipped`)
21010+
core.warning(`Location file in ${repo._repo.name} at ${path} specified without valid spec.targets, will be skipped`)
2101021011
}
2101121012
return repoData
2101221013
}
@@ -21018,8 +21019,7 @@ const getRepos = async () => {
2101821019
sort: 'full_name',
2101921020
per_page: 100
2102021021
})
21021-
core.info(`Using repository filter: ${repositoryFilter}`)
21022-
core.info(`Found ${repos.length} github repositories, now getting service data for those that match the filter ...`)
21022+
core.info(`Found ${repos.length} github repositories, now getting service data for those that match ${repositoryFilter}`)
2102321023

2102421024
// We will create an array of batches to speed up execution, run each batch
2102521025
// In series, and then join them together.
@@ -21028,8 +21028,7 @@ const getRepos = async () => {
2102821028

2102921029
for (const repo of repos) {
2103021030
if (repo.name.match(repositoryFilterRegex)) {
21031-
const pushMissing = true
21032-
repoFns.push(parseServiceDefinition(repo, catalogFile, pushMissing))
21031+
repoFns.push(parseServiceDefinition(repo, catalogFile))
2103321032
}
2103421033
}
2103521034

@@ -28263,7 +28262,7 @@ try {
2826328262
})
2826428263

2826528264
const refreshData = async () => {
28266-
core.startGroup('Loading services, systems and owners ...')
28265+
core.startGroup('🗂️ Loading services, systems and owners ...')
2826728266
const { systems, owners, structure, services } = await loadData({ core, notion })
2826828267
core.info(`Found ${structure.length} fields in the Service database: ${structure.map((item) => item.name)}`)
2826928268
core.info(`Loaded ${Object.keys(systems || {}).length} systems`)

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ jobs:
134134
system_database: 121534684fe840a1953500e603c2b602
135135
repository_type: all
136136
repository_filter: .*
137+
push_missing: true
137138
catalog_file: catalog-info.yaml
138139

139140
```

src/github.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ const getRepos = async () => {
1919
const repositoryType = core.getInput('repository_type') || 'all'
2020
const repositoryFilter = core.getInput('repository_filter') || '.*'
2121
const repositoryBatchSize = parseInt(core.getInput('repository_batch_size') || '10')
22+
const pushMissing = core.getBooleanInput('push_missing')
2223
const owner = core.getInput('github_owner')
2324
const catalogFile = core.getInput('catalog_file') || 'catalog-info.yaml'
2425
const repositoryFilterRegex = new RegExp(repositoryFilter)
2526
const octokit = new Octokit({ auth: GITHUB_TOKEN })
2627

27-
const parseServiceDefinition = async (repo, path, pushMissing) => {
28+
const parseServiceDefinition = async (repo, path) => {
2829
const repoData = []
29-
core.debug(`Processing ${path} in ${repo.name} ...`)
3030
try {
3131
const { data } = await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', {
3232
owner: repo.full_name.split('/')[0],
@@ -45,14 +45,16 @@ const getRepos = async () => {
4545
repoData.push(serviceDefinition)
4646
}
4747
}
48+
core.debug(`🌟 Processed ${path} in ${repo.name} ...`)
4849
} catch (ex) {
4950
if (pushMissing) {
5051
repoData.push({
5152
status: `${catalogFile} missing`,
5253
_repo: repo
5354
})
55+
core.debug(`- Loaded basic service data for ${repo.name} as no ${path} found`)
5456
} else {
55-
core.warning(`Unable to find ${path} in ${repo.name}, not processing`)
57+
core.debug(`✋ Unable to find ${path} in ${repo.name}, not processing as 'push_missing' is false`)
5658
}
5759
}
5860
return repoData
@@ -63,14 +65,13 @@ const getRepos = async () => {
6365
const targets = serviceDefinition.spec?.targets
6466
if (targets && targets.length > 0) {
6567
for (const target of targets) {
66-
const pushMissing = false
67-
const targetDefinition = await parseServiceDefinition(repo, target, pushMissing)
68+
const targetDefinition = await parseServiceDefinition(repo, target)
6869
targetDefinition.fromLocation = true
6970
repoData.push(...targetDefinition)
7071
monoRepoCount++
7172
}
7273
} else {
73-
core.warning(`Location file in ${repo._repo.name} at ${path} specified without valid spec.targets, will be skipped`)
74+
core.warning(`Location file in ${repo._repo.name} at ${path} specified without valid spec.targets, will be skipped`)
7475
}
7576
return repoData
7677
}
@@ -82,8 +83,7 @@ const getRepos = async () => {
8283
sort: 'full_name',
8384
per_page: 100
8485
})
85-
core.info(`Using repository filter: ${repositoryFilter}`)
86-
core.info(`Found ${repos.length} github repositories, now getting service data for those that match the filter ...`)
86+
core.info(`Found ${repos.length} github repositories, now getting service data for those that match ${repositoryFilter}`)
8787

8888
// We will create an array of batches to speed up execution, run each batch
8989
// In series, and then join them together.
@@ -92,8 +92,7 @@ const getRepos = async () => {
9292

9393
for (const repo of repos) {
9494
if (repo.name.match(repositoryFilterRegex)) {
95-
const pushMissing = true
96-
repoFns.push(parseServiceDefinition(repo, catalogFile, pushMissing))
95+
repoFns.push(parseServiceDefinition(repo, catalogFile))
9796
}
9897
}
9998

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ try {
1515
})
1616

1717
const refreshData = async () => {
18-
core.startGroup('Loading services, systems and owners ...')
18+
core.startGroup('🗂️ Loading services, systems and owners ...')
1919
const { systems, owners, structure, services } = await loadData({ core, notion })
2020
core.info(`Found ${structure.length} fields in the Service database: ${structure.map((item) => item.name)}`)
2121
core.info(`Loaded ${Object.keys(systems || {}).length} systems`)

src/index.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test('complete input should succeed with default inputs', () => {
88
process.env.INPUT_DATABASE = process.env.NOTION_DATABASE // cecaf0beb15945158d155866ff9acce8
99
process.env.INPUT_NOTION_TOKEN = process.env.NOTION_TOKEN
1010
process.env.INPUT_GITHUB_TOKEN = process.env.GITHUB_TOKEN
11+
process.env.INPUT_PUSH_MISSING = 'true'
1112
process.env.INPUT_REPOSITORY_TYPE = 'public'
1213
process.env.INPUT_REPOSITORY_FILTER = 'notion-github-catalog'
1314
process.env.INPUT_GITHUB_OWNER = 'infinitaslearning'

src/local.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ process.env.INPUT_REPOSITORY_TYPE = 'public'
88
process.env.INPUT_GITHUB_OWNER = 'infinitaslearning'
99
process.env.INPUT_REPOSITORY_FILTER = '.*'
1010
process.env.INPUT_REPOSITORY_BATCH_SIZE = '50'
11+
process.env.INPUT_PUSH_MISSING = 'true'
1112
process.env.INPUT_DATABASE = 'cecaf0beb15945158d155866ff9acce8'
1213
process.env.INPUT_OWNER_DATABASE = '7943615f4dba43b3a3b0f991f4f7136d'
1314
process.env.INPUT_SYSTEM_DATABASE = '121534684fe840a1953500e603c2b602'

0 commit comments

Comments
 (0)