Skip to content

fix(metrics): include GraphQL discussion activity in engagement score - #3461

Merged
Priyanshu-byte-coder merged 6 commits into
Priyanshu-byte-coder:mainfrom
nyxsky404:fix/community-engagement-discussions
Sep 12, 2026
Merged

Priyanshu-byte-coder merged 6 commits into
Priyanshu-byte-coder:mainfrom
nyxsky404:fix/community-engagement-discussions

Conversation

@nyxsky404

@nyxsky404 nyxsky404 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

User description

Summary

/api/metrics/devtrack-badges always returned discussions.count/points: 0 because the score used a hardcoded placeholder. This wires up the same GraphQL contributionsCollection fields used by /api/metrics/discussions (discussion + discussion-comment counts for the last 30 days) and folds them into the weighted breakdown (* 2, capped at 15). GraphQL failures soft-fail to 0 so the rest of the score still returns.

Closes #3352


Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that changes existing behavior)
  • Documentation update
  • Refactor / code cleanup (no functional change)
  • Performance improvement
  • Security fix
  • Tests only

What Changed

  • Added GraphQL discussion contribution fetch in src/app/api/metrics/devtrack-badges/route.ts
  • Included real discussion count/points in the community engagement breakdown
  • Added unit coverage for users with activity, without activity, and GraphQL failure

How to Test

  1. Sign in with a GitHub account that has discussion or discussion-comment activity in the last 30 days
  2. Call GET /api/metrics/devtrack-badges
  3. Confirm breakdown.discussions.count and points are non-zero and total includes those points
  4. For an account with no discussion activity, confirm discussions stay at 0 while other categories still populate

Expected result:

Discussions reflect real GitHub contribution data instead of a permanent zero placeholder.


Checklist

  • Linked the related issue above
  • Self-reviewed my own diff
  • No unnecessary console.log, debug code, or commented-out blocks
  • npm run lint passes locally
  • No TypeScript errors (npm run type-check)
  • Added or updated tests where applicable
  • Updated documentation / comments if behavior changed

Additional Context

Weight matches issuesOpened (count * 2, max 15). Overall score still clamps to 100.

Made with Cursor


CodeAnt-AI Description

Include GitHub Discussions activity in community engagement scores

What Changed

  • Community engagement metrics now count discussions and discussion comments from the last 30 days
  • Discussion activity contributes up to 15 points to the engagement score and appears in the returned breakdown
  • GitHub API failures leave discussion points at zero without preventing the rest of the score from loading
  • Added coverage for active users, users without discussion activity, authentication failures, and API errors

Impact

✅ Accurate discussion engagement scores
✅ Discussion activity reflected in user breakdowns
✅ Engagement metrics remain available during GitHub API failures

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI lite review requested due to automatic review settings August 6, 2026 11:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:testing GSSoC type bonus: tests (+10 pts) type:performance GSSoC type bonus: performance (+15 pts) gssoc26 GSSoC 2026 contribution labels Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@github-actions github-actions Bot added the type:design GSSoC type bonus: UI/design (+10 pts) label Aug 9, 2026
@github-actions github-actions Bot added the type:devops GSSoC type bonus: devops (+15 pts) label Aug 9, 2026
@nyxsky404

Copy link
Copy Markdown
Contributor Author

@Priyanshu-byte-coder please review pr and merge it, i have also fixed the ci failures

@nyxsky404

Copy link
Copy Markdown
Contributor Author

Hi @Priyanshu-byte-coder — gentle nudge.

This PR is ready for review from my side. I've rebased/kept it current where possible. If CI is red due to unrelated upstream/main issues or deploy previews, the code change itself should still be reviewable.

Please review and merge when you can — and add gssoc:approved (+ difficulty/type) if appropriate so it can count for GSSoC.

Thank you!

Keep the GraphQL discussion engagement score and drop the workflow and modal changes that already landed on main.
@codeant-ai

codeant-ai Bot commented Aug 17, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 3b8fd03 Aug 17, 2026 · 17:13 17:16

@nyxsky404

Copy link
Copy Markdown
Contributor Author

Merged current main to clear the conflicts. This branch had picked up the same extra files as #3174/#3362 (automated-tests.yml plus the modal tweaks that #3499 already shipped), so those are dropped. The PR is now only the GraphQL discussion activity wiring in devtrack-badges plus its unit tests.

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Aug 17, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

This PR has been inactive for 21 days. If it is still in progress, please leave an update — otherwise it will be closed in 7 days.

@github-actions github-actions Bot added the stale Inactive for 21+ days label Sep 8, 2026
@PriyanshuValura

Copy link
Copy Markdown

Good fix. discussionsPoints was hardcoded to 0 behind a // placeholder — GitHub Discussions API requires GraphQL comment, so the Community Champion score silently ignored a whole contribution category. Using contributionsCollection with totalDiscussionContributions + totalDiscussionCommentContributions is the right call — that's the only place GitHub exposes those counts.

Two things you got right that are easy to get wrong:

  • Fails safe on every path. Non-OK response, GraphQL errors array, and a thrown request all return 0. A Discussions hiccup can't take down the whole badges endpoint, which matters because the other five metrics are unrelated.
  • Kept the failure isolation while parallelising. Wrapping the existing Promise.allSettled inside Promise.all alongside fetchDiscussionCount means the GraphQL call runs concurrently with the five REST searches instead of after them, and the per-search allSettled semantics are untouched. Easy to accidentally collapse that into one Promise.all and make any single search failure fatal.

Verified against current main: merges clean, type-check clean, 163 files / 2387 tests passing.

On CI: Analyze (javascript-typescript) was failing, but it wasn't your code — CodeQL hit a GitHub-side outage (No server is currently available to service your request) on 17 Aug. I re-ran the job and it passes.

Minor, not blocking: session.accessToken! leans on the non-null assertion, which is safe here only because of the early return above it. const token = session.accessToken after the guard would let the compiler prove it instead.

Merged.

@Priyanshu-byte-coder
Priyanshu-byte-coder merged commit e460df3 into Priyanshu-byte-coder:main Sep 12, 2026
17 of 19 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Merged! Thanks for contributing to DevTrack.

If the project has been useful to you, a ⭐ star on the repo is the easiest way to support it — it helps DevTrack get discovered by more developers.

Keep an eye on open issues for your next contribution!

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

Labels

gssoc26 GSSoC 2026 contribution size:L This PR changes 100-499 lines, ignoring generated files stale Inactive for 21+ days type:bug GSSoC type bonus: bug fix type:design GSSoC type bonus: UI/design (+10 pts) type:devops GSSoC type bonus: devops (+15 pts) type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Community engagement metric always reports zero discussion activity

4 participants