@@ -17,8 +17,8 @@ module BuildChartTypes =
1717
1818 type Build =
1919 {
20- Id : int
21- BuildNumber : int
20+ Id : int64
21+ BuildNumber : int64
2222 TimeTaken : TimeSpan
2323 Status : BuildStatus
2424 Branch : string
@@ -99,7 +99,6 @@ module BuildChartHttpClients =
9999 open System.Net .Http .Headers
100100 open Microsoft.Extensions .Caching .Memory
101101 open Microsoft.FSharp .Core .Option
102- open FSharp.Control .Tasks
103102 open Newtonsoft.Json .Linq
104103 open Giraffe
105104
@@ -133,8 +132,8 @@ module BuildChartHttpClients =
133132 let started = x.Value< Nullable< DateTime>> " started"
134133 let finished = x.Value< Nullable< DateTime>> " finished"
135134 {
136- Id = x.Value< int > " buildId"
137- BuildNumber = x.Value< int > " buildNumber"
135+ Id = x.Value< int64 > " buildId"
136+ BuildNumber = x.Value< int64 > " buildNumber"
138137 Status = x.Value< string> " status" |> parseStatus
139138 Branch = x.Value< string> " branch"
140139 FromPullRequest = x.Value< string> " pullRequestId" |> isPullRequest
@@ -158,13 +157,15 @@ module BuildChartHttpClients =
158157 sprintf " https://ci.appveyor.com/api/projects/%s /%s /history?recordsNumber=%d%s "
159158 account project ( 5 * buildCount) branchFilter
160159
161- let request = new HttpRequestMessage( HttpMethod.Get, url)
160+ let requestFactory =
161+ fun _ ->
162+ let request = new HttpRequestMessage( HttpMethod.Get, url)
163+ if authToken.IsSome then
164+ let token = AES.decryptUrlEncodedString Env.cryptoKey authToken.Value
165+ request.Headers.Authorization <- AuthenticationHeaderValue( " Bearer" , token)
166+ request
162167
163- if authToken.IsSome then
164- let token = AES.decryptUrlEncodedString Env.cryptoKey authToken.Value
165- request.Headers.Authorization <- AuthenticationHeaderValue( " Bearer" , token)
166-
167- let! json = httpClient.SendAsync request
168+ let! json = httpClient.SendAsync requestFactory
168169
169170 return json
170171 |> ( Str.toOption
@@ -215,8 +216,8 @@ module BuildChartHttpClients =
215216 let finished = x.Value< Nullable< DateTime>> " finished_at"
216217 let state = x.Value< string> " state"
217218 {
218- Id = x.Value< int > " id"
219- BuildNumber = x.Value< int > " number"
219+ Id = x.Value< int64 > " id"
220+ BuildNumber = x.Value< int64 > " number"
220221 Branch = ( x.Value< JObject> " branch" ) .Value< string> " name"
221222 FromPullRequest = x.Value< string> " event_type" |> isPullRequest
222223 TimeTaken = BuildStatsHelper.timeTaken started finished
@@ -233,19 +234,13 @@ module BuildChartHttpClients =
233234 task {
234235 let account , project = slug
235236
236- let request = new HttpRequestMessage()
237- request.Method <- HttpMethod.Get
238- request.Headers.Add( " Travis-API-Version" , " 3" )
239- request.Headers.TryAddWithoutValidation( " User-Agent" , " BuildStats.info-API" ) |> ignore
240-
241- let topLevelDomain =
237+ let topLevelDomain , token =
242238 match isFallback, authToken with
243- | true , _ -> " org"
244- | false , None -> defaultArg ( tryGetTLD account project) " com"
239+ | true , _ -> " org" , None
240+ | false , None -> defaultArg ( tryGetTLD account project) " com" , None
245241 | false , Some t ->
246- let token = AES.decryptUrlEncodedString Env.cryptoKey t
247- request.Headers.Authorization <- AuthenticationHeaderValue( " token" , token)
248- " com"
242+ let tkn = AES.decryptUrlEncodedString Env.cryptoKey t
243+ " com" , Some tkn
249244
250245 let branchFilter =
251246 match branch with
@@ -265,9 +260,20 @@ module BuildChartHttpClients =
265260 branchFilter
266261 eventFilter
267262
268- request.RequestUri <- Uri( url)
269-
270- let! json = httpClient.SendAsync request
263+ let requestFactory =
264+ fun _ ->
265+ let request = new HttpRequestMessage()
266+ request.Method <- HttpMethod.Get
267+ request.Headers.Add( " Travis-API-Version" , " 3" )
268+ request.Headers.TryAddWithoutValidation( " User-Agent" , " BuildStats.info-API" ) |> ignore
269+ request.RequestUri <- Uri( url)
270+ match token with
271+ | None -> ()
272+ | Some t ->
273+ request.Headers.Authorization <- AuthenticationHeaderValue( " token" , t)
274+ request
275+
276+ let! json = httpClient.SendAsync requestFactory
271277
272278 let builds =
273279 json
@@ -325,8 +331,8 @@ module BuildChartHttpClients =
325331 let started = x.Value< Nullable< DateTime>> " start_time"
326332 let finished = x.Value< Nullable< DateTime>> " stop_time"
327333 {
328- Id = x.Value< int > " build_num"
329- BuildNumber = x.Value< int > " build_num"
334+ Id = x.Value< int64 > " build_num"
335+ BuildNumber = x.Value< int64 > " build_num"
330336 Status = x.Value< string> " status" |> parseStatus
331337 Branch = x.Value< string> " branch"
332338 FromPullRequest = x.Value< string> " subject" |> isPullRequest
@@ -353,8 +359,8 @@ module BuildChartHttpClients =
353359 sprintf " https://circleci.com/api/v1/project/%s /%s%s ?limit=%i "
354360 account project branchFilter limit
355361
356- let request = new HttpRequestMessage( HttpMethod.Get, url)
357- let! json = httpClient.SendAsync request
362+ let requestFactory = fun _ -> new HttpRequestMessage( HttpMethod.Get, url)
363+ let! json = httpClient.SendAsync requestFactory
358364
359365 return json
360366 |> ( Str.toOption
@@ -394,8 +400,8 @@ module BuildChartHttpClients =
394400 let started = x.Value< Nullable< DateTime>> " startTime"
395401 let finished = x.Value< Nullable< DateTime>> " finishTime"
396402 {
397- Id = x.Value< int > " id"
398- BuildNumber = x.Value< int > " id"
403+ Id = x.Value< int64 > " id"
404+ BuildNumber = x.Value< int64 > " id"
399405 Status = x.Value< string> " result" |> parseStatus
400406 Branch = ( x.Value< string> " sourceBranch" ) .Replace( " refs/heads/" , " " )
401407 FromPullRequest = x.Value< string> " reason" |> isPullRequest
@@ -421,8 +427,8 @@ module BuildChartHttpClients =
421427 sprintf " https://dev.azure.com/%s /%s /_apis/build/builds?api-version=%s &definitions=%i &$top=%i%s "
422428 account project apiVersion definitionId limit branchFilter
423429
424- let request = new HttpRequestMessage( HttpMethod.Get, url)
425- let! json = httpClient.SendAsync request
430+ let requestFactory = fun _ -> new HttpRequestMessage( HttpMethod.Get, url)
431+ let! json = httpClient.SendAsync requestFactory
426432
427433 return json
428434 |> ( Str.toOption
@@ -469,8 +475,8 @@ module BuildChartHttpClients =
469475 let outcome = parseStatus status conclusion
470476
471477 {
472- Id = x.Value< int > " id"
473- BuildNumber = x.Value< int > " run_number"
478+ Id = x.Value< int64 > " id"
479+ BuildNumber = x.Value< int64 > " run_number"
474480 Status = outcome
475481 Branch = ( x.Value< string> " head_branch" )
476482 FromPullRequest = x.Value< string> " event" |> isPullRequest
@@ -497,8 +503,8 @@ module BuildChartHttpClients =
497503 sprintf " https://api.github.com/repos/%s /%s /actions/runs%s "
498504 owner repo branchFilter
499505
500- let request = new HttpRequestMessage( HttpMethod.Get, url)
501- let! json = httpClient.SendAsync request
506+ let requestFactory = fun _ -> new HttpRequestMessage( HttpMethod.Get, url)
507+ let! json = httpClient.SendAsync requestFactory
502508
503509 let totalCount , jArray =
504510 Str.toOption json
@@ -517,4 +523,4 @@ module BuildChartHttpClients =
517523 |> convertToBuilds
518524 |> List.filter ( BuildStatsHelper.prFilter inclFromPullRequest)
519525 |> List.truncate buildCount
520- }
526+ }
0 commit comments