Skip to content

MOSIP-45242-GitHub tracker add support for both inji and mosip project#42

Open
jayesh12234 wants to merge 5 commits into
mosip:developfrom
jayesh12234:develop
Open

MOSIP-45242-GitHub tracker add support for both inji and mosip project#42
jayesh12234 wants to merge 5 commits into
mosip:developfrom
jayesh12234:develop

Conversation

@jayesh12234

@jayesh12234 jayesh12234 commented Jun 29, 2026

Copy link
Copy Markdown

Summary

  • Add GITHUB_ORGS env var to sync multiple GitHub organizations in one call
  • Fix org read APIs to filter by repos.owner so /orgs/mosip/* and /orgs/inji/* return org-specific data
  • No database schema changes

Changes

  • Sync: repoSyncRoute loops over GITHUB_ORGS when no org is passed in request body
  • Read APIs: leaderboard, summary, activity, users, and user details now filter via repos.owner
  • New: utils/orgQuery.js — shared SQL join/filter helpers

Config

GITHUB_ORGS=mosip,inji

Test plan

  • Sync repos for both orgs via POST /admin/sync/repos
  • Confirm mosip vs inji leaderboard return different data
  • Confirm summary/activity/users are org-scoped

Summary by CodeRabbit

  • New Features

    • Added support for syncing repositories from multiple GitHub organizations, with configuration via environment settings or a request body value.
    • Organization activity, summary, user details, and leaderboard views now return data scoped to the selected organization.
  • Bug Fixes

    • Fixed org-based activity and summary requests so they use the requested organization ID correctly.
    • Improved repository sync feedback when no organization is configured or provided.

Signed-off-by: Jayesh Kharode <jayesh.kharode@technoforte.co.in>
Signed-off-by: Jayesh Kharode <jayesh.kharode@technoforte.co.in>
Signed-off-by: Jayesh Kharode <jayesh.kharode@technoforte.co.in>
Signed-off-by: Jayesh Kharode <jayesh.kharode@technoforte.co.in>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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 (2)
github-activity-tracker/backend/services/userDetailsService.js (1)

29-39: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Scope the initial user lookup to the requested org.

dailyQuery is org-filtered, but the profile lookup still resolves login globally. A request like /orgs/inji/users/<mosip-only-user> can return that user with zero activity instead of “not found” for the org.

🐛 Proposed fix
 async function getUserDetails(login, period, orgId) {
   if (isExcludedGitHubLogin(login)) {
     throw new Error('User not found');
   }
+  const orgOwner = String(orgId).toLowerCase();
+
   /* 1. Get user details */
   const userQuery = `
-    SELECT id, login, avatar_url, NULL as name, NULL as email
-    FROM github_users
-    WHERE login = $1
+    SELECT gu.id, gu.login, gu.avatar_url, NULL as name, NULL as email
+    FROM github_users gu
+    WHERE gu.login = $1
+      AND EXISTS (
+        SELECT 1
+        FROM activity_events e
+        JOIN repos r ON r.github_repo_id = e.repo_id
+        WHERE e.user_id = gu.id
+          AND LOWER(r.owner) = $2
+      )
   `;
