MCPcopy Create free account
hub / github.com/github/docs / checkVariable

Function checkVariable

script/early-access/update-data-and-image-paths.js:127–150  ·  view source on GitHub ↗
(dataRef)

Source from the content-addressed store, hash-verified

125console.log('Done! Run "git status" in your docs-early-access checkout to see the changes.\n')
126
127function checkVariable(dataRef) {
128 // Get the data filepath from the data reference,
129 // where the data reference looks like: {% data variables.foo.bar %}
130 // and the data filepath looks like: data/variables/foo.yml with key of 'bar'.
131 const variablePathArray = dataRef
132 .match(/{% data (.*?) %}/)[1]
133 .split('.')
134 // If early access is part of the path, remove it (since the path below already includes it)
135 .filter((n) => n !== 'early-access')
136
137 // Given a string `variables.foo.bar` split into an array, we want the last segment 'bar', which is the variable key.
138 // Then pop 'bar' off the array because it's not really part of the filepath.
139 // The filepath we want is `variables/foo.yml`.
140 const variableKey = last(variablePathArray)
141 variablePathArray.pop()
142 const variablePath = path.posix.join(earlyAccessData, `${variablePathArray.join('/')}.yml`)
143
144 // If the variable file doesn't exist in data/early-access, exclude it
145 if (!fs.existsSync(variablePath)) return false
146
147 // If the variable file exists but doesn't have the referenced key, exclude it
148 const variableFileContent = yaml.load(fs.readFileSync(variablePath, 'utf8'))
149 return variableFileContent[variableKey]
150}
151
152function checkReusable(dataRef) {
153 // Get the data filepath from the data reference,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected