Skip to content

Commit

Permalink
Merge pull request #1 from twof/TestPR
Browse files Browse the repository at this point in the history
Fix downstream.yml and catch future broken yaml
  • Loading branch information
twof committed Oct 23, 2020
2 parents 9757519 + 33341cd commit c77a6c1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/twof/Downstream
rev: 0.0.1
rev: 0.0.2
hooks:
- id: downstream
4 changes: 3 additions & 1 deletion Sources/Downstream/downstream.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
associations:
main.swift:
- https://github.com/JohnSundell/Files/blob/master/Sources/Files.swift
- https://github.com/twof/Downstream/blob/main/README.md
Associations.swift:
- https://github.com/twof/Downstream/blob/main/README.md
11 changes: 9 additions & 2 deletions Sources/Downstream/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ let todos = fileList.flatMap { filePath -> [String] in
// print("parent", changedFile.parent?.path)
// print("yaml", try? changedFile.parent?.file(named: "downstream.yml").read())
// let associationsData = (try? changedFile.parent?.file(named: "downstream.yml").read() as? Data).flatMap { try? decoder.decode(AssociationsFile.self, from: $0) }
// print("associations", associationsData)


if
let parent = changedFile.parent,
let downsteamYML = try? parent.file(named: "downstream.yml").read(),
let associationsFile = try? decoder.decode(AssociationsFile.self, from: downsteamYML)
let downsteamYML = try? parent.file(named: "downstream.yml").read()
{
guard let associationsFile = try? decoder.decode(AssociationsFile.self, from: downsteamYML) else {
print("\(parent.path)downstream.yml could not be parsed")
exit(1)
}
let fileName = changedFile.name
let newTodos = associationsFile.associations[fileName] ?? []
return newTodos.map {
Expand All @@ -40,3 +45,5 @@ if !todos.isEmpty {
print($0)
}
}

exit(0)

0 comments on commit c77a6c1

Please sign in to comment.