Skip to content

Commit

Permalink
Move and fix oncall.sh script (#18217)
Browse files Browse the repository at this point in the history
In the future we can create automation to send reminders to a Slack
channel. Or send the list every time there's a oncall changeover.
  • Loading branch information
lucasmrod committed Apr 11, 2024
1 parent c917ac3 commit 598dfa3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 8 additions & 0 deletions tools/oncall/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Oncall

You can use the `oncall.sh` script to find out if there are any open issues or PRs from the community:
```sh
gh auth login
./tools/oncall/oncall.sh issues
./tools/oncall/oncall.sh prs
```
15 changes: 8 additions & 7 deletions scripts/on-call → tools/oncall/oncall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ usage() {
Contains useful commands for on-call.
Usage:
$(basename $0) <command>
$(basename "$0") <command>
Commands:
issues List open issues from outside contributors.
Expand All @@ -18,7 +18,7 @@ EOF
}

require() {
type $1 >/dev/null 2>&1 || {
type "$1" >/dev/null 2>&1 || {
echo "$1 is required but not installed. Aborting." >&2
exit 1
}
Expand All @@ -29,12 +29,12 @@ issues() {
require jq

auth_status="$(gh auth status -t 2>&1)"
username="$(echo "${auth_status}" | sed -n -r 's/^.* Logged in to [^[:space:]]+ as ([^[:space:]]+).*/\1/p')"
username="$(echo "${auth_status}" | sed -n -r 's/^.* Logged in to github.com account ([^[:space:]]+).*/\1/p')"
token="$(echo "${auth_status}" | sed -n -r 's/^.*Token: ([a-zA-Z0-9_]*)/\1/p')"

members="$(curl -s -u "${username}:${token}" https://api.github.com/orgs/fleetdm/members | jq -r 'map(.login)')"
members="$(curl -s -u "${username}:${token}" https://api.github.com/orgs/fleetdm/members?per_page=100 | jq -r 'map(.login)')"

gh pr list --repo fleetdm/fleet --label "bug" --label ":reproduce" --json id,title,author,url,createdAt |
gh issue list --repo fleetdm/fleet --json id,title,author,url,createdAt,labels --limit 100 |
jq -r --argjson members "$members" \
'map(select(.author.login as $in | $members | index($in) | not)) | sort_by(.createdAt) | reverse'
}
Expand All @@ -44,10 +44,11 @@ prs() {
require jq

auth_status="$(gh auth status -t 2>&1)"
username="$(echo "${auth_status}" | sed -n -r 's/^.* Logged in to [^[:space:]]+ as ([^[:space:]]+).*/\1/p')"
username="$(echo "${auth_status}" | sed -n -r 's/^.* Logged in to github.com account ([^[:space:]]+).*/\1/p')"
token="$(echo "${auth_status}" | sed -n -r 's/^.*Token: ([a-zA-Z0-9_]*)/\1/p')"

members="$(curl -s -u "${username}:${token}" https://api.github.com/orgs/fleetdm/members | jq -r 'map(.login)')"
members="$(curl -s -u "${username}:${token}" https://api.github.com/orgs/fleetdm/members?per_page=100 | jq -r 'map(.login)' | jq '. += ["app/dependabot"]')"

# defaults to listing open prs
gh pr list --repo fleetdm/fleet --json id,title,author,url,createdAt |
jq -r --argjson members "$members" \
Expand Down

0 comments on commit 598dfa3

Please sign in to comment.