Skip to content

Commit

Permalink
Fix 'Failed to load data for file at path ../build-request.json' error
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins committed Oct 23, 2024
1 parent 231adf4 commit f18b7e8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,16 @@ struct PrepareRelease {
previousVersion: Version
) throws {
let commits = try Process.git.listOfCommitsBetween("HEAD", "\(previousVersion)")

let featuresReader = FeaturesReader(repoPath: repoPath)

let releaseNotes = try ReleaseNotesBuilder(
previousVersion: previousVersion,
newVersion: newVersion,
repoOrg: repoOrg,
repoType: repoType,
commits: commits
commits: commits,
features: featuresReader.getFeaturesFromFile(),
featuresIDToServiceName: featuresReader.getFeaturesIDToServiceNameDictFromFile()
).build()

let manifest = ReleaseManifest(
Expand Down
19 changes: 10 additions & 9 deletions AWSSDKSwiftCLI/Sources/AWSSDKSwiftCLI/Models/Features.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@
import Foundation
import AWSCLIUtils

struct FeaturesReader: Decodable {
private let requestFilePath: String
private let mappingFilePath: String
struct FeaturesReader {
private let repoPath: String
private let requestFile = "build-request.json"
private let mappingFile = "feature-service-id.json"

public init(
requestFilePath: String = "../build-request.json",
mappingFilePath: String = "../feature-service-id.json"
repoPath: String = "."
) {
self.requestFilePath = requestFilePath
self.mappingFilePath = mappingFilePath
self.repoPath = repoPath
}

public func getFeaturesFromFile() throws -> Features {
let fileContents = try FileManager.default.loadContents(atPath: requestFilePath)
let path = URL(filePath: repoPath).appending(component: requestFile).path()
let fileContents = try FileManager.default.loadContents(atPath: path)
return try JSONDecoder().decode(Features.self, from: fileContents)
}

public func getFeaturesIDToServiceNameDictFromFile() throws -> [String: String] {
let fileContents = try FileManager.default.loadContents(atPath: mappingFilePath)
let path = URL(filePath: repoPath).appending(component: mappingFile).path()
let fileContents = try FileManager.default.loadContents(atPath: path)
return try JSONDecoder().decode([String: String].self, from: fileContents)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ struct ReleaseNotesBuilder {
let repoOrg: PrepareRelease.Org
let repoType: PrepareRelease.Repo
let commits: [String]
var featuresReader: FeaturesReader = FeaturesReader()
let features: Features
let featuresIDToServiceName: [String: String]

// MARK: - Build

Expand All @@ -41,9 +42,7 @@ struct ReleaseNotesBuilder {
}

func buildServiceChangeSection() throws -> [String] {
let features = try featuresReader.getFeaturesFromFile()
let mapping = try featuresReader.getFeaturesIDToServiceNameDictFromFile()
return buildServiceFeatureSection(features, mapping) + buildServiceDocSection(features, mapping)
return buildServiceFeatureSection(features, featuresIDToServiceName) + buildServiceDocSection(features, featuresIDToServiceName)
}

private func buildServiceFeatureSection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,8 @@ class ReleaseNotesBuilderTests: XCTestCase {
repoType: .awsSdkSwift,
commits: testCommits,
// Parametrize behavior of FeaturesReader with paths used to create JSON test files
featuresReader: FeaturesReader(
requestFilePath: "build-request.json",
mappingFilePath: "feature-service-id.json"
)
features: FeaturesReader().getFeaturesFromFile(),
featuresIDToServiceName: FeaturesReader().getFeaturesIDToServiceNameDictFromFile()
)
}
}

0 comments on commit f18b7e8

Please sign in to comment.