Skip to content

chore: remove pr number from data#194

Merged
MatteoGabriele merged 3 commits into
mainfrom
chore/remove-pr-number-from-data
Jun 20, 2026
Merged

chore: remove pr number from data#194
MatteoGabriele merged 3 commits into
mainfrom
chore/remove-pr-number-from-data

Conversation

@MatteoGabriele

@MatteoGabriele MatteoGabriele commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Updates
    • Ecosystem health records now identify PRs using a stable key (pr_key) instead of a numeric PR id (pr_number).
    • Closure-rate metrics now group and compute results using pr_key for consistent deduplication.
    • Chart calculation options were updated to support prKey.
  • Chores
    • Added a data migration utility to update persisted scan results to the new pr_key format.
  • Tests
    • Updated unit test fixtures and helpers to use pr_key instead of pr_number.

@netlify

netlify Bot commented Jun 20, 2026

Copy link
Copy Markdown

Deploy Preview for agentscan ready!

Name Link
🔨 Latest commit df3d7e9
🔍 Latest deploy log https://app.netlify.com/projects/agentscan/deploys/6a36ccaca2c22e0008ce217e
😎 Deploy Preview https://deploy-preview-194--agentscan.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@MatteoGabriele, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 53 minutes and 17 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3a28c558-b5ff-4d64-9120-b2c714a333ed

📥 Commits

Reviewing files that changed from the base of the PR and between 917d137 and df3d7e9.

📒 Files selected for processing (2)
  • scripts/pr-hash.ts
  • shared/utils/charts.ts
📝 Walkthrough

Walkthrough

Replaces the numeric pr_number field with a hashed string identifier pr_key computed via hashPrId(repo, prId) using SHA-256 HMAC and a secret key. Updates EcosystemHealthItem, ScanResult, and intermediate data types; scan-users collection logic; chart grouping and deduplication; all test mocks and fixtures; and provides a migration script for existing data.

Changes

Replace pr_number with hashed pr_key

Layer / File(s) Summary
PR hashing utility and dependencies
scripts/pr-hash.ts, package.json
New hashPrId(repo, prId) function computes deterministic SHA-256 HMAC hex digest from ${repo}:${prId} using PR_HASH_SECRET environment variable. Adds @types/node ^26.0.0 dev dependency.
Update data contracts to use pr_key
shared/types/ecosystem-health.ts, scripts/scan-users.ts, shared/utils/charts.ts
Replaces pr_number: number with pr_key: string in EcosystemHealthItem, ScanResult interface, intermediate user record type, and RepoClosedPrOptions options type.
Update scan-users to compute and persist pr_key
scripts/scan-users.ts
Imports hashPrId utility. Computes pr_key via hashPrId(repoFullName, pr.number) during PR author collection and persists pr_key: user.pr_key in ScanResult output.
Update chart logic to use pr_key for grouping
shared/utils/charts.ts
Changes getClosedPrPercentageByRepo default PR identity key from prNumberKey to prKey. Updates internal grouping to deduplicate by string prId extracted via entry[prKey] instead of numeric PR numbers. Updates snapshot closure-rate documentation.
Update test mocks and fixtures to use pr_key
test/unit/mocks/ecosystemHealthItems.ts, test/unit/shared/utils/charts.test.ts
Removes pr_number from all mock items. Refactors createEcosystemHealthItem helper to accept pr_key: string parameter. Updates all getClosedPrDelta test fixture calls to use new string pr_key arguments.
Data migration script for existing scan results
scripts/migrate-pr-numbers.ts
New migration script loads data/scan-results.json, rewrites each record by computing pr_key via hashPrId(repo_name, pr_key), writes updated array back, and logs migrated record count.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • MatteoGabriele/agentscan#149: Introduced PR-number-based grouping in getClosedPrPercentageByRepo with prNumberKey in RepoClosedPrOptions, which this PR replaces with hashed pr_key identifiers.
  • MatteoGabriele/agentscan#187: Adds closure-rate snapshot and delta helpers built on getClosedPrPercentageByRepo; this PR's switch from pr_number to pr_key affects the underlying grouping logic those helpers depend on.

Poem

🐇 A hash is born from secret and string,
pr_key replaces that number thing!
SHA-256 keeps each PR obscure,
While deduplication stays secure.
From GitHub ID to hex so bright,
The bunny's data migration done right! 🔐

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective: replacing pr_number with pr_key across the codebase and associated data structures.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/remove-pr-number-from-data

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@MatteoGabriele MatteoGabriele force-pushed the chore/remove-pr-number-from-data branch from 75fcaf0 to 917d137 Compare June 20, 2026 17:17

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripts/scan-users.ts (1)

192-213: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don’t swallow hashPrId configuration failures inside the profile-fetch catch block.

At Line [201], if hashPrId throws (e.g., missing PR_HASH_SECRET), it is reported as “Error fetching profile” and the scan continues with misleading diagnostics. This should fail fast (or be handled separately) rather than being treated as a per-user API failure.

