feat&perf(base): minor QoL improvements#22
feat&perf(base): minor QoL improvements#22ferferga wants to merge 5 commits intogh-metrics:masterfrom
Conversation
Merged flags in the same query Signed-off-by: GitHub <[email protected]>
…ion in indepth mode - By default, GitHub repositoriesContributedTo just shows data from last year. When indepth is enabled, we fetch data since the beginning of the times. See https://github.com/orgs/community/discussions/24350 for full info Signed-off-by: GitHub <[email protected]>
- Reduces 2 queries in 1 Signed-off-by: GitHub <[email protected]>
Signed-off-by: GitHub <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR adds a configuration option to control whether a user's own repositories are counted in “Contributed to X repositories” and refactors the base plugin’s contribution/repository queries to fetch more data per request for better performance.
Changes:
- Introduces a
repositories_ownedinput (action and plugin metadata) wired through to the base plugin asrepositories.ownedto toggle inclusion of the user’s own repositories in contributed-repositories statistics. - Updates
field.repositories.graphqlandcontributions.graphqlto fetch repository counts/disk usage and all contribution totals (plus optional indepth fields) in a single query. - Refactors
source/plugins/base/index.mjsto (a) use the new ownership flag in both unit queries and indepth aggregation, and (b) aggregate repositories and contributions over the account lifetime using fewer GraphQL calls.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| source/plugins/base/queries/field.repositories.graphql | Simplifies the repositories field query to return totalCount and totalDiskUsage in one call, used by the base plugin’s fallback path. |
| source/plugins/base/queries/contributions.graphql | Expands the contributions query to fetch all total contribution counts and optional indepth-by-repository fields in a single contributionsCollection query. |
| source/plugins/base/metadata.yml | Adds the repositories_owned plugin input (default yes) to control whether own repositories are included in the contributed-repositories count. |
| source/plugins/base/index.mjs | Wires repositories.owned through to GraphQL calls, uses it to filter contributed repositories, refactors repository stats and contributions fetching, and introduces indepth lifetime aggregation logic (with some issues noted in comments). |
| action.yml | Exposes the new repositories_owned input at the GitHub Action level so users can configure the ownership behavior in workflows. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
source/plugins/base/index.mjs
Outdated
| } | ||
| catch { | ||
| console.debug(`metrics/compute/${login}/base > failed to retrieve contributionsCollection`) | ||
| data.user.contributionsCollection[field] = NaN |
There was a problem hiding this comment.
In this catch block, field is not defined in this scope anymore (the surrounding for (const field of fields) loop was removed), so data.user.contributionsCollection[field] = NaN will throw a ReferenceError the first time this path is hit and prevent the fallback from completing. Instead of using an undefined loop variable, either initialize data.user.contributionsCollection as a whole or explicitly set each expected property on it when the contributions query fails.
| data.user.contributionsCollection[field] = NaN | |
| data.user.contributionsCollection = data.user.contributionsCollection ?? {} |
| for (const contribution of contributions) { | ||
| for (const field in contribution) { | ||
| if (indepthExtraFields.includes(field)) { | ||
| for (const repo of contribution[field]) { | ||
| const nameWithOwner = repo.repository.nameWithOwner | ||
| if (!_owned && nameWithOwner.split('/')[0] === login) continue | ||
| totalReposContributed.add(nameWithOwner) | ||
| } | ||
| } else { | ||
| data.user.contributionsCollection[field] ??= 0 | ||
| data.user.contributionsCollection[field] += contribution[field] | ||
| } |
There was a problem hiding this comment.
In the indepth lifetime aggregation, you accumulate each range's numeric fields into data.user.contributionsCollection[field] using +=, but this object has already been populated earlier from the bulk or fallback contributions query, so totals like totalCommitContributions and totalIssueContributions will be double-counted (once from the initial query, again from the lifetime ranges). To avoid inflated statistics, either base the lifetime totals on a fresh accumulator and assign them at the end, or overwrite the existing values (or use a Math.max-style comparison as in the previous implementation) rather than incrementing them on top of the last-year snapshot.
Signed-off-by: GitHub <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| data.user.contributionsCollection[field] ?? 0 | ||
| ) | ||
| } | ||
|
|
There was a problem hiding this comment.
data.user.repositoriesContributedTo may be undefined when this indepth lifetime contributions path runs, because postprocess.user does not initialise this property and both the bulk BaseUserX query and the fallback unit repositoriesContributedTo query can fail. In that case, assigning to data.user.repositoriesContributedTo.totalCount will throw at runtime; consider initialising data.user.repositoriesContributedTo to a safe default (for example mirroring the structure used in postprocess.organization/postprocess.skip) before writing totalCount.
| data.user.repositoriesContributedTo ??= { totalCount: 0 } |
| user: ["packages", "starredRepositories", "watching", "sponsorshipsAsSponsor", "sponsorshipsAsMaintainer", "followers", "following", "issueComments", "organizations", `repositoriesContributedTo(includeUserRepositories: ${_owned})`], | ||
| organization: ["packages", "sponsorshipsAsSponsor", "sponsorshipsAsMaintainer", "membersWithRole"], |
There was a problem hiding this comment.
The new repositories.owned input is used here to control includeUserRepositories in unit field queries and in the indepth lifetime aggregation, but the bulk BaseUserX query (source/plugins/base/queries/user.x.graphql:30) still hardcodes repositoriesContributedTo(includeUserRepositories: true). This means that when indepth mode is disabled and the bulk query succeeds, toggling repositories_owned has no effect on the "Contributed to X repositories" count; to align behaviour with the option description, the bulk query should also be parameterised to respect _owned.
| repositories_owned: | ||
| description: Include your own repositories in the "Contributed to X repositories" count | ||
| default: <default-value> |
There was a problem hiding this comment.
action.yml is treated as an auto-generated file in the test suite (tests/ci.test.js:16-21 asserts that it must not appear as modified in diffs). With these manual changes, CI will fail unless the generator and/or the test expectations are updated accordingly, so please ensure this file is regenerated from its source or the tests are adjusted in tandem.
| repositories_owned: | ||
| description: | | ||
| Include your own repositories in the "Contributed to X repositories" count | ||
| type: boolean | ||
| default: yes |
There was a problem hiding this comment.
The new repositories_owned input is defined here but does not yet appear in the base plugin README options table (which currently documents neighbouring inputs such as repositories_forks and repositories_affiliations). To keep user-facing configuration documentation in sync with available inputs, consider adding a README entry or regenerating the plugin docs from this metadata.
This pull request introduces a new configuration option to control whether a user's own repositories are included in the "Contributed to X repositories" count, and refactors how contribution and repository data are queried and aggregated. The changes improve flexibility and accuracy in reporting user contributions, especially for in-depth statistics.
New Feature: Repository Ownership Option
repositories_ownedto bothaction.ymlandmetadata.yml, allowing users to specify whether their own repositories should be included in the contributed repositories count. [1] [2]Refactoring and Improvements to Data Queries