Skip to content

Commit ba0d137

Browse files
authored
chore(commits): Remove create_commit dual write function (#102498)
We're no longer planning on using the dual written tables, so removing these functions <!-- Describe your PR here. -->
1 parent 4d7bd87 commit ba0d137

File tree

9 files changed

+21
-219
lines changed

9 files changed

+21
-219
lines changed

src/sentry/integrations/bitbucket/webhook.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from sentry.models.organization import Organization
3030
from sentry.models.repository import Repository
3131
from sentry.plugins.providers import IntegrationRepositoryProvider
32-
from sentry.releases.commits import create_commit
3332
from sentry.utils.email import parse_email
3433

3534
logger = logging.getLogger("sentry.webhooks")
@@ -145,9 +144,9 @@ def __call__(self, event: Mapping[str, Any], **kwargs) -> None:
145144
author = authors[author_email]
146145
try:
147146
with transaction.atomic(router.db_for_write(Commit)):
148-
create_commit(
149-
organization=organization,
150-
repo_id=repo.id,
147+
Commit.objects.create(
148+
repository_id=repo.id,
149+
organization_id=organization.id,
151150
key=commit["hash"],
152151
message=commit["message"],
153152
author=author,

src/sentry/integrations/bitbucket_server/webhook.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from sentry.models.organization import Organization
2727
from sentry.models.repository import Repository
2828
from sentry.plugins.providers import IntegrationRepositoryProvider
29-
from sentry.releases.commits import create_commit
3029
from sentry.shared_integrations.exceptions import ApiHostError, ApiUnauthorized, IntegrationError
3130
from sentry.web.frontend.base import region_silo_view
3231

@@ -132,9 +131,9 @@ def __call__(self, event: Mapping[str, Any], **kwargs) -> None:
132131
author = authors[author_email]
133132
try:
134133
with transaction.atomic(router.db_for_write(Commit)):
135-
create_commit(
136-
organization=organization,
137-
repo_id=repo.id,
134+
Commit.objects.create(
135+
repository_id=repo.id,
136+
organization_id=organization.id,
138137
key=commit["id"],
139138
message=commit["message"],
140139
author=author,

src/sentry/integrations/github/webhook.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
RepoExistsError,
4747
get_integration_repository_provider,
4848
)
49-
from sentry.releases.commits import create_commit
5049
from sentry.seer.autofix.webhooks import handle_github_pr_webhook_for_autofix
5150
from sentry.shared_integrations.exceptions import ApiError
5251
from sentry.users.services.user.service import user_service
@@ -444,9 +443,9 @@ def _handle(
444443
author.preload_users()
445444
try:
446445
with transaction.atomic(router.db_for_write(Commit)):
447-
c, _ = create_commit(
448-
organization=organization,
449-
repo_id=repo.id,
446+
c = Commit.objects.create(
447+
organization_id=organization.id,
448+
repository_id=repo.id,
450449
key=commit["id"],
451450
message=commit["message"],
452451
author=author,

src/sentry/integrations/gitlab/webhooks.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from sentry.organizations.services.organization import organization_service
3434
from sentry.organizations.services.organization.model import RpcOrganization
3535
from sentry.plugins.providers import IntegrationRepositoryProvider
36-
from sentry.releases.commits import create_commit
3736

3837
logger = logging.getLogger("sentry.webhooks")
3938

@@ -252,9 +251,9 @@ def __call__(self, event: Mapping[str, Any], **kwargs):
252251
if author is not None:
253252
author.preload_users()
254253
with transaction.atomic(router.db_for_write(Commit)):
255-
create_commit(
256-
organization=organization,
257-
repo_id=repo.id,
254+
Commit.objects.create(
255+
repository_id=repo.id,
256+
organization_id=organization.id,
258257
key=commit["id"],
259258
message=commit["message"],
260259
author=author,

src/sentry/integrations/utils/commit_context.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from sentry.models.commit import Commit
2929
from sentry.models.commitauthor import CommitAuthor
3030
from sentry.models.organization import Organization
31-
from sentry.releases.commits import create_commit
3231
from sentry.shared_integrations.exceptions import ApiError
3332
from sentry.utils import metrics
3433
from sentry.utils.committers import get_stacktrace_path_from_event_frame
@@ -159,9 +158,9 @@ def get_or_create_commit_from_blame(
159158
email=blame.commit.commitAuthorEmail,
160159
defaults={"name": blame.commit.commitAuthorName},
161160
)
162-
commit, _ = create_commit(
163-
organization=Organization.objects.get(id=organization_id),
164-
repo_id=blame.repo.id,
161+
commit = Commit.objects.create(
162+
organization_id=organization_id,
163+
repository_id=blame.repo.id,
165164
key=blame.commit.commitId,
166165
date_added=blame.commit.committedDate,
167166
author=commit_author,

src/sentry/releases/commits.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import logging
2-
from datetime import datetime
3-
4-
from django.db import router
52

63
from sentry.models.commit import Commit as OldCommit
7-
from sentry.models.commitauthor import CommitAuthor
8-
from sentry.models.organization import Organization
94
from sentry.releases.models import Commit
10-
from sentry.utils.db import atomic_transaction
115

126
logger = logging.getLogger(__name__)
137

@@ -35,33 +29,3 @@ def _dual_write_commit(old_commit: OldCommit) -> Commit:
3529
},
3630
)
3731
return new_commit
38-
39-
40-
def create_commit(
41-
organization: Organization,
42-
repo_id: int,
43-
key: str,
44-
message: str | None = None,
45-
author: CommitAuthor | None = None,
46-
date_added: datetime | None = None,
47-
) -> tuple[OldCommit, Commit]:
48-
with atomic_transaction(
49-
using=(
50-
router.db_for_write(OldCommit),
51-
router.db_for_write(Commit),
52-
)
53-
):
54-
commit_kwargs = {}
55-
if date_added is not None:
56-
commit_kwargs["date_added"] = date_added
57-
58-
old_commit = OldCommit.objects.create(
59-
organization_id=organization.id,
60-
repository_id=repo_id,
61-
key=key,
62-
author=author,
63-
message=message,
64-
**commit_kwargs,
65-
)
66-
new_commit = _dual_write_commit(old_commit)
67-
return old_commit, new_commit

src/sentry_plugins/bitbucket/endpoints/webhook.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
from sentry.integrations.bitbucket.constants import BITBUCKET_IP_RANGES, BITBUCKET_IPS
1515
from sentry.models.commit import Commit
1616
from sentry.models.commitauthor import CommitAuthor
17-
from sentry.models.organization import Organization
1817
from sentry.models.repository import Repository
1918
from sentry.organizations.services.organization.service import organization_service
2019
from sentry.plugins.providers import RepositoryProvider
21-
from sentry.releases.commits import create_commit
2220
from sentry.utils import json
2321
from sentry.utils.email import parse_email
2422

@@ -48,10 +46,6 @@ def __call__(self, organization_id: int, event):
4846
repo.config["name"] = event["repository"]["full_name"]
4947
repo.save()
5048

51-
try:
52-
organization = Organization.objects.get(id=organization_id)
53-
except Organization.DoesNotExist:
54-
raise Http404()
5549
for change in event["push"]["changes"]:
5650
for commit in change.get("commits", []):
5751
if RepositoryProvider.should_ignore_commit(commit["message"]):
@@ -73,9 +67,9 @@ def __call__(self, organization_id: int, event):
7367
author = authors[author_email]
7468
try:
7569
with transaction.atomic(router.db_for_write(Commit)):
76-
create_commit(
77-
organization=organization,
78-
repo_id=repo.id,
70+
Commit.objects.create(
71+
repository_id=repo.id,
72+
organization_id=organization_id,
7973
key=commit["hash"],
8074
message=commit["message"],
8175
author=author,

src/sentry_plugins/github/webhooks/events/push.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from sentry.models.organization import Organization
1616
from sentry.models.repository import Repository
1717
from sentry.plugins.providers import RepositoryProvider
18-
from sentry.releases.commits import create_commit
1918
from sentry.shared_integrations.exceptions import ApiError
2019
from sentry.users.services.user.service import user_service
2120
from sentry_plugins.github.client import GithubPluginClient
@@ -40,11 +39,6 @@ def _handle(self, event, organization_id, is_apps):
4039
except Repository.DoesNotExist:
4140
raise Http404()
4241

43-
try:
44-
organization = Organization.objects.get(id=organization_id)
45-
except Organization.DoesNotExist:
46-
raise Http404()
47-
4842
# We need to track GitHub's "full_name" which is the repository slug.
4943
# This is needed to access the API since `external_id` isn't sufficient.
5044
if repo.config.get("name") != event["repository"]["full_name"]:
@@ -147,9 +141,9 @@ def _handle(self, event, organization_id, is_apps):
147141

148142
try:
149143
with transaction.atomic(router.db_for_write(Commit)):
150-
c, _ = create_commit(
151-
organization=organization,
152-
repo_id=repo.id,
144+
c = Commit.objects.create(
145+
repository_id=repo.id,
146+
organization_id=organization_id,
153147
key=commit["id"],
154148
message=commit["message"],
155149
author=author,

tests/sentry/releases/test_commits.py

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

0 commit comments

Comments
 (0)