Skip to content

feat(repos): Add task to periodically sync repos from github - #112043

Merged
wedamija merged 5 commits into
masterfrom
danf/github-periodic-repo-sync
Apr 7, 2026
Merged

wedamija merged 5 commits into
masterfrom
danf/github-periodic-repo-sync

Conversation

@wedamija

@wedamija wedamija commented Apr 1, 2026

Copy link
Copy Markdown
Member

This adds a task that runs every 24 hours to make sure that the available repositories on the github side match the repositories we have on the Sentry side.

@wedamija
wedamija requested review from a team April 1, 2026 20:54
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 1, 2026
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on 0b8b67c in this run:

tests/sentry/taskworker/test_config.py::test_all_instrumented_tasks_registered — log
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/taskworker/test_config.py:120: in test_all_instrumented_tasks_registered
    raise AssertionError(
E   AssertionError: Found 2 module(s) with @instrumented_task that are NOT registered in TASKWORKER_IMPORTS.
E   These tasks will not be discovered by the taskworker in production!
E   
E   Missing modules:
E     - sentry.integrations.github.tasks.sync_repos
E     - sentry.integrations.github.tasks.sync_repos_on_install_change
E   
E   Add these to TASKWORKER_IMPORTS in src/sentry/conf/server.py

@wedamija
wedamija force-pushed the danf/github-installation-repositories branch from 9323c8d to 9a5dc41 Compare April 1, 2026 22:25
@wedamija
wedamija force-pushed the danf/github-periodic-repo-sync branch from dc6db0b to 04ffffa Compare April 1, 2026 22:26
Base automatically changed from danf/github-installation-repositories to master April 3, 2026 16:23
@wedamija
wedamija force-pushed the danf/github-periodic-repo-sync branch from e1110fd to 9e370c5 Compare April 3, 2026 16:24
@wedamija
wedamija force-pushed the danf/github-periodic-repo-sync branch from 2e87a63 to a342e00 Compare April 3, 2026 22:25
@wedamija
wedamija changed the base branch from master to danf/github-installation-repositories-take-2 April 3, 2026 22:25
Base automatically changed from danf/github-installation-repositories-take-2 to master April 6, 2026 17:50
This adds a task that runs every 24 hours to make sure that the available repositories on the github side match the repositories we have on the Sentry side.

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Duplicated _get_repo_config already exists in link_all_repos
    • Removed the duplicated _get_repo_config function and imported get_repo_config from link_all_repos.py instead, following the existing pattern used by sync_repos_on_install_change.py.

Create PR

Or push these changes by commenting:

@cursor push 240cd2d26b
Preview (240cd2d26b)
diff --git a/src/sentry/integrations/source_code_management/sync_repos.py b/src/sentry/integrations/source_code_management/sync_repos.py
--- a/src/sentry/integrations/source_code_management/sync_repos.py
+++ b/src/sentry/integrations/source_code_management/sync_repos.py
@@ -9,7 +9,6 @@
 """
 
 import logging
-from collections.abc import Mapping
 from datetime import timedelta
 from typing import Any
 
@@ -18,6 +17,7 @@
 from sentry import features
 from sentry.constants import ObjectStatus
 from sentry.features.exceptions import FeatureNotRegistered
+from sentry.integrations.github.tasks.link_all_repos import get_repo_config
 from sentry.integrations.models.organization_integration import OrganizationIntegration
 from sentry.integrations.services.integration import integration_service
 from sentry.integrations.services.repository.service import repository_service
@@ -51,14 +51,6 @@
 ]
 
 
-def _get_repo_config(repo: Mapping[str, Any], integration_id: int) -> RepositoryInputConfig:
-    return {
-        "external_id": str(repo["id"]),
-        "integration_id": integration_id,
-        "identifier": repo["full_name"],
-    }
-
-
 def _has_feature(flag_name: str, org: Any) -> bool:
     """Check a feature flag, returning False if the flag is not registered."""
     try:
@@ -206,7 +198,7 @@
         if new_ids:
             integration_repo_provider = get_integration_repository_provider(integration)
             repo_configs: list[RepositoryInputConfig] = [
-                _get_repo_config(repo, integration.id)
+                get_repo_config(repo, integration.id)
                 for repo in provider_repos
                 if str(repo["id"]) in new_ids
             ]

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Keep the sync task GitHub-specific for now. Generalizing to all SCMs
requires a consistent way to extract external_id from each provider's
API response, which needs a separate refactor.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 56bb0e1. Configure here.

@markstory markstory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks reasonable to me. client.get_repos() will fetch all repos with pagination so sync should be exhaustive. There are a lot of RPC calls in these tasks but there isn't a good way around that.

@wedamija
wedamija merged commit f57c63e into master Apr 7, 2026
80 checks passed
@wedamija
wedamija deleted the danf/github-periodic-repo-sync branch April 7, 2026 16:23
george-sentry pushed a commit that referenced this pull request Apr 9, 2026
This adds a task that runs every 24 hours to make sure that the
available repositories on the github side match the repositories we have
on the Sentry side.
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 23, 2026

This branch was successfully deployed

1 active deployment
Preview — 56bb0e1d Deployed Apr 6, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants