Skip to content

Commit 3aef4d5

Browse files
authored
fix: avoid stalled maintainer author activity lookups (#130724)
* fix: avoid stalled maintainer author activity lookups * test: validate required author activity fixture entries
1 parent 92d81bd commit 3aef4d5

3 files changed

Lines changed: 385 additions & 202 deletions

File tree

‎.agents/skills/openclaw-pr-maintainer/SKILL.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,20 @@ gh api -X POST "repos/openclaw/openclaw/issues/<number>/assignees" -f 'assignees
9393
- For every reviewed, triaged, closed, or landed issue/PR, show the opener's human name when available, GitHub login, and account age.
9494
- Get the login from `gh issue view` / `gh pr view` (`author.login`), then fetch profile metadata once with `gh api users/<login> --jq '{login,name,created_at,type}'`.
9595
- Report opener identity as one compact line:
96-
`By: Jane Doe (@jane, acct 2021-04-03) | OpenClaw: 4 PRs, 2 issues, 11 commits/12mo | GitHub: 9 repos, 86 commits, 9 PRs, 3 issues, 12 reviews`
97-
- Always show recent activity in two lanes: OpenClaw-local PRs, issues, and commits in the last 12 months; and general public GitHub activity over the same window. For linked issue-fixing PRs, include both the PR author and issue opener when they differ.
96+
`By: Jane Doe (@jane, acct 2021-04-03) | OpenClaw: 4 PRs, 2 issues, 11 commits/12mo | GitHub contributions: 86 commits, 9 PRs, 3 issues, 12 reviews/12mo`
97+
- Show activity in two separate lanes: repo search totals for authored PRs/issues and commits, and GitHub contribution-graph totals. State each interval; neither lane is an exhaustive activity history. For linked issue-fixing PRs, include both the PR author and issue opener when they differ.
9898
- Prefer the bundled helper for activity lookups:
9999

100100
```bash
101101
.agents/skills/openclaw-pr-maintainer/scripts/github-activity.sh <login> [other-login...]
102102
.agents/skills/openclaw-pr-maintainer/scripts/github-activity.sh --global <login>
103103
```
104104

105-
- The helper reports repo-local activity first and can fetch public GitHub contribution totals for the same window with `--global`; run the global form by default for review/triage identity summaries.
106-
- If the global contribution graph reports zero or looks inconsistent with visible public activity, sanity-check with `gh api users/<login>`, `gh api 'users/<login>/events/public?per_page=100'`, and recent public repo commits before calling the account inactive.
107-
- The helper is intentionally cache-friendly for gitcrawl-backed `gh`: it rounds repo-local windows to the UTC day, rounds global contribution windows to the UTC hour, and counts PRs/issues from one paginated issues response before fetching commits separately. Prefer reusing the helper instead of hand-rolling several `gh api` loops.
108-
- If the contribution graph is misleading or zero but public events/repos show activity, keep it one line, for example:
109-
`By: pickaxe (@ProspectOre, acct 2019-08-24) | OpenClaw: 5 PRs, 0 issues, 5 commits/12mo | GitHub: 5 repos, 29 recent events, 100 public own-repo commits; graph=0`
105+
- Run `--global` by default for review/triage identity summaries. The helper prints canonical profile identity before requesting activity, then makes three single-page REST searches (`per_page=1`) for repo totals and one optional GraphQL contribution aggregate: at most five `gh` calls per resolved login, independent of activity volume. It uses `total_count`, never fetched row counts or pagination.
106+
- Keep bare PATH `gh` with native `--cache 1h` for profile, search, and GraphQL reads. Octopool delegates author/date-filtered searches and GraphQL, so bare `gh` alone does not guarantee fleet-cache coverage. Native caching keeps repeated lookups bounded without a custom store; do not source `plain-gh.sh`, force fresh reads, or query private cache databases.
107+
- Windows use completed UTC days with calendar-month subtraction clamped at month ends. Repo search uses PR/issue creation time and default-branch commit committer date. `--months` controls the repo interval; global contributions cap at 12 months because GitHub accepts at most one year. The helper prints both intervals and explicitly labels a global cap for longer requests.
108+
- Search totals reflect GitHub's index and may be cached or lag recent changes. Printed intervals are query bounds, not proof of live freshness. Incomplete search results, malformed/missing data, request failures, and unresolved identity are not zero. The helper labels those outcomes, continues later logins, and exits nonzero if identity or requested activity is unavailable or incomplete.
109+
- Contribution totals follow GitHub's contribution rules and token visibility; they may include private repositories. Do not call them public-only or infer inactivity from a zero graph. Do not automatically scan events or repositories as a fallback; report the limitation and inspect specific evidence separately only when needed.
110110
- If `name` is empty, use the login only. If profile lookup is rate-limited or unavailable, say `account age unknown` rather than omitting the opener.
111111
- Use identity and activity as triage signal, not proof by itself: new, low-activity, or bot-like accounts can raise review caution, but code, repro, and CI evidence still decide.
112112

‎.agents/skills/openclaw-pr-maintainer/scripts/github-activity.sh‎

Lines changed: 98 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ set -euo pipefail
44
repo="openclaw/openclaw"
55
months="12"
66
include_global="0"
7-
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8-
repo_root="$(git -C "$script_dir/../../../.." rev-parse --show-toplevel 2>/dev/null || true)"
9-
if [ -z "$repo_root" ]; then
10-
repo_root="$(cd "$script_dir/../../../.." && pwd)"
11-
fi
12-
13-
# shellcheck disable=SC1091
14-
source "$repo_root/scripts/lib/plain-gh.sh"
157

168
usage() {
179
printf 'Usage: %s [--repo owner/repo] [--months N] [--global] <github-login> [login...]\n' "$0"
@@ -22,86 +14,54 @@ die() {
2214
exit 1
2315
}
2416

25-
need() {
26-
command -v "$1" >/dev/null 2>&1 || die "missing required command: $1"
27-
}
28-
29-
gh() {
30-
gh_plain "$@"
31-
}
32-
33-
date_utc_relative_months() {
34-
local count="$1"
35-
if date -u -v-"${count}"m +%Y-%m-%dT00:00:00Z >/dev/null 2>&1; then
36-
date -u -v-"${count}"m +%Y-%m-%dT00:00:00Z
37-
return
17+
search_count() {
18+
local endpoint="$1" query="$2" response count
19+
query=$(jq -rn --arg q "$query" '$q | @uri')
20+
# Native gh caching also covers author/date searches the fleet shim delegates.
21+
if ! response=$(gh api "search/${endpoint}?q=${query}&per_page=1" --cache 1h 2>/dev/null); then
22+
printf 'unavailable (request failed)'
23+
return 1
3824
fi
39-
date -u -d "${count} months ago" +%Y-%m-%dT00:00:00Z
40-
}
41-
42-
date_to_epoch() {
43-
local value="$1"
44-
if date -u -j -f '%Y-%m-%dT%H:%M:%SZ' "$value" +%s >/dev/null 2>&1; then
45-
date -u -j -f '%Y-%m-%dT%H:%M:%SZ' "$value" +%s
46-
return
25+
if ! count=$(jq -er '
26+
if type == "object" and
27+
(.total_count | type == "number" and . >= 0 and . == floor) and
28+
(.incomplete_results | type == "boolean") then
29+
if .incomplete_results then "incomplete (reported \(.total_count))"
30+
else .total_count | tostring end
31+
else error("invalid search aggregate") end' <<<"$response" 2>/dev/null); then
32+
printf 'unavailable (invalid response)'
33+
return 1
4734
fi
48-
date -u -d "$value" +%s
49-
}
50-
51-
rough_age() {
52-
local created_at="$1"
53-
local now_s created_s days
54-
now_s=$(date -u +%s)
55-
created_s=$(date_to_epoch "$created_at")
56-
days=$(( (now_s - created_s) / 86400 ))
57-
if (( days < 120 )); then
58-
printf '~%dd old' "$days"
59-
return
60-
fi
61-
awk -v days="$days" 'BEGIN { printf "~%.1fy old", days / 365.2425 }'
62-
}
63-
64-
thread_kinds() {
65-
local login="$1"
66-
local since_ts="$2"
67-
gh api --paginate "repos/${repo}/issues?state=all&creator=${login}&since=${since_ts}&per_page=100" \
68-
--jq ".[] | select(.created_at >= \"${since_ts}\") | if has(\"pull_request\") then \"pr\" else \"issue\" end"
69-
}
70-
71-
count_kind_lines() {
72-
local kind="$1"
73-
local lines="$2"
74-
grep -cx "$kind" <<<"$lines" 2>/dev/null || true
75-
}
76-
77-
count_commits() {
78-
local login="$1"
79-
local since_ts="$2"
80-
gh api --paginate "repos/${repo}/commits?author=${login}&since=${since_ts}&per_page=100" \
81-
--jq '.[].sha' | wc -l | tr -d '[:space:]'
35+
printf '%s' "$count"
36+
[[ "$count" != incomplete* ]]
8237
}
8338

8439
global_activity() {
85-
local login="$1"
86-
local since_ts="$2"
87-
local now_ts="$3"
40+
local login="$1" response
41+
# GraphQL may use the real CLI via the shim, but remains one aggregate request.
8842
# shellcheck disable=SC2016
89-
gh api graphql \
90-
-f login="$login" \
91-
-f from="$since_ts" \
92-
-f to="$now_ts" \
93-
-f query='
94-
query($login: String!, $from: DateTime!, $to: DateTime!) {
95-
user(login: $login) {
96-
contributionsCollection(from: $from, to: $to) {
97-
totalCommitContributions
98-
totalIssueContributions
99-
totalPullRequestContributions
100-
totalPullRequestReviewContributions
43+
if ! response=$(gh api graphql --cache 1h -f login="$login" -f from="$global_from" -f to="$global_to" \
44+
-f query='query($login: String!, $from: DateTime!, $to: DateTime!) {
45+
user(login: $login) { contributionsCollection(from: $from, to: $to) {
46+
totalCommitContributions totalIssueContributions
47+
totalPullRequestContributions totalPullRequestReviewContributions
48+
} }
49+
}' 2>/dev/null); then
50+
printf 'unavailable (request failed)\n'
51+
return 1
52+
fi
53+
jq -er '
54+
if (.errors // [] | length) > 0 then error("GraphQL errors") else
55+
.data.user.contributionsCollection |
56+
[.totalCommitContributions, .totalPullRequestContributions,
57+
.totalIssueContributions, .totalPullRequestReviewContributions] |
58+
if all(.[]; type == "number" and . >= 0 and . == floor) then
59+
"\(.[0]) commits, \(.[1]) PRs, \(.[2]) issues, \(.[3]) reviews"
60+
else error("invalid contribution aggregate") end
61+
end' <<<"$response" 2>/dev/null || {
62+
printf 'unavailable (invalid response)\n'
63+
return 1
10164
}
102-
}
103-
}' \
104-
--jq '.data.user.contributionsCollection // empty'
10565
}
10666

10767
while [[ $# -gt 0 ]]; do
@@ -114,7 +74,7 @@ while [[ $# -gt 0 ]]; do
11474
--months)
11575
[[ $# -ge 2 ]] || die "--months requires a positive integer"
11676
months="$2"
117-
[[ "$months" =~ ^[0-9]+$ && "$months" != "0" ]] || die "--months must be a positive integer"
77+
[[ "$months" =~ ^[1-9][0-9]*$ ]] || die "--months must be a positive integer"
11878
shift 2
11979
;;
12080
--global)
@@ -129,63 +89,68 @@ while [[ $# -gt 0 ]]; do
12989
shift
13090
break
13191
;;
132-
-*)
133-
die "unknown option: $1"
134-
;;
135-
*)
136-
break
137-
;;
92+
-*) die "unknown option: $1" ;;
93+
*) break ;;
13894
esac
13995
done
14096

141-
[[ $# -gt 0 ]] || {
142-
usage >&2
143-
exit 2
144-
}
145-
146-
OPENCLAW_GH_BIN="$(resolve_plain_gh_bin)" || die "missing required command: gh"
147-
export OPENCLAW_GH_BIN
148-
need jq
149-
150-
since_ts=$(date_utc_relative_months "$months")
151-
now_ts=$(date -u +%Y-%m-%dT%H:00:00Z)
97+
[[ $# -gt 0 ]] || { usage >&2; exit 2; }
98+
[[ "$repo" =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ ]] || die "--repo requires owner/repo"
99+
for command in gh jq; do
100+
command -v "$command" >/dev/null 2>&1 || die "missing required command: $command"
101+
done
152102

103+
# Use completed UTC days and clamp calendar subtraction at month ends on both OSes.
104+
# The contribution API accepts at most one year; never relabel that as the repo range.
105+
clock=$(date -u +%s)
106+
windows=$(jq -nr --argjson clock "$clock" --argjson months "$months" '
107+
def iso: strftime("%Y-%m-%dT%H:%M:%SZ");
108+
($clock | gmtime | .[3:6] = [0,0,0]) as $end |
109+
def ago($n):
110+
($end[0] * 12 + $end[1] - $n) as $month |
111+
[($month / 12 | floor), ($month % 12), 1, 0, 0, 0, 0, 0] as $first |
112+
if $first[0] < 1 then error("unsupported date range") else
113+
($first | .[1] += 1 | mktime - 86400 | gmtime | .[2]) as $last |
114+
$first | .[2] = ([$end[2], $last] | min) | mktime | iso
115+
end;
116+
[$months, 12] | min as $global |
117+
[ago($months), ($end | mktime - 1 | iso), ago($global),
118+
($end | mktime | iso), $global] | @tsv') || die "unsupported --months range"
119+
IFS=$'\t' read -r repo_from repo_to global_from global_to global_months <<<"$windows"
120+
failed=0
153121
for login in "$@"; do
154-
profile=$(gh api "users/${login}" --jq '{login,name,created_at,type}')
155-
display_login=$(jq -r '.login' <<<"$profile")
156-
name=$(jq -r '.name // empty' <<<"$profile")
157-
created_at=$(jq -r '.created_at' <<<"$profile")
158-
type=$(jq -r '.type' <<<"$profile")
159-
created_day=${created_at%%T*}
160-
161-
kinds=$(thread_kinds "$display_login" "$since_ts")
162-
prs=$(count_kind_lines pr "$kinds")
163-
issues=$(count_kind_lines issue "$kinds")
164-
commits=$(count_commits "$display_login" "$since_ts")
165-
166-
if [[ -n "$name" ]]; then
167-
printf '%s (@%s, %s, account created %s, %s)\n' \
168-
"$name" "$display_login" "$type" "$created_day" "$(rough_age "$created_at")"
169-
else
170-
printf '@%s (%s, account created %s, %s)\n' \
171-
"$display_login" "$type" "$created_day" "$(rough_age "$created_at")"
122+
[[ "$login" =~ ^[A-Za-z0-9_-]+(\[bot\])?$ ]] || {
123+
printf '@%s (invalid login; account age unknown)\n' "$login"
124+
failed=1
125+
continue
126+
}
127+
if ! profile=$(gh api "users/${login}" --cache 1h --jq '{login,name,created_at,type}' 2>/dev/null) ||
128+
! display_login=$(jq -er '.login | select(type == "string" and test("^[A-Za-z0-9_-]+(\\[bot\\])?$"))' <<<"$profile" 2>/dev/null); then
129+
printf '@%s (profile unavailable; account age unknown)\n' "$login"
130+
printf 'Activity unavailable (identity not resolved)\n'
131+
failed=1
132+
continue
172133
fi
173-
printf '%s last %smo: %s PRs, %s issues, %s commits\n' "$repo" "$months" "$prs" "$issues" "$commits"
174-
134+
# Identity is useful even if the very next activity request stalls or fails.
135+
jq -r --argjson clock "$clock" '
136+
(if (.name | type) == "string" and .name != "" then "\(.name) (@\(.login), " else "@\(.login) (" end) as $who |
137+
(try (.created_at | fromdateiso8601) catch null) as $created |
138+
(if $created == null then "account age unknown" else
139+
"account created \(.created_at | split("T")[0]), ~\((($clock - $created) / 86400) | floor)d old" end) as $age |
140+
"\($who)\(.type | select(type == "string" and length > 0) // "type unknown"), \($age))"' <<<"$profile"
141+
query="repo:${repo} author:${display_login}"
142+
prs=$(search_count issues "$query is:pr created:${repo_from}..${repo_to}") || failed=1
143+
issues=$(search_count issues "$query is:issue created:${repo_from}..${repo_to}") || failed=1
144+
commits=$(search_count commits "$query committer-date:${repo_from}..${repo_to}") || failed=1
145+
printf '%s last %smo [%s..%s]: %s PRs, %s issues, %s commits\n' \
146+
"$repo" "$months" "$repo_from" "$repo_to" "$prs" "$issues" "$commits"
147+
printf 'Repo counts: search index totals, default-branch commits; 1h cache; index/cache may lag. Query bounds are not live as-of timestamps.\n'
175148
if [[ "$include_global" == "1" ]]; then
176-
if global_json=$(global_activity "$display_login" "$since_ts" "$now_ts" 2>/dev/null); then
177-
if [[ -n "$global_json" ]]; then
178-
global_commits=$(jq -r '.totalCommitContributions' <<<"$global_json")
179-
global_issues=$(jq -r '.totalIssueContributions' <<<"$global_json")
180-
global_prs=$(jq -r '.totalPullRequestContributions' <<<"$global_json")
181-
global_reviews=$(jq -r '.totalPullRequestReviewContributions' <<<"$global_json")
182-
printf 'GitHub public last %smo: %s commits, %s PRs, %s issues, %s reviews\n' \
183-
"$months" "$global_commits" "$global_prs" "$global_issues" "$global_reviews"
184-
else
185-
printf 'GitHub public last %smo: unavailable\n' "$months"
186-
fi
187-
else
188-
printf 'GitHub public last %smo: unavailable\n' "$months"
189-
fi
149+
printf 'GitHub contributions last %smo [%s..%s]' "$global_months" "$global_from" "$global_to"
150+
[[ "$global_months" == "$months" ]] || printf ' (capped at one year; requested %smo)' "$months"
151+
printf ': '
152+
global_activity "$display_login" || failed=1
153+
printf 'Contribution graph only; token-visible activity may include private repositories. Zero does not prove inactivity.\n'
190154
fi
191155
done
156+
exit "$failed"

0 commit comments

Comments
 (0)