Skip to content

Improve contributions-for-user.sh: surface authored PRs, group commits, skip empty areas#1532

Draft
Ivaylogi98 wants to merge 1 commit into
cloudfoundry:mainfrom
Ivaylogi98:update-contribution-counting-script
Draft

Improve contributions-for-user.sh: surface authored PRs, group commits, skip empty areas#1532
Ivaylogi98 wants to merge 1 commit into
cloudfoundry:mainfrom
Ivaylogi98:update-contribution-counting-script

Conversation

@Ivaylogi98

Copy link
Copy Markdown
Contributor

What

Reworks toc/working-groups/contributions-for-user.sh so the generated gists actually reflect a user's contribution footprint. The previous version omitted authored PRs entirely, generated empty gists for unrelated areas, and missed several categories of contribution relevant to RFC-0006 approver requirements.

Why

Running the script as a candidate for approver returned gists that contained only review/comment activity — no authored PRs, no code contributions on others' PRs, and a flood of empty gists for areas the user has never touched. This made the output unusable for assembling evidence of substantial contributions.

Changes

New sections in the gist

  • PRs Authored — PRs where the user is the author, with their open/closed/merged state. Previously absent entirely.
  • Commits on others' PRs — commits authored by the user that landed in a PR authored by someone else (i.e. pushed onto a collaborator's branch). Previously invisible.
  • Code contributions (merged PRs) — replaces the flat commit listing. Merged PRs are now top-level bullets; commits are indented underneath only when a PR has more than one. Picks up the refactor proposed in Fix yq commit message parsing in contributions script #1457.

Correctness fixes

  • Gist filename was using the undefined ${wg} instead of ${WORKING_GROUP}, producing empty-prefixed filenames.
  • yq commit-message parsing used .commit.message | split("\n")[0] which raised !!seq cannot be added to !!str. Fixed to ((.commit.message | split("\n"))[0]).
  • GitHub search index silently omits some PRs (bosh-agent#393 is one example). Added a targeted events-based fallback that does single-PR lookups for any PR numbers visible in the user's events but missing from search results.
  • The author/committer commit search used repos/{repo}/commits?author= which filters by email rather than login, missing most commits. Replaced with search/commits?q=author:${user}+repo:${repo}.
  • Normalize USERNAME via gh api users/${USERNAME} so the GitHub search API (case-sensitive on author: / reviewed-by: qualifiers) matches reliably.

Performance / robustness

  • Skip gist creation for areas with zero contributions — eliminates a dozen empty gists per run.
  • --paginate added to search/commits so >100 commits are not silently dropped.
  • Events fallback filters to payload.action == "opened" so each PR triggers at most one API lookup, not one per recorded event.
  • All deduplication moved from O(n²) array loops to O(1) associative-array sets (local -A seen).
  • emit_pr_with_commits promoted from a nested closure to a top-level function with an explicit repo parameter, removing the implicit closure-by-name on the outer function's ${repo}.
  • Dropped the now-deprecated cloak-preview and groot-preview Accept headers — both endpoints have been stable for years.
  • Shebang switched to #!/usr/bin/env bash with an explicit bash 4+ version check, since the script now relies on associative arrays. macOS users on the system bash 3.2 get a clear "install bash via Homebrew" message instead of cryptic local -A errors mid-run.

Testing

Ran against Foundational Infrastructure for an approver-candidate user. Areas with no contributions are now skipped; areas with contributions produce gists with all five sections populated, including PRs the GitHub search index had been silently dropping.

Authored with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

1 participant