Skip to content

Commit ca7fcd4

Browse files
Revert "feat(github): Handle installation_repositories webhook (#111864)"
This reverts commit a8a8009. Co-authored-by: wedamija <6288560+wedamija@users.noreply.github.com>
1 parent f2148f4 commit ca7fcd4

24 files changed

Lines changed: 18 additions & 1002 deletions

File tree

src/sentry/features/temporary.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ def register_temporary_features(manager: FeatureManager) -> None:
137137
manager.add("organizations:integrations-cursor", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
138138
manager.add("organizations:integrations-github-copilot-agent", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
139139
manager.add("organizations:integrations-github-platform-detection", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
140-
manager.add("organizations:github-repo-auto-sync", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
141140
manager.add("organizations:integrations-perforce", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
142141
manager.add("organizations:integrations-slack-staging", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
143142
manager.add("organizations:scm-source-context", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)

src/sentry/integrations/bitbucket/repository.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections.abc import Mapping
21
from typing import Any
32

43
from sentry.integrations.types import IntegrationProviderSlug
@@ -48,7 +47,7 @@ def get_webhook_secret(self, organization):
4847
return secret
4948

5049
def build_repository_config(
51-
self, organization: RpcOrganization, data: Mapping[str, Any]
50+
self, organization: RpcOrganization, data: dict[str, Any]
5251
) -> RepositoryConfig:
5352
installation = self.get_installation(data.get("installation"), organization.id)
5453
client = installation.get_client()

src/sentry/integrations/bitbucket_server/repository.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections.abc import Mapping
21
from datetime import datetime, timezone
32
from typing import Any
43

@@ -36,7 +35,7 @@ def get_repository_data(self, organization, config):
3635
return config
3736

3837
def build_repository_config(
39-
self, organization: RpcOrganization, data: Mapping[str, Any]
38+
self, organization: RpcOrganization, data: dict[str, Any]
4039
) -> RepositoryConfig:
4140
installation = self.get_installation(data.get("installation"), organization.id)
4241
client = installation.get_client()

src/sentry/integrations/github/repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_repository_data(
5252
return config
5353

5454
def build_repository_config(
55-
self, organization: RpcOrganization, data: Mapping[str, Any]
55+
self, organization: RpcOrganization, data: dict[str, Any]
5656
) -> RepositoryConfig:
5757
return {
5858
"name": data["identifier"],

src/sentry/integrations/github/tasks/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
from .codecov_account_unlink import codecov_account_unlink
33
from .link_all_repos import link_all_repos
44
from .pr_comment import github_comment_workflow
5-
from .sync_repos_on_install_change import sync_repos_on_install_change
65

76
__all__ = (
87
"codecov_account_link",
98
"codecov_account_unlink",
109
"github_comment_workflow",
1110
"link_all_repos",
12-
"sync_repos_on_install_change",
1311
)

src/sentry/integrations/github/tasks/link_all_repos.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from collections.abc import Mapping
32
from typing import Any
43

54
from taskbroker_client.retry import Retry
@@ -14,7 +13,6 @@
1413
from sentry.organizations.services.organization import organization_service
1514
from sentry.plugins.providers.integration_repository import (
1615
RepoExistsError,
17-
RepositoryInputConfig,
1816
get_integration_repository_provider,
1917
)
2018
from sentry.shared_integrations.exceptions import ApiError
@@ -25,9 +23,9 @@
2523
logger = logging.getLogger(__name__)
2624

2725

28-
def get_repo_config(repo: Mapping[str, Any], integration_id: int) -> RepositoryInputConfig:
26+
def get_repo_config(repo, integration_id):
2927
return {
30-
"external_id": str(repo["id"]),
28+
"external_id": repo["id"],
3129
"integration_id": integration_id,
3230
"identifier": repo["full_name"],
3331
}
@@ -79,7 +77,7 @@ def link_all_repos(
7977

8078
integration_repo_provider = get_integration_repository_provider(integration)
8179

82-
repo_configs: list[RepositoryInputConfig] = []
80+
repo_configs: list[dict[str, Any]] = []
8381
missing_repos = []
8482
for repo in repositories:
8583
try:

src/sentry/integrations/github/tasks/sync_repos_on_install_change.py

Lines changed: 0 additions & 136 deletions
This file was deleted.

src/sentry/integrations/github/webhook.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from sentry.integrations.github.webhook_types import (
3131
GITHUB_WEBHOOK_TYPE_HEADER_KEY,
3232
GithubWebhookType,
33-
InstallationRepositoriesEvent,
3433
)
3534
from sentry.integrations.pipeline import ensure_integration
3635
from sentry.integrations.services.integration.model import (
@@ -419,57 +418,6 @@ def _handle_organization_deletion(
419418
)
420419

421420

422-
class InstallationRepositoriesEventWebhook(GitHubWebhook):
423-
"""
424-
Handles installation_repositories events when repos are added to or
425-
removed from the GitHub App installation. Runs in control silo.
426-
427-
https://docs.github.com/en/webhooks/webhook-events-and-payloads#installation_repositories
428-
"""
429-
430-
EVENT_TYPE = IntegrationWebhookEventType.INSTALLATION_REPOSITORIES
431-
432-
def __call__( # type: ignore[override]
433-
self, event: InstallationRepositoriesEvent, host: str | None = None, **kwargs: Any
434-
) -> None:
435-
external_id = get_github_external_id(event=event, host=host)
436-
if external_id is None:
437-
return
438-
439-
result = integration_service.organization_contexts(
440-
provider=self.provider,
441-
external_id=external_id,
442-
)
443-
integration = result.integration
444-
445-
if integration is None:
446-
logger.warning(
447-
"github.installation_repositories.missing_integration",
448-
extra={"external_id": str(external_id)},
449-
)
450-
return
451-
452-
action = event["action"]
453-
repos_added = event["repositories_added"]
454-
repos_removed = event["repositories_removed"]
455-
repository_selection = event["repository_selection"]
456-
457-
if not repos_added and not repos_removed:
458-
return
459-
460-
from .tasks.sync_repos_on_install_change import sync_repos_on_install_change
461-
462-
sync_repos_on_install_change.apply_async(
463-
kwargs={
464-
"integration_id": integration.id,
465-
"action": action,
466-
"repos_added": repos_added,
467-
"repos_removed": repos_removed,
468-
"repository_selection": repository_selection,
469-
}
470-
)
471-
472-
473421
class PushEventWebhook(GitHubWebhook):
474422
"""https://developer.github.com/v3/activity/events/types/#pushevent"""
475423

@@ -1010,7 +958,6 @@ class GitHubIntegrationsWebhookEndpoint(Endpoint):
1010958
_handlers: dict[GithubWebhookType, type[GitHubWebhook]] = {
1011959
GithubWebhookType.CHECK_RUN: CheckRunEventWebhook,
1012960
GithubWebhookType.INSTALLATION: InstallationEventWebhook,
1013-
GithubWebhookType.INSTALLATION_REPOSITORIES: InstallationRepositoriesEventWebhook,
1014961
GithubWebhookType.ISSUE: IssuesEventWebhook,
1015962
GithubWebhookType.ISSUE_COMMENT: IssueCommentEventWebhook,
1016963
GithubWebhookType.PULL_REQUEST: PullRequestEventWebhook,
Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
from enum import StrEnum
4-
from typing import Any, Literal, TypedDict
54

65
GITHUB_WEBHOOK_TYPE_HEADER = "HTTP_X_GITHUB_EVENT"
76
GITHUB_WEBHOOK_TYPE_HEADER_KEY = "X-GITHUB-EVENT"
@@ -23,25 +22,7 @@ class GithubWebhookType(StrEnum):
2322

2423

2524
# Event type strings (X-GitHub-Event header values) that the cell webhook endpoint processes.
26-
# INSTALLATION and INSTALLATION_REPOSITORIES are handled in control only.
27-
_CONTROL_ONLY_EVENTS = frozenset(
28-
{GithubWebhookType.INSTALLATION, GithubWebhookType.INSTALLATION_REPOSITORIES}
29-
)
25+
# INSTALLATION is handled in control only.
3026
CELL_PROCESSED_GITHUB_EVENTS = frozenset(
31-
t.value for t in GithubWebhookType if t not in _CONTROL_ONLY_EVENTS
27+
t.value for t in GithubWebhookType if t != GithubWebhookType.INSTALLATION
3228
)
33-
34-
35-
class GitHubInstallationRepo(TypedDict):
36-
id: int
37-
full_name: str
38-
private: bool
39-
40-
41-
class InstallationRepositoriesEvent(TypedDict):
42-
action: Literal["added", "removed"]
43-
installation: dict[str, Any]
44-
repositories_added: list[GitHubInstallationRepo]
45-
repositories_removed: list[GitHubInstallationRepo]
46-
repository_selection: Literal["all", "selected"]
47-
sender: dict[str, Any]

src/sentry/integrations/github_enterprise/repository.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from collections.abc import Mapping
21
from typing import Any
32

43
from sentry.integrations.github.repository import GitHubRepositoryProvider
@@ -30,7 +29,7 @@ def _validate_repo(self, client, installation, repo):
3029
return repo_data
3130

3231
def build_repository_config(
33-
self, organization: RpcOrganization, data: Mapping[str, Any]
32+
self, organization: RpcOrganization, data: dict[str, Any]
3433
) -> RepositoryConfig:
3534
integration = integration_service.get_integration(
3635
integration_id=data["integration_id"], provider=self.repo_provider

0 commit comments

Comments
 (0)