Suggested fix
-          try {
-            const fullProfile = await octokit.rest.users.getByUsername({
-              username: pr.user.login,
-            });
+          const prKey = hashPrId(repoFullName, pr.number);
+          try {
+            const fullProfile = await octokit.rest.users.getByUsername({
+              username: pr.user.login,
+            });

             users.push({
               id: fullProfile.data.id,
               login: fullProfile.data.login,
               created_at: fullProfile.data.created_at,
-              pr_key: hashPrId(repoFullName, pr.number),
+              pr_key: prKey,
               pr_status: pr.state,
               public_repos: fullProfile.data.public_repos,
               repo_name: repoFullName,
             });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/scan-users.ts` around lines 192 - 213, The hashPrId function call on
line 201 is inside the try-catch block designed to handle
octokit.rest.users.getByUsername API errors. If hashPrId throws a configuration
error (like missing PR_HASH_SECRET), it gets caught and reported as a profile
fetch error, which is misleading. Move the hashPrId call outside and before the
try-catch block so that configuration failures fail fast instead of being
swallowed as per-user API failures.
🧹 Nitpick comments (1)
test/unit/shared/utils/charts.test.ts (1)

225-231: ⚡ Quick win

Avoid casting partial test objects to EcosystemHealthItem.

Using as EcosystemHealthItem here bypasses required-field checks and can mask contract drift. Prefer filling required defaults in the helper and returning a fully typed object without assertion.

Suggested change
   function createEcosystemHealthItem(
     created_at: string,
     repo_name: string,
     pr_key: string,
     pr_status: "open" | "closed",
     score: number,
   ): EcosystemHealthItem {
     return {
       created_at,
       repo_name,
       pr_key,
       pr_status,
       score,
-    } as EcosystemHealthItem;
+      user_created_at: "1970-01-01T00:00:00Z",
+      user_public_repos_count: 0,
+      events_count: 0,
+    };
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit/shared/utils/charts.test.ts` around lines 225 - 231, Remove the `as
EcosystemHealthItem` type assertion from the return statement in this test
helper function. Instead, identify all required fields of the
EcosystemHealthItem type and provide sensible default values for any missing
properties beyond the current five (created_at, repo_name, pr_key, pr_status,
score). Return the fully populated object without casting to ensure the test
object matches the actual contract of EcosystemHealthItem and prevents future
contract drift from going unnoticed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/pr-hash.ts`:
- Around line 5-12: The hashPrId function needs to validate that the prId
parameter is a finite number before proceeding with the hash calculation. Add a
validation check after the secret validation (after the PR_HASH_SECRET
environment variable check) to ensure prId is a finite number using the
Number.isFinite method, and throw an Error if the validation fails. This
prevents non-finite values like NaN or Infinity from being hashed and persisted
as invalid pr_key identifiers.

In `@shared/utils/charts.ts`:
- Around line 107-110: The guard condition checking if repo and prId are truthy
occurs after the String() coercion, but String(undefined) and String(null)
produce truthy strings ("undefined" and "null"), making the check ineffective.
Move the guard condition to check the raw values entry[repoKey] and entry[prKey]
for truthiness BEFORE applying String() coercion, so that undefined or null
values are properly filtered out before being used for deduplication.

---

Outside diff comments:
In `@scripts/scan-users.ts`:
- Around line 192-213: The hashPrId function call on line 201 is inside the
try-catch block designed to handle octokit.rest.users.getByUsername API errors.
If hashPrId throws a configuration error (like missing PR_HASH_SECRET), it gets
caught and reported as a profile fetch error, which is misleading. Move the
hashPrId call outside and before the try-catch block so that configuration
failures fail fast instead of being swallowed as per-user API failures.

---

Nitpick comments:
In `@test/unit/shared/utils/charts.test.ts`:
- Around line 225-231: Remove the `as EcosystemHealthItem` type assertion from
the return statement in this test helper function. Instead, identify all
required fields of the EcosystemHealthItem type and provide sensible default
values for any missing properties beyond the current five (created_at,
repo_name, pr_key, pr_status, score). Return the fully populated object without
casting to ensure the test object matches the actual contract of
EcosystemHealthItem and prevents future contract drift from going unnoticed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f5f01d7a-52bf-4457-a1a4-6d6515f1b17d

📥 Commits

Reviewing files that changed from the base of the PR and between 75fcaf0 and 917d137.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • data/scan-results.json
  • package.json
  • scripts/migrate-pr-numbers.ts
  • scripts/pr-hash.ts
  • scripts/scan-users.ts
  • shared/types/ecosystem-health.ts
  • shared/utils/charts.ts
  • test/unit/mocks/ecosystemHealthItems.ts
  • test/unit/shared/utils/charts.test.ts
✅ Files skipped from review due to trivial changes (2)
  • scripts/migrate-pr-numbers.ts
  • package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • shared/types/ecosystem-health.ts

Comment thread scripts/pr-hash.ts
Comment thread shared/utils/charts.ts Outdated
@MatteoGabriele MatteoGabriele merged commit 48c040c into main Jun 20, 2026
5 checks passed
@graphieros

Copy link
Copy Markdown
Collaborator

yolo style 😎

@MatteoGabriele

Copy link
Copy Markdown
Owner Author

This is us after merging.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants