Skip to content

Commit f4b1e7d

Browse files
committed
looking in the right place for downstream.yml files
1 parent 9000c7e commit f4b1e7d

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

Sources/downstream/DownstreamArgument.swift

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ struct DownstreamArgument: ParsableCommand {
3333
}
3434

3535
// Associations file is used in place of an actual file during tests
36-
func todos(fileList: [String]) throws -> TodoList {
36+
func todos(fileList: [String], associationsFiles: [String: AssociationsFile]?=nil) throws -> TodoList {
3737
return try fileList.reduce(into: TodoList()) { (result, filePath) in
38-
let matches = try matches(forFile: filePath)
38+
let parent = URL(fileURLWithPath: filePath).deletingLastPathComponent().path
39+
let matches = try matches(forFile: filePath, associationsFile: associationsFiles?[parent])
3940
if !matches.isEmpty {
4041
result[filePath] = matches
4142
}
@@ -46,12 +47,13 @@ struct DownstreamArgument: ParsableCommand {
4647
let decoder = YAMLDecoder()
4748

4849
if let associationsFile = associationsFile {
49-
return associationsFile.associations.matches(path)
50+
let changedFile = URL(fileURLWithPath: path)
51+
return associationsFile.associations.matches(changedFile.lastPathComponent)
5052
} else {
5153
// This path should be coming from git diff, so we expect it to be valid
5254
let changedFile = URL(fileURLWithPath: path)
5355
let parent = changedFile.deletingLastPathComponent()
54-
let downstreamYML = changedFile.appendingPathComponent("downstream.yml")
56+
let downstreamYML = parent.appendingPathComponent("downstream.yml")
5557

5658
if
5759
let contentData = FileManager.default.contents(atPath: downstreamYML.path),

Tests/DownstreamTests/DownstreamTests.swift

+21
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,25 @@ final class DownstreamTests: XCTestCase {
2828
let todos = try downstreamArgument.matches(forFile: "main.swift", associationsFile: associations)
2929
XCTAssertEqual(todos, ["www.maindocs.com", "anotherPlaceToFindDocs"])
3030
}
31+
32+
func testMultipleInputFiles() throws {
33+
let topAssociations = AssociationsFile(associations: [
34+
"Package.swift": ["dependenciesDocs.com"]
35+
])
36+
37+
let sourceAssociations = AssociationsFile(associations: [
38+
"main.swift": ["www.maindocs.com", "anotherPlaceToFindDocs"],
39+
"unchangingFile.swift": ["www.unchangingDocs.edu"],
40+
])
41+
42+
let allAssociations = ["/": topAssociations, "/Source": sourceAssociations]
43+
44+
let downstreamArgument = DownstreamArgument()
45+
let todos = try downstreamArgument.todos(fileList: ["/Source/main.swift", "/Package.swift"], associationsFiles: allAssociations)
46+
47+
XCTAssertEqual(todos, [
48+
"/Source/main.swift": ["www.maindocs.com", "anotherPlaceToFindDocs"],
49+
"/Package.swift": ["dependenciesDocs.com"]
50+
])
51+
}
3152
}

0 commit comments

Comments
 (0)