Skip to content

Commit 25b478b

Browse files
committed
Add lifecycle and dependsOn
1 parent 0baac53 commit 25b478b

6 files changed

Lines changed: 112 additions & 8 deletions

File tree

dist/index.js

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20409,6 +20409,34 @@ const loadData = async ({ notion }) => {
2040920409
exports.loadData = loadData
2041020410

2041120411

20412+
/***/ }),
20413+
20414+
/***/ 4154:
20415+
/***/ ((__unused_webpack_module, exports) => {
20416+
20417+
const getDependsOn = async (dependsOn, { notion, database }) => {
20418+
const dependencies = []
20419+
for (const dependency of dependsOn) {
20420+
// Lets see if we can find the row
20421+
const search = await notion.databases.query({
20422+
database_id: database,
20423+
filter: {
20424+
property: 'Name',
20425+
text: {
20426+
equals: dependency
20427+
}
20428+
}
20429+
})
20430+
if (search.results.length > 0) {
20431+
dependencies.push({ id: search.results[0].id })
20432+
}
20433+
}
20434+
return dependencies
20435+
}
20436+
20437+
exports.getDependsOn = getDependsOn
20438+
20439+
2041220440
/***/ }),
2041320441

2041420442
/***/ 3504:
@@ -20461,6 +20489,18 @@ const getRepos = async () => {
2046120489
}
2046220490
}
2046320491
}
20492+
20493+
// Now we want to sort the repositories based on their name, and the number of dependencies
20494+
repoData.sort((a, b) => {
20495+
const aDependsOn = a.spec?.dependsOn?.length || 0
20496+
const bDependsOn = b.spec?.dependsOn?.length || 0
20497+
const aSort = aDependsOn + '.' + a._repo.name
20498+
const bSort = bDependsOn + '.' + b._repo.name
20499+
if (aSort < bSort) return -1
20500+
if (aSort > bSort) return 1
20501+
return 0
20502+
})
20503+
2046420504
core.info(`Processed ${repoData.length} matching repositories`)
2046520505
return repoData
2046620506
}
@@ -20580,6 +20620,7 @@ exports.ensureLinks = ensureLinks
2058020620

2058120621
const core = __nccwpck_require__(272)
2058220622
const { ensureLinks } = __nccwpck_require__(5475)
20623+
const { getDependsOn } = __nccwpck_require__(4154)
2058320624

