File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed
Sources/PackageCollections/Providers
Tests/PackageCollectionsTests Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ import PackageModel
19
19
import TSCBasic
20
20
21
21
struct GitHubPackageMetadataProvider : PackageMetadataProvider {
22
+ private static let apiHostPrefix = " api. "
23
+
22
24
public var name : String = " GitHub "
23
25
24
26
var configuration : Configuration
@@ -179,7 +181,7 @@ struct GitHubPackageMetadataProvider: PackageMetadataProvider {
179
181
let owner = String ( url [ ownerRange] )
180
182
let repo = String ( url [ repoRange] )
181
183
182
- return URL ( string: " https://api. \( host) /repos/ \( owner) / \( repo) " )
184
+ return URL ( string: " https:// \( Self . apiHostPrefix ) \( host) /repos/ \( owner) / \( repo) " )
183
185
}
184
186
}
185
187
return nil
@@ -194,7 +196,8 @@ struct GitHubPackageMetadataProvider: PackageMetadataProvider {
194
196
options. validResponseCodes = validResponseCodes
195
197
options. authorizationProvider = { url in
196
198
url. host. flatMap { host in
197
- self . configuration. authTokens ( ) ? [ . github( host) ] . flatMap { token in
199
+ let host = host. hasPrefix ( Self . apiHostPrefix) ? String ( host. dropFirst ( Self . apiHostPrefix. count) ) : host
200
+ return self . configuration. authTokens ( ) ? [ . github( host) ] . flatMap { token in
198
201
" token \( token) "
199
202
}
200
203
}
Original file line number Diff line number Diff line change @@ -209,7 +209,7 @@ class GitHubPackageMetadataProviderTests: XCTestCase {
209
209
try testWithTemporaryDirectory { tmpPath in
210
210
let repoURL = " https://github.com/octocat/Hello-World.git "
211
211
let apiURL = URL ( string: " https://api.github.com/repos/octocat/Hello-World " ) !
212
- let authTokens = [ AuthTokenType . github ( " api. github.com" ) : " foo " ]
212
+ let authTokens = [ AuthTokenType . github ( " github.com " ) : " foo " ]
213
213
214
214
let handler : HTTPClient . Handler = { request, _, completion in
215
215
if request. headers. get ( " Authorization " ) . first == " token \( authTokens. first!. value) " {
@@ -335,7 +335,7 @@ class GitHubPackageMetadataProviderTests: XCTestCase {
335
335
httpClient. configuration. requestHeaders!. add ( name: " Cache-Control " , value: " no-cache " )
336
336
var configuration = GitHubPackageMetadataProvider . Configuration ( )
337
337
if let token = ProcessEnv . vars [ " GITHUB_API_TOKEN " ] {
338
- configuration. authTokens = { [ . github( " api. github.com" ) : token] }
338
+ configuration. authTokens = { [ . github( " github.com " ) : token] }
339
339
}
340
340
configuration. apiLimitWarningThreshold = 50
341
341
configuration. cacheTTLInSeconds = - 1 // Disable cache so we hit the API
You can’t perform that action at this time.
0 commit comments