fleet/tools/oncall/oncall.sh
Andrew Mellor e64bc837bd
Update oncall.sh to exclude app/kilo-code-bot (#44474)
Added app/kilo-code-bot exclude

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

* **Chores**
* Updated internal tooling to recognize an additional bot account in
pull request filtering processes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-01 17:03:53 +01:00

92 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# Script for on-call use.
# Formatted with shfmt. See https://github.com/mvdan/sh
set -euo pipefail
usage() {
cat <<EOF
Contains useful commands for on-call.
Usage:
$(basename "$0") <command>
Commands:
issues List open issues from outside contributors.
prs List open prs from outside contributors.
EOF
}
require() {
type "$1" >/dev/null 2>&1 || {
echo "$1 is required but not installed. Aborting." >&2
exit 1
}
}
ensure_gh_auth() {
auth_status="$(gh auth status -t 2>&1 || true)"
if echo "$auth_status" | grep -q "You are not logged into any GitHub hosts."; then
echo "$auth_status" >&2
exit 1
fi
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')"
if [ -z "${username}" ] || [ -z "${token}" ]; then
echo "Failed to parse GitHub auth status. Try: gh auth login" >&2
exit 1
fi
}
issues() {
require gh
require jq
ensure_gh_auth
members="$(curl -s -u "${username}:${token}" https://api.github.com/orgs/fleetdm/members?per_page=100 | jq -r 'map(.login)')"
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 | .[] | [(.url | split("/") | last), .createdAt, .author.login, .title] | @tsv'
}
prs() {
require gh
require jq
ensure_gh_auth
members="$(curl -s -u "${username}:${token}" https://api.github.com/orgs/fleetdm/members?per_page=100 | jq -r 'map(.login) + ["app/dependabot", "app/kiloconnect", "app/kilo-code-bot"]')"
# defaults to listing open prs
gh pr list --limit 1000 --repo fleetdm/fleet --json id,title,author,url,createdAt,isDraft |
jq -r --argjson members "$members" \
'map(select((.author.login as $login | ($members | index($login)) == null) and .isDraft == false)) | sort_by(.createdAt) | reverse | .[] | [(.url | split("/") | last), .createdAt, .author.login, .title] | @tsv'
}
# check for at least one argument
if [ "$#" -lt 1 ]; then
echo -e "No command provided.\n"
usage
exit 1
fi
# main script
case "$1" in
issues)
issues
;;
prs)
prs
;;
-h | --help)
usage
exit 0
;;
*)
echo "Invalid argument: $1"
usage
exit 1
;;
esac