-  const userRes = await pool.query(userQuery, [login]);
+  const userRes = await pool.query(userQuery, [login, orgOwner]);
-  const orgOwner = String(orgId).toLowerCase();
-
   const dailyRes = await pool.query(dailyQuery, [
🤖 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 `@github-activity-tracker/backend/services/userDetailsService.js` around lines
29 - 39, The initial user lookup in getUserDetails currently searches
github_users only by login, so it can return a user outside the requested org.
Update the userQuery in getUserDetails to scope the lookup by orgId as well,
using the same org membership data/source used elsewhere in this service, so
org-only requests return “User not found” when the login does not belong to that
org.
github-activity-tracker/backend/routes/repoSyncRoute.js (1)

25-41: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Don't report zero after partial multi-org writes.

If syncRepos(orgName) fails on the second or later org, github-activity-tracker/backend/services/syncRepos.js:13-99 may already have written repos for earlier orgs (and even part of the failing org), but this catch block still returns repos_processed: 0. That breaks the route contract for callers and makes retries blind. Please return partial per-org results, or at least preserve the completed count instead of zeroing the whole response.

🤖 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 `@github-activity-tracker/backend/routes/repoSyncRoute.js` around lines 25 -
41, The error handling in repoSyncRoute’s sync loop is resetting repos_processed
to 0 even after syncRepos(orgName) has already completed some work for earlier
orgs. Update the route’s try/catch so it preserves the accumulated
reposProcessed count from the for-of loop, or otherwise returns partial per-org
progress instead of zeroing the response in the catch block. Use the existing
repoSyncRoute handler and syncRepos(orgName) callsite to keep the completed
count consistent with partial multi-org writes.
🤖 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 `@github-activity-tracker/backend/config/syncConfig.js`:
- Around line 10-11: The org list in syncConfig.js is being de-duplicated before
case normalization, so values like “mosip” and “MOSIP” still survive as separate
entries. Update the org parsing logic to normalize each trimmed value to
lowercase before it is passed into the Set, and keep the existing filtering of
empty values so repoSyncRoute only syncs each org once.

In `@github-activity-tracker/backend/services/orgSummaryService.js`:
- Around line 59-60: The time-range filter in orgSummaryService.js currently
uses an inclusive BETWEEN in the query-building logic, which double-counts
events exactly at the boundary between periods. Update the predicate in the code
that appends to whereClauses after params.push(start, end) so it uses a
half-open window with e.created_at >= start and e.created_at < end, preserving
correct separation between the previous and current summary windows.

---

Outside diff comments:
In `@github-activity-tracker/backend/routes/repoSyncRoute.js`:
- Around line 25-41: The error handling in repoSyncRoute’s sync loop is
resetting repos_processed to 0 even after syncRepos(orgName) has already
completed some work for earlier orgs. Update the route’s try/catch so it
preserves the accumulated reposProcessed count from the for-of loop, or
otherwise returns partial per-org progress instead of zeroing the response in
the catch block. Use the existing repoSyncRoute handler and syncRepos(orgName)
callsite to keep the completed count consistent with partial multi-org writes.

In `@github-activity-tracker/backend/services/userDetailsService.js`:
- Around line 29-39: The initial user lookup in getUserDetails currently
searches github_users only by login, so it can return a user outside the
requested org. Update the userQuery in getUserDetails to scope the lookup by
orgId as well, using the same org membership data/source used elsewhere in this
service, so org-only requests return “User not found” when the login does not
belong to that org.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 72dd3c0e-545f-4526-8edf-f8712cd6716c

📥 Commits

Reviewing files that changed from the base of the PR and between 37033f7 and 0244969.

📒 Files selected for processing (13)
  • github-activity-tracker/backend/.env.example
  • github-activity-tracker/backend/app.js
  • github-activity-tracker/backend/config/syncConfig.js
  • github-activity-tracker/backend/routes/orgActivityRoute.js
  • github-activity-tracker/backend/routes/orgSummaryRoute.js
  • github-activity-tracker/backend/routes/repoSyncRoute.js
  • github-activity-tracker/backend/routes/userDetailsRoute.js
  • github-activity-tracker/backend/services/leaderBoardService.js
  • github-activity-tracker/backend/services/orgActivityService.js
  • github-activity-tracker/backend/services/orgSummaryService.js
  • github-activity-tracker/backend/services/orgUsersService.js
  • github-activity-tracker/backend/services/userDetailsService.js
  • github-activity-tracker/backend/utils/orgQuery.js

Comment thread github-activity-tracker/backend/config/syncConfig.js Outdated
Comment thread github-activity-tracker/backend/services/orgSummaryService.js Outdated
Signed-off-by: Jayesh Kharode <jayesh.kharode@technoforte.co.in>
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