Skip to content

Commit a058709

Browse files
committed
scripts: address FSharpLint warnings
Contains failing CI.
1 parent d5b4312 commit a058709

File tree

6 files changed

+52
-49
lines changed

6 files changed

+52
-49
lines changed

scripts/checkCommits1by1.fsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ let GitHubApiCall(url: string) =
12311231
```
12321232
"""
12331233

1234-
match httpRequestException.StatusCode |> Option.ofNullable with
1234+
match Option.ofNullable httpRequestException.StatusCode with
12351235
| Some statusCode when statusCode = HttpStatusCode.NotFound ->
12361236
if accessTokenName <> "ACCESS_TOKEN" then
12371237
failwith accessTokenErrorMsg
@@ -1332,7 +1332,7 @@ Please activate GitHub Actions in your repository. Click on the
13321332
let notUsedGitPush1by1 =
13331333
gitHubActionsEnabled
13341334
&& ciStatuses.Any(fun (hasCiStatus, shouldHaveCiStatus) ->
1335-
hasCiStatus = false && shouldHaveCiStatus = true
1335+
(not hasCiStatus) && shouldHaveCiStatus
13361336
)
13371337

13381338
if notUsedGitPush1by1 then
@@ -1378,10 +1378,12 @@ prCommits
13781378
// discard check suites for the commit that are not from PR branch
13791379
|> Seq.filter(fun suite -> suite.PullRequests.Length > 0)
13801380
// take the first one (triggered by push); second one is triggered by pull_request
1381-
|> Seq.head
1381+
|> Seq.tryHead
13821382

1383-
let status = checkSuiteOfInterest.Status
1384-
let conclusion = checkSuiteOfInterest.Conclusion
1383+
let status, conclusion =
1384+
match checkSuiteOfInterest with
1385+
| Some checkSuite -> checkSuite.Status, checkSuite.Conclusion
1386+
| None -> failwith "No check suite found"
13851387

13861388
if status = "completed" && conclusion = "failure" then
13871389
Console.WriteLine()

scripts/deleteAssetsFromOldReleases.fsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ gitTagsToRemove
254254
| ex ->
255255
match FindException<HttpRequestException> ex with
256256
| Some httpRequestException ->
257-
match httpRequestException.StatusCode |> Option.ofNullable with
257+
match Option.ofNullable httpRequestException.StatusCode with
258258
| Some statusCode when statusCode = HttpStatusCode.Forbidden ->
259259

260260
failwith githubApiCallForbiddenErrorMsg
@@ -266,7 +266,7 @@ gitTagsToRemove
266266

267267
| _ -> reraise()
268268

269-
let DeleteAsset (url: string) (accessToken: string) =
269+
let deleteAsset (url: string) (accessToken: string) =
270270
use client = new HttpClient()
271271
client.DefaultRequestHeaders.Accept.Clear()
272272
client.DefaultRequestHeaders.Add("User-Agent", userAgent)
@@ -293,7 +293,7 @@ gitTagsToRemove
293293
| ex ->
294294
match FindException<HttpRequestException> ex with
295295
| Some httpRequestException ->
296-
match httpRequestException.StatusCode |> Option.ofNullable with
296+
match Option.ofNullable httpRequestException.StatusCode with
297297
| Some statusCode when statusCode = HttpStatusCode.Forbidden ->
298298
failwith githubApiCallForbiddenErrorMsg
299299
| _ -> reraise()
@@ -304,6 +304,6 @@ gitTagsToRemove
304304
let parsedJsonObj = GitHubAssetType.Parse releaseJsonString
305305

306306
parsedJsonObj.Assets
307-
|> Seq.iter(fun asset -> DeleteAsset asset.Url githubToken)
307+
|> Seq.iter(fun asset -> deleteAsset asset.Url githubToken)
308308
| _ -> ()
309309
)

scripts/deleteOldArtifacts.fsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ let GitHubApiQuery
133133
| ex ->
134134
match FindException<HttpRequestException> ex with
135135
| Some httpRequestException ->
136-
match httpRequestException.StatusCode |> Option.ofNullable with
136+
match Option.ofNullable httpRequestException.StatusCode with
137137
| Some statusCode when statusCode = HttpStatusCode.Forbidden ->
138138

139139
failwith githubApiCallForbiddenErrorMsg
@@ -142,14 +142,14 @@ let GitHubApiQuery
142142

143143
| _ -> reraise()
144144

145-
let hasCIStatus(commit: string) : bool =
145+
let HasCIStatus(commit: string) : bool =
146146
let url =
147147
sprintf
148148
"https://api.github.com/repos/%s/commits/%s/check-suites"
149149
githubRepository
150150
commit
151151

152-
let mediaTypeWithQuality = "application/vnd.github+json" |> Some
152+
let mediaTypeWithQuality = Some "application/vnd.github+json"
153153

154154
let json = GitHubApiQuery url Get mediaTypeWithQuality
155155

@@ -158,7 +158,7 @@ let hasCIStatus(commit: string) : bool =
158158
let userNameOrOrgName = githubRepository.Split("/").[0]
159159

160160
let artifactsApiQueryResult =
161-
let mediaTypeWithQuality = "application/vnd.github+json" |> Some
161+
let mediaTypeWithQuality = Some "application/vnd.github+json"
162162

163163
let url =
164164
$"https://api.github.com/repos/{githubRepository}/actions/artifacts"
@@ -204,7 +204,7 @@ let DeleteArtifact (githubRepository: string) (artifactId: string) =
204204
let url =
205205
$"https://api.github.com/repos/{githubRepository}/actions/artifacts/{artifactId}"
206206

207-
GitHubApiQuery url Delete None |> ignore
207+
GitHubApiQuery url Delete None |> ignore<string>
208208

209209
let previousCommitsHashes = GetPreviousCommitsHashes()
210210

@@ -214,25 +214,23 @@ match whatArtifactsToDelete with
214214
Console.WriteLine "About to delete only the artifacts of previous commit..."
215215

216216
let previousCommitWithCIStatusOpt =
217-
Seq.tryFind hasCIStatus previousCommitsHashes
217+
Seq.tryFind HasCIStatus previousCommitsHashes
218218

219219
match previousCommitWithCIStatusOpt with
220220
| None ->
221221
Console.WriteLine "No commits found with CI status"
222222
exit 0
223-
| _ -> ()
224-
225-
let previousCommitWithCIStatus = previousCommitWithCIStatusOpt.Value
226-
227-
let artifactIdsToDelete =
228-
artifactIds
229-
|> Seq.filter(fun item ->
230-
item.WorkflowRun.HeadSha = previousCommitWithCIStatus
223+
| Some previousCommitWithCIStatus ->
224+
let artifactIdsToDelete =
225+
artifactIds
226+
|> Seq.filter(fun item ->
227+
item.WorkflowRun.HeadSha = previousCommitWithCIStatus
228+
)
229+
|> Seq.map(fun artifact -> artifact.Id.ToString())
230+
231+
artifactIdsToDelete
232+
|> Seq.iter(fun artifactId -> DeleteArtifact githubRepository artifactId
231233
)
232-
|> Seq.map(fun artifact -> artifact.Id.ToString())
233-
234-
artifactIdsToDelete
235-
|> Seq.iter(fun artifactId -> DeleteArtifact githubRepository artifactId)
236234

237235
| AllFromBranchlessCommitsAndAllFromPreviousOnesInThisBranch ->
238236
Console.WriteLine "About to delete all previous artifacts of this branch..."

scripts/gitPush1by1.fsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,17 @@ let GitFetch(remoteOpt: Option<string>) =
6767
let GetLastNthCommitFromRemoteBranch
6868
(remoteName: string)
6969
(remoteBranch: string)
70-
(n: uint32)
70+
(commitNumber: uint32)
7171
=
7272
let gitShow =
7373
{
7474
Command = "git"
7575
Arguments =
76-
sprintf "show %s/%s~%i --no-patch" remoteName remoteBranch n
76+
sprintf
77+
"show %s/%s~%i --no-patch"
78+
remoteName
79+
remoteBranch
80+
commitNumber
7781
}
7882

7983
let gitShowProcOutput = Process.Execute(gitShow, Echo.Off).UnwrapDefault()
@@ -187,25 +191,22 @@ let maybeRemote, maybeNumberOfCommits, force =
187191
"Second argument should be an integer higher than zero"
188192

189193
Environment.Exit 2
190-
failwith "Unreachable"
194+
failwith "Unreachable because of System.Exit call on previous line (193)"
191195
| true, num ->
192196
let numberOfCommits = Some num
193197
let remote = Some args.[0]
194198

195199
let force =
196200
if args.Length = 3 then
197-
if args.[2] = "-f" || args.[2] = "--force" then
198-
true
199-
else
200-
false
201+
args.[2] = "-f" || args.[2] = "--force"
201202
else
202203
false
203204

204205
remote, numberOfCommits, force
205206
| _ ->
206207
Console.Error.WriteLine "Second argument should be an integer"
207208
Environment.Exit 3
208-
failwith "Unreachable"
209+
failwith "Unreachable because of System.Exit call on previous line (208)"
209210
elif args.Length = 0 then
210211
None, None, false
211212
else // if args.Length = 1 then
@@ -215,7 +216,7 @@ let maybeRemote, maybeNumberOfCommits, force =
215216
"Argument for the number of commits should be an integer higher than zero"
216217

217218
Environment.Exit 2
218-
failwith "Unreachable"
219+
failwith "Unreachable because of System.Exit call on previous line (218)"
219220
| true, num ->
220221
let numberOfCommits = Some num
221222
let remote = None
@@ -239,7 +240,7 @@ let remote, remoteUrl =
239240
)
240241

241242
Environment.Exit 4
242-
failwith "unreachable"
243+
failwith "Unreachable because of System.Exit call on previous line (242)"
243244
| Some remote -> remote
244245
| None ->
245246
if remotes.Count() > 1 then
@@ -266,7 +267,7 @@ let commitsToBePushed =
266267
)
267268

268269
Environment.Exit 5
269-
failwith "Unreachable"
270+
failwith "Unreachable because of System.Exit call on previous line (269)"
270271
elif commitsToPush.Length = 1 then
271272
// no need to ask for confirmation since 1 commit doesn't need to be separated from other commits
272273
// (one by one doesn't apply to a length of one)
@@ -280,7 +281,7 @@ let commitsToBePushed =
280281
remote
281282
)
282283

283-
Console.ReadKey true |> ignore
284+
Console.ReadKey true |> ignore<ConsoleKeyInfo>
284285
Console.WriteLine "Pushing..."
285286
commitsToPush
286287
| Some numberOfCommits -> GetLastCommits numberOfCommits

scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ let validExtensions =
2121

2222
let invalidFiles =
2323
validExtensions
24-
|> Seq.map(fun ext ->
24+
|> Seq.collect(fun ext ->
2525
Helpers.GetInvalidFiles
2626
rootDir
2727
("*" + ext)
2828
FileConventions.NonVerboseFlags
2929
)
30-
|> Seq.concat
3130

3231
let message = "Please don't use non-verbose flags in the following files:"
3332

scripts/runFSharpLint.fsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ let targetSolution =
5757
| None ->
5858
let solFiles = Directory.GetFiles(targetDir.FullName, "*.sln")
5959

60+
let getMultipleSolutionsFoundErrorMessage dirName =
61+
sprintf
62+
"Multiple solution files found in %s; please specify one as an argument"
63+
dirName
64+
6065
if solFiles.Length = 0 then
6166
let solFiles = Directory.GetFiles(fallbackDir.FullName, "*.sln")
6267

@@ -66,11 +71,11 @@ let targetSolution =
6671
targetDir.FullName
6772
fallbackDir.FullName
6873
elif solFiles.Length > 1 then
69-
failwithf
70-
"Multiple solution files found in %s; please specify one as an argument"
71-
fallbackDir.FullName
74+
failwith(
75+
getMultipleSolutionsFoundErrorMessage fallbackDir.FullName
76+
)
7277
else
73-
let solFile = solFiles.[0] |> FileInfo
78+
let solFile = FileInfo solFiles.[0]
7479

7580
printfn
7681
"Using solution file %s from target directory %s"
@@ -79,11 +84,9 @@ let targetSolution =
7984

8085
solFile
8186
elif solFiles.Length > 1 then
82-
failwithf
83-
"Multiple solution files found in %s; please specify one as an argument"
84-
targetDir.FullName
87+
failwith(getMultipleSolutionsFoundErrorMessage targetDir.FullName)
8588
else
86-
let solFile = solFiles.[0] |> FileInfo
89+
let solFile = FileInfo solFiles.[0]
8790

8891
printfn
8992
"Using solution file %s from target directory %s"

0 commit comments

Comments
 (0)