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 ac6aeb7
Showing
1 changed file
with
64 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,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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
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.
Sorry, something went wrong.
knocte
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)