Skip to content

Commit 5f6a875

Browse files
authored
Merge pull request github#7272 from github/repo-sync
repo sync
2 parents a2bc6c7 + 936f3e1 commit 5f6a875

File tree

6 files changed

+157
-14
lines changed

6 files changed

+157
-14
lines changed

data/graphql/ghae/graphql_previews.ghae.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
- CreateDeploymentInput
2626
- CreateDeploymentPayload
2727
owning_teams:
28-
- '@github/ecosystem-api'
28+
- '@github/c2c-actions-service'
2929
- title: >-
3030
MergeInfoPreview - More detailed information about a pull request's merge
3131
state.

data/graphql/graphql_previews.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
- CreateDeploymentInput
2626
- CreateDeploymentPayload
2727
owning_teams:
28-
- '@github/ecosystem-api'
28+
- '@github/c2c-actions-service'
2929
- title: >-
3030
MergeInfoPreview - More detailed information about a pull request's merge
3131
state.

lib/graphql/static/previews.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"Mutation.createDeployment"
2424
],
2525
"owning_teams": [
26-
"@github/ecosystem-api"
26+
"@github/c2c-actions-service"
2727
],
2828
"accept_header": "application/vnd.github.flash-preview+json",
2929
"href": "/graphql/overview/schema-previews#deployments-preview"
@@ -940,7 +940,7 @@
940940
"Mutation.createDeployment"
941941
],
942942
"owning_teams": [
943-
"@github/ecosystem-api"
943+
"@github/c2c-actions-service"
944944
],
945945
"accept_header": "application/vnd.github.flash-preview+json",
946946
"href": "/graphql/overview/schema-previews#deployments-preview"

lib/graphql/static/schema-dotcom.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,7 +2048,7 @@
20482048
"Mutation.createDeployment"
20492049
],
20502050
"owning_teams": [
2051-
"@github/ecosystem-api"
2051+
"@github/c2c-actions-service"
20522052
],
20532053
"accept_header": "application/vnd.github.flash-preview+json",
20542054
"href": "/graphql/overview/schema-previews#deployments-preview"
@@ -2106,7 +2106,7 @@
21062106
"Mutation.createDeployment"
21072107
],
21082108
"owning_teams": [
2109-
"@github/ecosystem-api"
2109+
"@github/c2c-actions-service"
21102110
],
21112111
"accept_header": "application/vnd.github.flash-preview+json",
21122112
"href": "/graphql/overview/schema-previews#deployments-preview"
@@ -14984,7 +14984,7 @@
1498414984
"Mutation.createDeployment"
1498514985
],
1498614986
"owning_teams": [
14987-
"@github/ecosystem-api"
14987+
"@github/c2c-actions-service"
1498814988
],
1498914989
"accept_header": "application/vnd.github.flash-preview+json",
1499014990
"href": "/graphql/overview/schema-previews#deployments-preview"
@@ -70019,7 +70019,7 @@
7001970019
"Mutation.createDeployment"
7002070020
],
7002170021
"owning_teams": [
70022-
"@github/ecosystem-api"
70022+
"@github/c2c-actions-service"
7002370023
],
7002470024
"accept_header": "application/vnd.github.flash-preview+json",
7002570025
"href": "/graphql/overview/schema-previews#deployments-preview"
@@ -70118,7 +70118,7 @@
7011870118
"Mutation.createDeployment"
7011970119
],
7012070120
"owning_teams": [
70121-
"@github/ecosystem-api"
70121+
"@github/c2c-actions-service"
7012270122
],
7012370123
"accept_header": "application/vnd.github.flash-preview+json",
7012470124
"href": "/graphql/overview/schema-previews#deployments-preview"

