MCPcopy Create free account
hub / github.com/EndBug/label-sync / parseConfigFile

Function parseConfigFile

src/index.ts:159–195  ·  view source on GitHub ↗
(
  fileExtension: string,
  unparsedConfig: string
)

Source from the content-addressed store, hash-verified

157}
158
159function parseConfigFile(
160 fileExtension: string,
161 unparsedConfig: string
162): LabelInfo[] {
163 let parsed: LabelInfo[]
164
165 if (['.yaml', '.yml'].includes(fileExtension)) {
166 // Parse YAML file
167 log.info('Parsing YAML file...')
168 parsed = yaml.load(unparsedConfig) as LabelInfo[]
169 try {
170 throwConfigError(parsed)
171 } catch (e) {
172 log.error(JSON.stringify(parsed, null, 2), false)
173 throw 'Parsed YAML file is invalid:\n' + e
174 }
175 } else if (fileExtension == '.json') {
176 // Try to parse JSON file
177 log.info('Parsing JSON file...')
178 try {
179 parsed = JSON.parse(unparsedConfig)
180 } catch {
181 throw "Couldn't parse JSON config file, check for syntax errors."
182 }
183
184 try {
185 throwConfigError(parsed)
186 } catch (e) {
187 log.error(JSON.stringify(parsed, null, 2), false)
188 throw 'Parsed JSON file is invalid:\n' + e
189 }
190 } else {
191 throw `Invalid file extension: ${fileExtension}`
192 }
193
194 return parsed
195}
196
197async function readRemoteConfigFile(fileURL: string): Promise<LabelInfo[]> {
198 startGroup('Reading remote config file...')

Callers 2

readConfigFileFunction · 0.85
readRemoteConfigFileFunction · 0.85

Calls 1

throwConfigErrorFunction · 0.85

Tested by

no test coverage detected