forked from nblockchain/conventions
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts/detectNotUsingGitPush1by1: add
- Loading branch information
1 parent
3a75658
commit 8cac35f
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/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 gitRepo = Environment.GetEnvironmentVariable "GITHUB_REPOSITORY" | ||
|
||
if gitRepo = null then | ||
failwith "You shouldn't use this script outside CI." | ||
|
||
let currentBranch = | ||
Fsdk | ||
.Process | ||
.Execute( | ||
{ | ||
Command = "git" | ||
Arguments = "rev-parse --abbrev-ref HEAD" | ||
}, | ||
Fsdk.Process.Echo.Off | ||
) | ||
.UnwrapDefault() | ||
.Trim() | ||
|
||
let prCommits = | ||
Fsdk | ||
.Process | ||
.Execute( | ||
{ | ||
Command = "git" | ||
Arguments = | ||
sprintf "rev-list %s~..%s" currentBranch currentBranch | ||
}, | ||
Fsdk.Process.Echo.Off | ||
) | ||
.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" | ||
gitRepo | ||
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.\n" | ||
+ "You may use this script:\n" | ||
+ "https://github.com/nblockchain/fsx/blob/master/Tools/gitPush1by1.fsx" | ||
) |