Skip to content

Commit d5a3714

Browse files
Revert "feat(commit-context): Do not create if older than 1 year (#54624)"
This reverts commit 14935b6. Co-authored-by: asottile-sentry <[email protected]>
1 parent b6cc323 commit d5a3714

File tree

3 files changed

+10
-73
lines changed

3 files changed

+10
-73
lines changed

src/sentry/integrations/utils/commit_context.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import logging
4-
from datetime import datetime, timedelta, timezone
54
from typing import Any, List, Mapping, Sequence, Tuple
65

76
import sentry_sdk
@@ -109,14 +108,7 @@ def find_commit_context_for_event(
109108
},
110109
)
111110

112-
# Only return suspect commits that are less than a year old
113-
if commit_context and is_date_less_than_year(commit_context["committedDate"]):
111+
if commit_context:
114112
result.append((commit_context, code_mapping))
115113

116114
return result, installation
117-
118-
119-
def is_date_less_than_year(date):
120-
return datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ").replace(
121-
tzinfo=timezone.utc
122-
) > datetime.now(tz=timezone.utc) - timedelta(days=365)

tests/sentry/tasks/test_commit_context.py

+8-61
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from datetime import datetime, timedelta
2-
from datetime import timezone as datetime_timezone
1+
from datetime import timedelta
32
from unittest.mock import Mock, patch
43

54
import pytest
@@ -84,9 +83,7 @@ class TestCommitContext(TestCommitContextMixin):
8483
"sentry.integrations.github.GitHubIntegration.get_commit_context",
8584
return_value={
8685
"commitId": "asdfwreqr",
87-
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)).strftime(
88-
"%Y-%m-%dT%H:%M:%SZ"
89-
),
86+
"committedDate": "2023-02-14T11:11Z",
9087
"commitMessage": "placeholder commit message",
9188
"commitAuthorName": "",
9289
"commitAuthorEmail": "admin@localhost",
@@ -144,51 +141,11 @@ def test_failed_to_fetch_commit_context_record(self, mock_get_commit_context, mo
144141
error_message="integration_failed",
145142
)
146143

147-
@patch("sentry.tasks.commit_context.logger")
148144
@patch(
149145
"sentry.integrations.github.GitHubIntegration.get_commit_context",
150146
return_value={
151147
"commitId": "asdfasdf",
152-
"committedDate": (
153-
datetime.now(tz=datetime_timezone.utc) - timedelta(days=370)
154-
).strftime("%Y-%m-%dT%H:%M:%SZ"),
155-
"commitMessage": "placeholder commit message",
156-
"commitAuthorName": "",
157-
"commitAuthorEmail": "admin@localhost",
158-
},
159-
)
160-
def test_found_commit_is_too_old(self, mock_get_commit_context, mock_logger):
161-
with self.tasks():
162-
assert not GroupOwner.objects.filter(group=self.event.group).exists()
163-
event_frames = get_frame_paths(self.event)
164-
process_commit_context(
165-
event_id=self.event.event_id,
166-
event_platform=self.event.platform,
167-
event_frames=event_frames,
168-
group_id=self.event.group_id,
169-
project_id=self.event.project_id,
170-
)
171-
172-
assert mock_logger.info.call_count == 1
173-
mock_logger.info.assert_called_with(
174-
"process_commit_context.find_commit_context",
175-
extra={
176-
"event": self.event.event_id,
177-
"group": self.event.group_id,
178-
"organization": self.event.group.project.organization_id,
179-
"reason": "could_not_fetch_commit_context",
180-
"code_mappings_count": 1,
181-
"fallback": True,
182-
},
183-
)
184-
185-
@patch(
186-
"sentry.integrations.github.GitHubIntegration.get_commit_context",
187-
return_value={
188-
"commitId": "asdfasdf",
189-
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)).strftime(
190-
"%Y-%m-%dT%H:%M:%SZ"
191-
),
148+
"committedDate": "2023-02-14T11:11Z",
192149
"commitMessage": "placeholder commit message",
193150
"commitAuthorName": "",
194151
"commitAuthorEmail": "admin@localhost",
@@ -213,9 +170,7 @@ def test_no_matching_commit_in_db(self, mock_get_commit_context):
213170
"sentry.integrations.github.GitHubIntegration.get_commit_context",
214171
return_value={
215172
"commitId": "asdfwreqr",
216-
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)).strftime(
217-
"%Y-%m-%dT%H:%M:%SZ"
218-
),
173+
"committedDate": "2023-02-14T11:11Z",
219174
"commitMessage": "placeholder commit message",
220175
"commitAuthorName": "",
221176
"commitAuthorEmail": "admin@localhost",
@@ -300,9 +255,7 @@ def test_no_inapp_frame_in_stacktrace(self, mock_process_suspect_commits):
300255
"sentry.integrations.github.GitHubIntegration.get_commit_context",
301256
return_value={
302257
"commitId": "somekey",
303-
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)).strftime(
304-
"%Y-%m-%dT%H:%M:%SZ"
305-
),
258+
"committedDate": "2023-02-14T11:11Z",
306259
"commitMessage": "placeholder commit message",
307260
"commitAuthorName": "",
308261
"commitAuthorEmail": "[email protected]",
@@ -343,9 +296,7 @@ def test_commit_author_not_in_sentry(self, mock_get_commit_context):
343296
"sentry.integrations.github.GitHubIntegration.get_commit_context",
344297
return_value={
345298
"commitId": "somekey",
346-
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)).strftime(
347-
"%Y-%m-%dT%H:%M:%SZ"
348-
),
299+
"committedDate": "2023-02-14T11:11Z",
349300
"commitMessage": "placeholder commit message",
350301
"commitAuthorName": "",
351302
"commitAuthorEmail": "[email protected]",
@@ -386,9 +337,7 @@ def test_commit_author_no_user(self, mock_get_commit_context, mock_get_users_for
386337
"sentry.integrations.github.GitHubIntegration.get_commit_context",
387338
return_value={
388339
"commitId": "somekey",
389-
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)).strftime(
390-
"%Y-%m-%dT%H:%M:%SZ"
391-
),
340+
"committedDate": "2023-02-14T11:11Z",
392341
"commitMessage": "placeholder commit message",
393342
"commitAuthorName": "",
394343
"commitAuthorEmail": "[email protected]",
@@ -474,9 +423,7 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo):
474423
Mock(
475424
return_value={
476425
"commitId": "asdfwreqr",
477-
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)).strftime(
478-
"%Y-%m-%dT%H:%M:%SZ"
479-
),
426+
"committedDate": "2023-02-14T11:11Z",
480427
"commitMessage": "placeholder commit message",
481428
"commitAuthorName": "",
482429
"commitAuthorEmail": "admin@localhost",

tests/sentry/tasks/test_post_process.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1303,9 +1303,7 @@ def test_issue_owners_should_ratelimit(self, logger):
13031303
class ProcessCommitsTestMixin(BasePostProgressGroupMixin):
13041304
github_blame_return_value = {
13051305
"commitId": "asdfwreqr",
1306-
"committedDate": (datetime.now(timezone.utc) - timedelta(days=2)).strftime(
1307-
"%Y-%m-%dT%H:%M:%SZ"
1308-
),
1306+
"committedDate": "",
13091307
"commitMessage": "placeholder commit message",
13101308
"commitAuthorName": "",
13111309
"commitAuthorEmail": "admin@localhost",

0 commit comments

Comments
 (0)