-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(commit-context): do not create suspect commits older than 1 year #55013
Changes from 9 commits
4fec5b2
b366a98
53a1f44
704f922
2e4e0fc
b442023
ab340d7
81b93a7
1d4fd3f
850770a
eb6b306
6c8537d
6e9972a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from datetime import timedelta | ||
from datetime import datetime, timedelta | ||
from datetime import timezone as datetime_timezone | ||
from unittest.mock import Mock, patch | ||
|
||
import pytest | ||
|
@@ -83,7 +84,7 @@ class TestCommitContext(TestCommitContextMixin): | |
"sentry.integrations.github.GitHubIntegration.get_commit_context", | ||
return_value={ | ||
"commitId": "asdfwreqr", | ||
"committedDate": "2023-02-14T11:11Z", | ||
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)), | ||
"commitMessage": "placeholder commit message", | ||
"commitAuthorName": "", | ||
"commitAuthorEmail": "admin@localhost", | ||
|
@@ -141,11 +142,47 @@ def test_failed_to_fetch_commit_context_record(self, mock_get_commit_context, mo | |
error_message="integration_failed", | ||
) | ||
|
||
@patch("sentry.tasks.commit_context.logger") | ||
@patch( | ||
"sentry.integrations.github.GitHubIntegration.get_commit_context", | ||
return_value={ | ||
"commitId": "asdfasdf", | ||
"committedDate": "2023-02-14T11:11Z", | ||
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=370)), | ||
"commitMessage": "placeholder commit message", | ||
"commitAuthorName": "", | ||
"commitAuthorEmail": "admin@localhost", | ||
}, | ||
) | ||
def test_found_commit_is_too_old(self, mock_get_commit_context, mock_logger): | ||
with self.tasks(): | ||
assert not GroupOwner.objects.filter(group=self.event.group).exists() | ||
event_frames = get_frame_paths(self.event) | ||
process_commit_context( | ||
event_id=self.event.event_id, | ||
event_platform=self.event.platform, | ||
event_frames=event_frames, | ||
group_id=self.event.group_id, | ||
project_id=self.event.project_id, | ||
) | ||
|
||
assert mock_logger.info.call_count == 1 | ||
mock_logger.info.assert_called_with( | ||
"process_commit_context.find_commit_context", | ||
extra={ | ||
"event": self.event.event_id, | ||
"group": self.event.group_id, | ||
"organization": self.event.group.project.organization_id, | ||
"reason": "could_not_fetch_commit_context", | ||
"code_mappings_count": 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ehh it could be that only one of the code mappings/installations had the old commit. |
||
"fallback": True, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the fallback mean that we would use the previous version of suspect commits? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
) | ||
|
||
@patch( | ||
"sentry.integrations.github.GitHubIntegration.get_commit_context", | ||
return_value={ | ||
"commitId": "asdfasdf", | ||
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)), | ||
"commitMessage": "placeholder commit message", | ||
"commitAuthorName": "", | ||
"commitAuthorEmail": "admin@localhost", | ||
|
@@ -170,7 +207,7 @@ def test_no_matching_commit_in_db(self, mock_get_commit_context): | |
"sentry.integrations.github.GitHubIntegration.get_commit_context", | ||
return_value={ | ||
"commitId": "asdfwreqr", | ||
"committedDate": "2023-02-14T11:11Z", | ||
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)), | ||
"commitMessage": "placeholder commit message", | ||
"commitAuthorName": "", | ||
"commitAuthorEmail": "admin@localhost", | ||
|
@@ -255,7 +292,7 @@ def test_no_inapp_frame_in_stacktrace(self, mock_process_suspect_commits): | |
"sentry.integrations.github.GitHubIntegration.get_commit_context", | ||
return_value={ | ||
"commitId": "somekey", | ||
"committedDate": "2023-02-14T11:11Z", | ||
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)), | ||
"commitMessage": "placeholder commit message", | ||
"commitAuthorName": "", | ||
"commitAuthorEmail": "randomuser@sentry.io", | ||
|
@@ -296,7 +333,7 @@ def test_commit_author_not_in_sentry(self, mock_get_commit_context): | |
"sentry.integrations.github.GitHubIntegration.get_commit_context", | ||
return_value={ | ||
"commitId": "somekey", | ||
"committedDate": "2023-02-14T11:11Z", | ||
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)), | ||
"commitMessage": "placeholder commit message", | ||
"commitAuthorName": "", | ||
"commitAuthorEmail": "randomuser@sentry.io", | ||
|
@@ -337,7 +374,7 @@ def test_commit_author_no_user(self, mock_get_commit_context, mock_get_users_for | |
"sentry.integrations.github.GitHubIntegration.get_commit_context", | ||
return_value={ | ||
"commitId": "somekey", | ||
"committedDate": "2023-02-14T11:11Z", | ||
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)), | ||
"commitMessage": "placeholder commit message", | ||
"commitAuthorName": "", | ||
"commitAuthorEmail": "randomuser@sentry.io", | ||
|
@@ -423,7 +460,7 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo): | |
Mock( | ||
return_value={ | ||
"commitId": "asdfwreqr", | ||
"committedDate": "2023-02-14T11:11Z", | ||
"committedDate": (datetime.now(tz=datetime_timezone.utc) - timedelta(days=7)), | ||
"commitMessage": "placeholder commit message", | ||
"commitAuthorName": "", | ||
"commitAuthorEmail": "admin@localhost", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to codecov, the block above is not being tested. Please look into it before we merge this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a test to increase coverage.