Skip to content

Commit

Permalink
scripts/detectNotUsingGitPush1by1: add
Browse files Browse the repository at this point in the history
  • Loading branch information
tehraninasab committed Mar 15, 2023
1 parent 3a75658 commit ac6aeb7
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions scripts/detectNotUsingGitPush1by1.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env -S dotnet fsi

open System
open System.Net.Http
open System.Net.Http.Headers

#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"

let currentBranch =

This comment has been minimized.

Copy link
@knocte

knocte Mar 15, 2023

Collaborator

@realmarv actually, the very first thing that this script should do, is retreive the env var GITHUB_REPOSITORY, and if it's empty or not null, it should failwith (in case someone has the stupid idea to run this outside CI)

This comment has been minimized.

Copy link
@tehraninasab

tehraninasab Mar 15, 2023

Author Owner

Done

Fsdk
.Process
.Execute(
{
Command = "git"
Arguments = "rev-parse --abbrev-ref HEAD"
},
Fsdk.Process.Echo.All
)
.UnwrapDefault()
.Trim()

let prCommits =
Fsdk
.Process
.Execute(
{
Command = "git"
Arguments =
sprintf "rev-list %s~..%s" currentBranch currentBranch
},
Fsdk.Process.Echo.All
)
.UnwrapDefault()
.Trim()
.Split "\n"
|> Seq.tail

let notUsingGitPush1by1 =
prCommits
|> Seq.map(fun commit ->
use client: HttpClient = new HttpClient()
client.DefaultRequestHeaders.Accept.Clear()

client.DefaultRequestHeaders.Accept.Add(
MediaTypeWithQualityHeaderValue "application/vnd.github+json"
)

client.DefaultRequestHeaders.Add("User-Agent", ".NET App")
client.DefaultRequestHeaders.Add("X-GitHub-Api-Version", "2022-11-28")

let url =
sprintf
"https://api.github.com/repos/%s/commits/%s/check-suites"
(Environment.GetEnvironmentVariable("GITHUB_REPOSITORY"))

This comment has been minimized.

Copy link
@knocte

knocte Mar 15, 2023

Collaborator

@realmarv nit: the above line only needs 2 parens, not 4

This comment has been minimized.

Copy link
@tehraninasab

tehraninasab Mar 15, 2023

Author Owner

Done

commit

let json = client.GetStringAsync(url).Result

json.Contains "\"check_suites\":[]"
)
|> Seq.contains true

if notUsingGitPush1by1 then
failwith "Please push the commits one by one."

This comment has been minimized.

Copy link
@knocte

knocte Mar 15, 2023

Collaborator

@realmarv please include the URL of the handy script that allows to do this

This comment has been minimized.

Copy link
@tehraninasab

tehraninasab Mar 15, 2023

Author Owner

Done. Should I add an instruction on how to use that script?

0 comments on commit ac6aeb7

Please sign in to comment.