-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdwr
More file actions
executable file
·96 lines (70 loc) · 1.73 KB
/
dwr
File metadata and controls
executable file
·96 lines (70 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
# Delete workflow runs - dwr
# Given an "owner/repo" name, such as "qmacro/thinking-aloud",
# retrieve the workflow runs for that repo and present them in a
# list. Selected runs will be deleted. Uses the GitHub API.
# Requires gh (GitHub CLI) and jq (JSON processor)
set -o errexit
set -o pipefail
# Load common functions
readonly here="$(dirname "$0")"
source "$here/github.sh"
declare repo hostname
jqscript() {
/bin/cat << EOF
def symbol:
sub("skipped"; "SKIP") |
sub("success"; "GOOD") |
sub("failure"; "FAIL");
def tz:
gsub("[TZ]"; " ");
.workflow_runs[]
| [
(.conclusion | symbol),
(.created_at | tz),
.id,
.event,
.name
]
| @tsv
EOF
}
selectruns() {
gh --hostname "$hostname" api --paginate "/repos/$repo/actions/runs" \
| jq -r -f <(jqscript) \
| fzf --multi --reverse
}
deleterun() {
local run id result
run=$1
id="$(cut -f 3 <<< "$run")"
gh --hostname "$hostname" api -X DELETE "/repos/$repo/actions/runs/$id" \
&& result="OK!" \
|| result="BAD"
printf "%s\t%s\n" "$result" "$run"
}
deleteruns() {
local id
while read -r run; do
deleterun "$run"
sleep 0.25
done
}
main() {
if [[ -n $1 ]]; then
# If owner/repo passed as argument, take that, assume github.com.
repo=$1
hostname=github.com
else
# Otherwise assume we're in a git repo, so use the placeholders
# and grab the hostname from the origin remote.
if ! git status > /dev/null 2>&1; then
echo "No repo specified and not in a repo dir"
exit 1
fi
repo=':owner/:repo'
hostname="$(get_hostname)"
fi
selectruns | deleteruns
}
main "$@"