Skip to content

Commit

Permalink
🐛 Fix parsing of multiple groups
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaHuhn committed Jan 9, 2021
1 parent f347007 commit 40b7915
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 28 deletions.
47 changes: 33 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30284,32 +30284,51 @@ const parseFiles = (files) => {
const parseConfig = async () => {
const fileContent = await fs.promises.readFile(context.CONFIG_PATH)

const configObject = yaml.load(fileContent.toString())
const configObject = yaml.load(fileContent.toString(), { json: true })

const result = []
const result = {}

Object.keys(configObject).forEach((key) => {
if (key === 'group') {
const object = configObject[key]
const repos = typeof object.repos === 'string' ? object.repos.split('\n').filter((n) => n) : object.repos

repos.forEach((name) => {
const files = parseFiles(object.files)
result.push({
repo: parseRepoName(name),
files
const rawObject = configObject[key]

const groups = Array.isArray(rawObject) ? rawObject : [ rawObject ]

groups.forEach((group) => {
const repos = typeof group.repos === 'string' ? group.repos.split('\n').filter((n) => n) : group.repos

repos.forEach((name) => {
const files = parseFiles(group.files)
const repo = parseRepoName(name)

if (result[repo.fullName] !== undefined) {
result[repo.fullName].files.push(...files)
return
}

result[repo.fullName] = {
repo,
files
}
})
})
} else {
const files = parseFiles(configObject[key])
result.push({
repo: parseRepoName(key),
const repo = parseRepoName(key)

if (result[repo.fullName] !== undefined) {
result[repo.fullName].files.push(...files)
return
}

result[repo.fullName] = {
repo,
files
})
}
}
})

return result
return Object.values(result)
}

while (fs.existsSync(context.TMP_DIR)) {
Expand Down
47 changes: 33 additions & 14 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,32 +124,51 @@ const parseFiles = (files) => {
const parseConfig = async () => {
const fileContent = await fs.promises.readFile(context.CONFIG_PATH)

const configObject = yaml.load(fileContent.toString())
const configObject = yaml.load(fileContent.toString(), { json: true })

const result = []
const result = {}

Object.keys(configObject).forEach((key) => {
if (key === 'group') {
const object = configObject[key]
const repos = typeof object.repos === 'string' ? object.repos.split('\n').filter((n) => n) : object.repos

repos.forEach((name) => {
const files = parseFiles(object.files)
result.push({
repo: parseRepoName(name),
files
const rawObject = configObject[key]

const groups = Array.isArray(rawObject) ? rawObject : [ rawObject ]

groups.forEach((group) => {
const repos = typeof group.repos === 'string' ? group.repos.split('\n').filter((n) => n) : group.repos

repos.forEach((name) => {
const files = parseFiles(group.files)
const repo = parseRepoName(name)

if (result[repo.fullName] !== undefined) {
result[repo.fullName].files.push(...files)
return
}

result[repo.fullName] = {
repo,
files
}
})
})
} else {
const files = parseFiles(configObject[key])
result.push({
repo: parseRepoName(key),
const repo = parseRepoName(key)

if (result[repo.fullName] !== undefined) {
result[repo.fullName].files.push(...files)
return
}

result[repo.fullName] = {
repo,
files
})
}
}
})

return result
return Object.values(result)
}

while (fs.existsSync(context.TMP_DIR)) {
Expand Down

0 comments on commit 40b7915

Please sign in to comment.