@@ -100,11 +100,10 @@ class GitHubAPI {
100100
101101 // MARK: - feed
102102
103- // TODO: fix path overwriting bug (see GitLab implementation)
104103 static func feedUrl( owner: String , repository: String , workflow: String , branch: String ? ) -> URL {
105104 // see https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-workflow
106- var components = URLComponents ( string : baseURL ( forAPI: true ) ) !
107- components. path = String ( format : " /repos/%@/%@/actions/workflows/%@/runs " , owner , repository , workflow )
105+ let url = baseURL ( forAPI: true ) . appending ( path : " /repos/ \( owner ) / \( repository ) /actions/workflows/ \( workflow ) /runs " )
106+ var components = URLComponents ( url : url , resolvingAgainstBaseURL : true ) !
108107 if let branch {
109108 components. appendQueryItem ( URLQueryItem ( name: " branch " , value: branch) )
110109 }
@@ -145,17 +144,19 @@ class GitHubAPI {
145144
146145 // MARK: - helper functions
147146
148- private static func baseURL( forAPI: Bool ) -> String {
147+ private static func baseURL( forAPI: Bool ) -> URL {
148+ var urlString = forAPI ? " https://api.github.com " : " https://github.com "
149149 let defaultsKey = forAPI ? " GitHubAPIBaseURL " : " GitHubBaseURL "
150150 if let defaultsBaseURL = UserDefaults . active. string ( forKey: defaultsKey) {
151- return defaultsBaseURL
151+ urlString = defaultsBaseURL
152152 }
153- return forAPI ? " https://api.github.com " : " https://github.com "
153+ guard let url = URL ( string: urlString) else { fatalError ( " Invalid base URL \( urlString) " ) }
154+ return url
154155 }
155156
156- private static func makeRequest( method: String = " GET " , baseUrl: String , path: String , params: Dictionary < String , String > = [ : ] , token: String ? = nil ) -> URLRequest {
157- var components = URLComponents ( string : baseUrl ) !
158- components. path = path // TODO: check for path overwriting issues
157+ private static func makeRequest( method: String = " GET " , baseUrl: URL , path: String , params: Dictionary < String , String > = [ : ] , token: String ? = nil ) -> URLRequest {
158+ let url = baseUrl . appending ( path : path )
159+ var components = URLComponents ( url : url , resolvingAgainstBaseURL : true ) !
159160 components. queryItems = params. map ( { URLQueryItem ( name: $0. key, value: $0. value) } )
160161 // TODO: Consider filtering token when the URL is overwritten via defaults
161162 return makeRequest ( method: method, url: components. url!, token: token)
0 commit comments