2058420625
const updateServices = async (repositories, { notion, database, systems, owners }) => {
2058520626
for (const repo of repositories) {
@@ -20608,9 +20649,13 @@ const updateServices = async (repositories, { notion, database, systems, owners
2060820649

2060920650
const updateNotionRow = async (repo, pageId, { notion, database, systems, owners }) => {
2061020651
try {
20652+
let dependsOn = []
20653+
if (repo.spec?.dependsOn?.length > 0) {
20654+
dependsOn = await getDependsOn(repo.spec.dependsOn, { notion, database })
20655+
}
2061120656
await notion.pages.update({
2061220657
page_id: pageId,
20613-
properties: createProperties(repo, { systems, owners })
20658+
properties: createProperties(repo, dependsOn, { systems, owners })
2061420659
})
2061520660
if (repo.metadata?.links) {
2061620661
await ensureLinks(pageId, repo.metadata.links, { notion })
@@ -20622,11 +20667,15 @@ const updateNotionRow = async (repo, pageId, { notion, database, systems, owners
2062220667

2062320668
const createNotionRow = async (repo, { notion, database, systems, owners }) => {
2062420669
try {
20670+
let dependsOn = []
20671+
if (repo.spec?.dependsOn?.length > 0) {
20672+
dependsOn = await getDependsOn(repo.spec.dependsOn, { notion, database })
20673+
}
2062520674
const page = await notion.pages.create({
2062620675
parent: {
2062720676
database_id: database
2062820677
},
20629-
properties: createProperties(repo, { systems, owners })
20678+
properties: createProperties(repo, dependsOn, { systems, owners })
2063020679
})
2063120680
if (repo.metadata?.links) {
2063220681
await ensureLinks(page.id, repo.metadata.links, { notion })
@@ -20636,7 +20685,7 @@ const createNotionRow = async (repo, { notion, database, systems, owners }) => {
2063620685
}
2063720686
}
2063820687

20639-
const createProperties = (repo, { systems, owners }) => {
20688+
const createProperties = (repo, dependsOn, { systems, owners }) => {
2064020689
let owner, system
2064120690
const ownerSpec = repo?.spec?.owner
2064220691
const systemSpec = repo?.spec?.system
@@ -20702,6 +20751,7 @@ const createProperties = (repo, { systems, owners }) => {
2070220751
},
2070320752
Owner: owner,
2070420753
System: system,
20754+
DependsOn: { relation: dependsOn },
2070520755
Visibility: {
2070620756
select: {
2070720757
name: repo._repo.visibility
@@ -20712,6 +20762,11 @@ const createProperties = (repo, { systems, owners }) => {
2071220762
name: repo._repo.language || 'Unknown'
2071320763
}
2071420764
},
20765+
Lifecycle: {
20766+
select: {
20767+
name: repo.spec?.lifecycle || 'Unknown'
20768+
}
20769+
},
2071520770
Status: {
2071620771
select: {
2071720772
name: repo.status

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ This action expects a Notion database with the following properties, this will b
1515
- Name: text
1616
- Description: text
1717
- Kind: select
18+
- Lifecycle: select
1819
- URL: url
1920
- Owner: select|relation
2021
- System: select|relation
22+
- DependsOn: relation (to self - new field - sync tasks)
2123
- Tags: multi_select
2224
- Visibility: select
2325
- Language: select

src/depends.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const getDependsOn = async (dependsOn, { notion, database }) => {
2+
const dependencies = []
3+
for (const dependency of dependsOn) {
4+
// Lets see if we can find the row
5+
const search = await notion.databases.query({
6+
database_id: database,
7+
filter: {
8+
property: 'Name',
9+
text: {
10+
equals: dependency
11+
}
12+
}
13+
})
14+
if (search.results.length > 0) {
15+
dependencies.push({ id: search.results[0].id })
16+
}
17+
}
18+
return dependencies
19+
}
20+
21+
exports.getDependsOn = getDependsOn

src/github.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ const getRepos = async () => {
4545
}
4646
}
4747
}
48+
49+
// Now we want to sort the repositories based on their name, and the number of dependencies
50+
repoData.sort((a, b) => {
51+
const aDependsOn = a.spec?.dependsOn?.length || 0
52+
const bDependsOn = b.spec?.dependsOn?.length || 0
53+
const aSort = aDependsOn + '.' + a._repo.name
54+
const bSort = bDependsOn + '.' + b._repo.name
55+
if (aSort < bSort) return -1
56+
if (aSort > bSort) return 1
57+
return 0
58+
})
59+
4860
core.info(`Processed ${repoData.length} matching repositories`)
4961
return repoData
5062
}

src/local.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ process.env.INPUT_NOTION_TOKEN = process.env.NOTION_TOKEN
66
process.env.INPUT_GITHUB_TOKEN = process.env.GITHUB_TOKEN
77
process.env.INPUT_REPOSITORY_TYPE = 'public'
88
process.env.INPUT_GITHUB_OWNER = 'infinitaslearning'
9-
process.env.INPUT_REPOSITORY_FILTER = 'notion'
9+
process.env.INPUT_REPOSITORY_FILTER = '.*'
1010
process.env.INPUT_DATABASE = 'cecaf0beb15945158d155866ff9acce8'
1111
process.env.INPUT_OWNER_DATABASE = '7943615f4dba43b3a3b0f991f4f7136d'
1212
process.env.INPUT_SYSTEM_DATABASE = '121534684fe840a1953500e603c2b602'
13-
1413
// process.env.INPUT_DATABASE = '2b26b4290cc84d95ad3e93c3255277a1'
1514
// process.env.INPUT_OWNER_DATABASE = '3ee0d01944924634990b42b44253d370'
1615
// process.env.INPUT_SYSTEM_DATABASE = 'c721d8f0e6e34961ba037c67ad632585'

src/services.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const core = require('@actions/core')
22
const { ensureLinks } = require('./links')
3+
const { getDependsOn } = require('./depends')
34

45
const updateServices = async (repositories, { notion, database, systems, owners }) => {
56
for (const repo of repositories) {
@@ -28,9 +29,13 @@ const updateServices = async (repositories, { notion, database, systems, owners
2829

2930
const updateNotionRow = async (repo, pageId, { notion, database, systems, owners }) => {
3031
try {
32+
let dependsOn = []
33+
if (repo.spec?.dependsOn?.length > 0) {
34+
dependsOn = await getDependsOn(repo.spec.dependsOn, { notion, database })
35+
}
3136
await notion.pages.update({
3237
page_id: pageId,
33-
properties: createProperties(repo, { systems, owners })
38+
properties: createProperties(repo, dependsOn, { systems, owners })
3439
})
3540
if (repo.metadata?.links) {
3641
await ensureLinks(pageId, repo.metadata.links, { notion })
@@ -42,11 +47,15 @@ const updateNotionRow = async (repo, pageId, { notion, database, systems, owners
4247

4348
const createNotionRow = async (repo, { notion, database, systems, owners }) => {
4449
try {
50+
let dependsOn = []
51+
if (repo.spec?.dependsOn?.length > 0) {
52+
dependsOn = await getDependsOn(repo.spec.dependsOn, { notion, database })
53+
}
4554
const page = await notion.pages.create({
4655
parent: {
4756
database_id: database
4857
},
49-
properties: createProperties(repo, { systems, owners })
58+
properties: createProperties(repo, dependsOn, { systems, owners })
5059
})
5160
if (repo.metadata?.links) {
5261
await ensureLinks(page.id, repo.metadata.links, { notion })
@@ -56,7 +65,7 @@ const createNotionRow = async (repo, { notion, database, systems, owners }) => {
5665
}
5766
}
5867

59-
const createProperties = (repo, { systems, owners }) => {
68+
const createProperties = (repo, dependsOn, { systems, owners }) => {
6069
let owner, system
6170
const ownerSpec = repo?.spec?.owner
6271
const systemSpec = repo?.spec?.system
@@ -122,6 +131,7 @@ const createProperties = (repo, { systems, owners }) => {
122131
},
123132
Owner: owner,
124133
System: system,
134+
DependsOn: { relation: dependsOn },
125135
Visibility: {
126136
select: {
127137
name: repo._repo.visibility
@@ -132,6 +142,11 @@ const createProperties = (repo, { systems, owners }) => {
132142
name: repo._repo.language || 'Unknown'
133143
}
134144
},
145+
Lifecycle: {
146+
select: {
147+
name: repo.spec?.lifecycle || 'Unknown'
148+
}
149+
},
135150
Status: {
136151
select: {
137152
name: repo.status

0 commit comments

Comments
 (0)