lib/graphql/static/schema-ghae.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@
16051605
"Mutation.createDeployment"
16061606
],
16071607
"owning_teams": [
1608-
"@github/ecosystem-api"
1608+
"@github/c2c-actions-service"
16091609
],
16101610
"accept_header": "application/vnd.github.flash-preview+json",
16111611
"href": "/graphql/overview/schema-previews#deployments-preview"
@@ -1663,7 +1663,7 @@
16631663
"Mutation.createDeployment"
16641664
],
16651665
"owning_teams": [
1666-
"@github/ecosystem-api"
1666+
"@github/c2c-actions-service"
16671667
],
16681668
"accept_header": "application/vnd.github.flash-preview+json",
16691669
"href": "/graphql/overview/schema-previews#deployments-preview"
@@ -13546,7 +13546,7 @@
1354613546
"Mutation.createDeployment"
1354713547
],
1354813548
"owning_teams": [
13549-
"@github/ecosystem-api"
13549+
"@github/c2c-actions-service"
1355013550
],
1355113551
"accept_header": "application/vnd.github.flash-preview+json",
1355213552
"href": "/graphql/overview/schema-previews#deployments-preview"
@@ -64861,7 +64861,7 @@
6486164861
"Mutation.createDeployment"
6486264862
],
6486364863
"owning_teams": [
64864-
"@github/ecosystem-api"
64864+
"@github/c2c-actions-service"
6486564865
],
6486664866
"accept_header": "application/vnd.github.flash-preview+json",
6486764867
"href": "/graphql/overview/schema-previews#deployments-preview"
@@ -64960,7 +64960,7 @@
6496064960
"Mutation.createDeployment"
6496164961
],
6496264962
"owning_teams": [
64963-
"@github/ecosystem-api"
64963+
"@github/c2c-actions-service"
6496464964
],
6496564965
"accept_header": "application/vnd.github.flash-preview+json",
6496664966
"href": "/graphql/overview/schema-previews#deployments-preview"
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/usr/bin/env node
2+
3+
// [start-readme]
4+
//
5+
// Run this script to add versions frontmatter and Liquid conditionals for
6+
// GitHub Enterprise Cloud, based on anything currently versioned for the specified release
7+
// of free-pro-team.
8+
//
9+
// [end-readme]
10+
11+
const fs = require('fs')
12+
const path = require('path')
13+
const walk = require('walk-sync')
14+
const program = require('commander')
15+
const frontmatter = require('../../lib/read-frontmatter')
16+
const contentPath = path.join(process.cwd(), 'content')
17+
const dataPath = path.join(process.cwd(), 'data')
18+
19+
program
20+
.description('Add versions frontmatter and Liquid conditionals for GitHub EC based on FPT. Runs on all content by default.')
21+
.option('-p, --products [OPTIONAL PRODUCT_IDS...]', 'Optional list of space-separated product IDs. Example: admin github developers')
22+
.parse(process.argv)
23+
24+
const { products } = program.opts()
25+
26+
console.log('✅ Adding EC versioning based on FPT latest versioning')
27+
28+
if (products) {
29+
console.log(`✅ Running on the following products: ${products}`)
30+
} else {
31+
console.log('✅ Running on all products')
32+
}
33+
34+
console.log('✅ Running on English content and data\n')
35+
36+
// The new conditional to add
37+
const githubECConditional = 'currentVersion == "enterprise-cloud@latest"'
38+
39+
// Match: currentVersion == "free-pro-team@latest"
40+
const fptConditionalRegex = /currentVersion == "free-pro-team@latest"/
41+
42+
console.log('Working...\n')
43+
44+
const englishContentFiles = walkContent(contentPath)
45+
const englishDataFiles = walkData(dataPath)
46+
47+
function walkContent (dirPath) {
48+
const productArray = products || ['']
49+
return productArray.map(product => {
50+
dirPath = path.join(contentPath, product)
51+
return walk(dirPath, { includeBasePath: true, directories: false })
52+
.filter(file => file.includes('/content/'))
53+
.filter(file => file.endsWith('.md'))
54+
.filter(file => !file.endsWith('README.md'))
55+
}).flat()
56+
}
57+
58+
function walkData (dirPath) {
59+
return walk(dirPath, { includeBasePath: true, directories: false })
60+
.filter(file => file.includes('/data/reusables') || file.includes('/data/variables'))
61+
.filter(file => !file.endsWith('README.md'))
62+
}
63+
64+
const allContentFiles = englishContentFiles
65+
const allDataFiles = englishDataFiles
66+
67+
// Update the data files
68+
allDataFiles
69+
.forEach(file => {
70+
const dataContent = fs.readFileSync(file, 'utf8')
71+
72+
const conditionalsToUpdate = getConditionalsToUpdate(dataContent)
73+
if (!conditionalsToUpdate.length) return
74+
75+
// Update Liquid in data files
76+
const newDataContent = updateLiquid(conditionalsToUpdate, dataContent)
77+
78+
fs.writeFileSync(file, newDataContent)
79+
})
80+
81+
// Update the content files
82+
allContentFiles
83+
.forEach(file => {
84+
const { data, content } = frontmatter(fs.readFileSync(file, 'utf8'))
85+
86+
// Return early if the current page frontmatter does not apply to either GHEC or the given fpt release
87+
if (!(data.versions['free-pro-team'])) return
88+
89+
const conditionalsToUpdate = getConditionalsToUpdate(content)
90+
if (!conditionalsToUpdate.length) return
91+
92+
// Update Liquid in content files
93+
const newContent = updateLiquid(conditionalsToUpdate, content)
94+
95+
// Add frontmatter version
96+
data.versions['enterprise-cloud'] = '*'
97+
98+
// Update Liquid in frontmatter props
99+
Object.keys(data)
100+
.filter(key => typeof data[key] === 'string')
101+
.forEach(key => {
102+
const conditionalsToUpdate = getConditionalsToUpdate(data[key])
103+
if (!conditionalsToUpdate.length) return
104+
data[key] = updateLiquid(conditionalsToUpdate, data[key])
105+
})
106+
107+
fs.writeFileSync(file, frontmatter.stringify(newContent, data, { lineWidth: 10000 }))
108+
})
109+
110+
function getConditionalsToUpdate (content) {
111+
const allConditionals = content.match(/{% if .+?%}/g)
112+
113+
return (allConditionals || [])
114+
.filter(conditional => !conditional.includes('enterprise-cloud'))
115+
.filter(conditional => conditional.includes('free-pro-team'))
116+
}
117+
118+
function updateLiquid (conditionalsToUpdate, content) {
119+
let newContent = content
120+
121+
conditionalsToUpdate.forEach(conditional => {
122+
let newConditional = conditional
123+
124+
const fptMatch = conditional.match(fptConditionalRegex)
125+
126+
if (!fptMatch) {
127+
console.error(conditional)
128+
return
129+
}
130+
131+
// First do the replacement within the conditional
132+
// Old: {% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.21" %}
133+
// New: {% if currentVersion == "free-pro-team@latest" or currentVersion ver_gt "enterprise-server@2.21" or currentVersion == "enterprise-cloud@latest" %}
134+
newConditional = newConditional.replace(fptMatch[0], `${fptMatch[0]} or ${githubECConditional}`)
135+
136+
// Then replace all instances of the conditional in the content
137+
newContent = newContent.replace(conditional, newConditional)
138+
})
139+
140+
return newContent
141+
}
142+
143+
console.log('Done!')

0 commit comments

Comments
 (0)