Repository navigation
scripts/nexus-audit.sh - #803
Closed
Aissamohammedi88 wants to merge 1 commit into
Closed
Aissamohammedi88 wants to merge 1 commit into
Aissamohammedi88 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#!/usr/bin/env bash
═══════════════════════════════════════════════════════════════════════════════
Nexus triage audit — read-only, uses GitHub REST API
Usage : ./nexus-audit.sh <owner/repo> [state]
Deps : curl, jq
═══════════════════════════════════════════════════════════════════════════════
set -euo pipefail
readonly API="https://api.github.com"
readonly UA="Nexus-Triage-Audit/1.0"
TOKEN="${GITHUB_TOKEN:-}"
REPO="${1:?Usage: $0 <owner/repo> [state]}"
STATE="${2:-open}"
[[ -n "$TOKEN" ]] || { echo "GITHUB_TOKEN required" >&2; exit 1; }
gh_get() {
curl -s -H "Accept: application/vnd.github+json"
-H "Authorization: Bearer $TOKEN"
-H "User-Agent: $UA"
--max-time 30
"$API$1"
}
fetch_all() {
local page=1 all="[]"
while (( page <= 10 )); do
local batch
batch=$(gh_get "/repos/$REPO/issues?state=$STATE&per_page=100&page=$page")
local n; n=$(echo "$batch" | jq 'if type == "array" then length else 0 end')
(( n == 0 )) && break
all=$(echo "$all" "$batch" | jq -s 'add')
(( n < 100 )) && break
((page++))
done
echo "$all" | jq '[.[] | select(.pull_request == null)]'
}
issues=$(fetch_all)
total=$(echo "$issues" | jq 'length')
if (( total == 0 )); then
echo "No open issues."
exit 0
fi
no_label=$(echo "$issues" | jq '[.[] | select((.labels | length) == 0)] | length')
no_assignee=$(echo "$issues" | jq '[.[] | select(.assignee == null)] | length')
no_comments=$(echo "$issues" | jq '[.[] | select(.comments == 0)] | length')
one_year_ago=$(date -u -d '1 year ago' +%Y-%m-%dT%H:%M:%SZ 2>/dev/null
|| date -u -v-1y +%Y-%m-%dT%H:%M:%SZ)
stale=$(echo "$issues" | jq --arg d "$one_year_ago"
'[.[] | select(.created_at < $d)] | length')
echo "═══════════════════════════════════════════════════════════════════════════"
echo " NEXUS AUDIT : $REPO (State: $STATE)"
echo "═══════════════════════════════════════════════════════════════════════════"
echo
echo "▶ FACTS"
echo "───────────────────────────────────────────────────────────────────────────"
printf " %-24s %s\n" "Open issues:" "$total"
printf " %-24s %s\n" "Without labels:" "$no_label"
printf " %-24s %s\n" "Without assignee:" "$no_assignee"
printf " %-24s %s\n" "Without any reply:" "$no_comments"
printf " %-24s %s\n" "Stale (> 1 year):" "$stale"
echo
echo " Top labels:"
echo "$issues" | jq -r '
[.[] | .labels[].name]
| group_by(.)
| map({label: .[0], count: length})
| sort_by(-.count) | .[0:5]
| .[] | " - (.label) ((.count))"
'
echo
echo "▶ RECOMMENDATIONS"
echo "───────────────────────────────────────────────────────────────────────────"
(( no_label > 0 )) && echo " [P1] $no_label issue(s) without labels — apply taxonomy."
(( stale > 0 )) && echo " [P1] $stale issue(s) stale (>1y) — close or relabel 'stale'."
(( no_assignee > 0 )) && echo " [P2] $no_assignee issue(s) unassigned — assign maintainer."
(( no_comments > 0 )) && echo " [P2] $no_comments issue(s) unanswered — acknowledge."
echo
echo "▶ OLDEST 5"
echo "───────────────────────────────────────────────────────────────────────────"
echo "$issues" | jq -r '
sort_by(.created_at) | .[0:5] | .[]
| " #(.number) (.created_at | split("T")[0]) (.title[0:70])"
'