Skip to content

feat: implement GitHub platform auto-discovery from GitHub API#506

Merged
Harxhit merged 4 commits into
Dev-Card:mainfrom
udaycodespace:feat/github-auto-discovery-32
Jun 12, 2026
Merged

feat: implement GitHub platform auto-discovery from GitHub API#506
Harxhit merged 4 commits into
Dev-Card:mainfrom
udaycodespace:feat/github-auto-discovery-32

Conversation

@udaycodespace

Copy link
Copy Markdown
Contributor

Summary

Implements GitHub Platform Auto-Discovery (#32).

This PR adds a new authenticated endpoint, GET /api/connect/github/autodiscover, which uses the user's connected GitHub account to discover platform links from their GitHub profile. The endpoint returns suggestions only and does not create any links automatically.

To reduce unnecessary GitHub API requests, discovery results are cached in Redis for one hour. The implementation also handles missing, expired, or revoked GitHub tokens gracefully.

Closes #32


Type of Change

  • Bug fix
  • New feature
  • Refactor (no functional change)
  • UI / Design change
  • Tests only
  • Documentation
  • Infrastructure / DevOps
  • Security

What Changed

  • Added GET /api/connect/github/autodiscover.
  • Reused the existing github_follow OAuth token flow to fetch GitHub profile data.
  • Added platform suggestion mapping from GitHub profile metadata.
  • Added Redis caching with a 1-hour TTL.
  • Added tests covering successful discovery, caching, token failures, Redis failures, and URL-based platform inference.

How to Test

  1. Connect a GitHub account using the existing GitHub connect flow.
  2. Send an authenticated request to GET /api/connect/github/autodiscover.
  3. Verify that platform suggestions are returned without creating any platform links.
  4. Repeat the request and verify the cached response is returned.
  5. Verify that revoked or invalid GitHub tokens return an appropriate error response.

Checklist

  • My code follows the project's coding style (pnpm -r run lint passes).
  • TypeScript compiles without errors (pnpm -r run typecheck).
  • I have added or updated tests for the changes I made.
  • All tests pass locally.
  • I have updated documentation where necessary.
  • No new console.log or debug statements left in the code.
  • Breaking changes are documented in this PR description.

Additional Context

Discovery Mapping

  • twitter_usernametwitter (high confidence)
  • dev.to URLs → devto (low confidence)
  • hashnode URLs → hashnode (low confidence)
  • npmjs URLs → npm (low confidence)
  • Other blog URLs → portfolio (high confidence)

Caching

  • Redis key: github:autodiscover:{userId}
  • TTL: 3600 seconds

Tests Added

  • Successful discovery response
  • Cache hit behavior
  • GitHub 401 handling
  • Missing GitHub connection
  • Redis failure fallback
  • Blog URL platform inference

@vercel

vercel Bot commented Jun 8, 2026

Copy link
Copy Markdown

@udaycodespace is attempting to deploy a commit to the Prashantkumar Khatri's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

CI — All Checks Passed

Backend — PASS

Check Result
Lint PASS
Test PASS
Typecheck PASS

Mobile — SKIP

Check Result
Lint -
Test -

Web — SKIP

Check Result
Check -
Build -

Last updated: Fri, 12 Jun 2026 07:39:46 GMT

@udaycodespace

Copy link
Copy Markdown
Contributor Author

Validated locally after the latest changes.

cd apps/backend
pnpm exec vitest run src/__tests__/connect.test.ts

Result: 12/12 tests passing.

The tests cover:

  • Successful discovery response
  • Redis cache hit behavior
  • GitHub API 401 / revoked token handling
  • Missing GitHub connection
  • Redis failure fallback
  • Platform inference from GitHub profile URLs

Attached screenshot of the local test run.

image

Comment thread apps/backend/src/routes/connect.ts Outdated
@udaycodespace

Copy link
Copy Markdown
Contributor Author

@Harxhit Fixed and pushed.

  1. I've restored the reply parameter in the route handler as requested.
  2. Please take another look.

@udaycodespace udaycodespace requested a review from Harxhit June 8, 2026 10:59
@Harxhit Harxhit added gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking. backend labels Jun 8, 2026
@udaycodespace

Copy link
Copy Markdown
Contributor Author

Hi @Harxhit,

I noticed the backend CI is failing with:

'reply' is defined but never used. Allowed unused args must match /^_/u

The failure points to the line that was restored during the review:

async (request: FastifyRequest, reply: FastifyReply) => {

Would it be okay if I update it to:

async (request: FastifyRequest, _reply: FastifyReply) => {

This would keep the parameter in the handler signature while satisfying the lint rule.

@udaycodespace

Copy link
Copy Markdown
Contributor Author

Hi @Harxhit,

Just following up on this PR. The requested change has been pushed and the review comment addressed. Could you please take another look when you get a chance?

Thanks!

@udaycodespace

Copy link
Copy Markdown
Contributor Author

Hi @Harxhit,

The unused reply lint issue has been fixed in commit 2a46693, and the backend CI is now passing (lint, test, and typecheck).

Could you please take another look when you get a chance?

Thanks!

@Harxhit Harxhit left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Approving

Comment thread apps/backend/src/routes/connect.ts Outdated
try { await request.jwtVerify() } catch (e) { reply.status(401).send({ error: 'Unauthorized' }) }
try { await request.jwtVerify() } catch { reply.status(401).send({ error: 'Unauthorized' }) }
}],
}, async (request: FastifyRequest, reply: FastifyReply) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you please address this?

@Harxhit Harxhit merged commit 82a256c into Dev-Card:main Jun 12, 2026
5 of 6 checks passed
@github-actions

Copy link
Copy Markdown

Congratulations @udaycodespace on getting PR #506 merged!

Thank you for your contribution to the project.

To receive the appropriate GSSoC labels and recognition, please mention @Harxhit in the #get-labels channel on our Discord server and share your merged PR link.

@Harxhit Harxhit added level:advanced Complex contribution involving deeper technical work. (+55 pts) quality:clean PR is well-structured, readable, and follows good practices. (×1.2 multiplier) type:testing Adds/improves tests (+10 pts) type:performance Performance optimization (+15 pts) type:refactor Code refactoring/cleanup (+10 pts) quality:exceptional Outstanding contribution with excellent implementation quality. (×1.5 multiplier) type:feature New feature implementation (+10 pts) and removed quality:clean PR is well-structured, readable, and follows good practices. (×1.2 multiplier) labels Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking. level:advanced Complex contribution involving deeper technical work. (+55 pts) quality:exceptional Outstanding contribution with excellent implementation quality. (×1.5 multiplier) type:feature New feature implementation (+10 pts) type:performance Performance optimization (+15 pts) type:refactor Code refactoring/cleanup (+10 pts) type:testing Adds/improves tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backend: implement GitHub platform auto-discovery from GitHub API

2 participants