Skip to content
Snippets Groups Projects
Commit b7e2d99d authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

add a script to check the GitHub mirror (!199)

## usage
```bash
nu scripts/check-mirror.nu ...[
    https://gitlab.isae-supaero.fr/dragoon/komodo
    https://github.com/dragoon-rs/komodo
    main
]
```
will
- check the Nushell version and throw a warning if mismatch
- add temporary remotes with random names
- fetch the temporary remotes
- get the revision of the `$branch` for both temporary remotes
- clean the temporary remotes
- show a message if the two revisions are not the same and how many commits they are different

> **Note**
>
> this does not conflict with #17
parent b5381fda
No related branches found
No related tags found
1 merge request!199add a script to check the GitHub mirror
Pipeline #8238 passed
REVISION: 1aa2ed1947a0b891398558fcf4e4289849cc5a1d
VERSION: 0.102.0
def "str color" [color: string]: [ string -> string ] {
$"(ansi $color)($in)(ansi reset)"
}
def __log [level: string, color: string, msg: string] {
print $"[(ansi $color)($level)(ansi reset)] ($msg)"
}
def "log error" [msg: string] { __log "ERR" "red" $msg }
def "log info" [msg: string] { __log "INF" "cyan" $msg }
def "log ok" [msg: string] { __log " OK" "green" $msg }
let config = open .nu.cfg
| lines
| parse "{key}: {value}"
| transpose --header-row
| into record
if (version).commit_hash != $config.REVISION or (version).version != $config.VERSION {
print --stderr $"(ansi yellow_bold)Warning(ansi reset): unexpected version"
print --stderr $" expected (ansi green)($config.VERSION)@($config.REVISION)(ansi reset)"
print --stderr $" found (ansi red)((version).version)@((version).commit_hash)(ansi reset)"
}
def main [base: string, mirror: string, branch: string] {
let base_remote = random uuid
let mirror_remote = random uuid
log info "adding remotes"
git remote add $base_remote $base
git remote add $mirror_remote $mirror
log info "fetching"
git fetch --quiet $base_remote
git fetch --quiet $mirror_remote
let base = git rev-parse $"($base_remote)/($branch)" | str trim
let mirror = git rev-parse $"($mirror_remote)/($branch)" | str trim
log info "cleaning"
git remote remove $base_remote
git remote remove $mirror_remote
if $base != $mirror {
let hist = git rev-list $"($mirror)..($base)" | lines
log error "mirror is out of date"
{
b: ($base | str substring 0..<7),
m: ($mirror | str substring 0..<7),
h: ($hist | length),
}
| print $" ($in.b | str color green) | ($in.m | str color red) \(($in.h) commits behind\)"
} else {
log ok "mirror is up to date"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment