Skip to content

Commit e53215c

Browse files
committed
detect repo automatically
1 parent d4e8397 commit e53215c

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ gh extension install skshetry/gh-cancel-runs
1212
## Usage
1313

1414
```
15-
gh cancel-runs <owner>/<repo>
15+
gh cancel-runs [<owner>/<repo>]
1616
```

gh-cancel-runs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
#!/bin/bash
22
if [ $# -eq 0 ]
33
then
4-
echo "Usage: gh cancel-runs <owner>/<name>"
5-
exit 1
4+
repo=$(gh repo view --json=nameWithOwner --jq ".nameWithOwner" | tee)
5+
echo "Using repo: $repo"
6+
else
7+
repo=$1
68
fi
79

810
# from: https://stackoverflow.com/a/60766849/5693170
911
# modified to be used as a gh extension to avoid specifying tokens
1012

1113
# Using tee to disable pager
12-
ids=($(gh api repos/$1/actions/runs --jq \
14+
ids=($(gh api repos/$repo/actions/runs --jq \
1315
'.workflow_runs[] | select([.status] | inside(["in_progress", "queued"])) | .id' \
1416
| tee))
1517

18+
if [ ${#ids[@]} -eq 0 ]; then
19+
echo "No scheduled runs to cancel."
20+
exit
21+
fi
22+
1623
for id in $ids
1724
do
1825
echo "Cancelling $id"
19-
gh api -X POST repos/$1/actions/runs/$id/cancel | tee
26+
gh api -X POST repos/$repo/actions/runs/$id/cancel | tee
2027
done
2128
echo

0 commit comments

Comments
 (0)