You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.0 KiB
Plaintext

8 months ago
# notify when the latest ci pipeline completes
export def notify [] {
while (info | get status) in ["running", "queued"] {
8 months ago
sleep 1sec;
};
let name = ($env.PWD | path basename)
notify-send $"CI ($name)" $"Job (info | get conclusion)"
8 months ago
}
export def watch [] {
loop {
while (info | get status) != "running" {
sleep 10sec;
}
notify
}
}
export def info [] {
if (get-ci) == "gitlab" {
return (glab ci get -F json | from json | {
conclusion: $in.status,
exists: true,
...$in
})
} else if (get-ci) == "github" {
use git.nu
let branch = (git gb | where current == true | first | get branch)
let info = (gh run list --json conclusion,name,startedAt,status,number,headBranch | from json | where headBranch == $branch | get -i 0 )
if $info != null {
return {
id: $info.number,
name: $info.name,
conclusion: $info.conclusion,
status: (match $info.status {
"in_progress" => {"running"},
"completed" => { $info.conclusion }
_ => $info.status
}),
exists: true,
}
}
8 months ago
}
({
id: null,
name: null,
status: null,
conclusion: null,
exists: false,
})
8 months ago
}
# notify in background
export def notify-bg [] {
use task.nu
8 months ago
task spawn -i -l "ci-notify" -g (task-group) {
8 months ago
ci notify
}
}
export def watch-bg [] {
use task.nu
8 months ago
task spawn -l "ci-watch" -g (task-group) {
while (ci info | get status) != "running" {
sleep 10sec;
}
notify-send $"CI (ci info | get id)" "Job started"
8 months ago
ci notify
ci watch-bg
8 months ago
}
}
export def get-ci [] {
let remote = (git remote get-url --all origin)
if ($remote | str contains gitlab) {
"gitlab"
} else if ($remote | str contains github.com) {
"github"
}
}
8 months ago
def task-group [] {
let name = ($env.PWD | path basename)
let groupname = $"ci-($name)"
if not ($groupname in ...(task group | columns)) {
task group add $groupname -p 4
}
$groupname
}