|
15 | 15 | from sentry.integrations.models.repository_project_path_config import RepositoryProjectPathConfig |
16 | 16 | from sentry.integrations.source_code_management.metrics import ( |
17 | 17 | CommitContextHaltReason, |
18 | | - SCMIntegrationInteractionEvent, |
| 18 | + CommitContextIntegrationInteractionEvent, |
19 | 19 | SCMIntegrationInteractionType, |
20 | 20 | ) |
21 | 21 | from sentry.locks import locks |
22 | 22 | from sentry.models.commit import Commit |
23 | 23 | from sentry.models.group import Group |
24 | 24 | from sentry.models.groupowner import GroupOwner |
25 | 25 | from sentry.models.options.organization_option import OrganizationOption |
| 26 | +from sentry.models.organization import Organization |
26 | 27 | from sentry.models.project import Project |
27 | 28 | from sentry.models.pullrequest import ( |
28 | 29 | CommentType, |
@@ -92,10 +93,23 @@ def integration_name(self) -> str: |
92 | 93 | def get_client(self) -> CommitContextClient: |
93 | 94 | raise NotImplementedError |
94 | 95 |
|
95 | | - def record_event(self, event: SCMIntegrationInteractionType): |
96 | | - return SCMIntegrationInteractionEvent( |
| 96 | + def record_event( |
| 97 | + self, |
| 98 | + event: SCMIntegrationInteractionType, |
| 99 | + organization: Organization | None = None, |
| 100 | + project: Project | None = None, |
| 101 | + commit: Commit | None = None, |
| 102 | + repository: Repository | None = None, |
| 103 | + pull_request: PullRequest | None = None, |
| 104 | + ): |
| 105 | + return CommitContextIntegrationInteractionEvent( |
97 | 106 | interaction_type=event, |
98 | 107 | provider_key=self.integration_name, |
| 108 | + organization=organization, |
| 109 | + project=project, |
| 110 | + commit=commit, |
| 111 | + repository=repository, |
| 112 | + pull_request=pull_request, |
99 | 113 | ) |
100 | 114 |
|
101 | 115 | def get_blame_for_files( |
@@ -142,15 +156,11 @@ def queue_comment_task_if_needed( |
142 | 156 | group_id: int, |
143 | 157 | ) -> None: |
144 | 158 | with self.record_event( |
145 | | - SCMIntegrationInteractionType.QUEUE_COMMENT_TASK |
| 159 | + SCMIntegrationInteractionType.QUEUE_COMMENT_TASK, |
| 160 | + organization=project.organization, |
| 161 | + project=project, |
| 162 | + commit=commit, |
146 | 163 | ).capture() as lifecycle: |
147 | | - lifecycle.add_extras( |
148 | | - { |
149 | | - "project_id": project.id, |
150 | | - "organization_id": project.organization_id, |
151 | | - "commit_id": commit.id, |
152 | | - } |
153 | | - ) |
154 | 164 | if not OrganizationOption.objects.get_value( |
155 | 165 | organization=project.organization, |
156 | 166 | key="sentry:github_pr_bot", |
@@ -301,17 +311,9 @@ def create_or_update_comment( |
301 | 311 | else SCMIntegrationInteractionType.UPDATE_COMMENT |
302 | 312 | ) |
303 | 313 |
|
304 | | - with self.record_event(interaction_type).capture() as lifecycle: |
305 | | - lifecycle.add_extras( |
306 | | - { |
307 | | - "repository_id": repo.id, |
308 | | - "organization_id": repo.organization_id, |
309 | | - "pull_request_id": pullrequest_id, |
310 | | - "comment_type": comment_type, |
311 | | - "language": language, |
312 | | - } |
313 | | - ) |
314 | | - |
| 314 | + with self.record_event( |
| 315 | + interaction_type, repository=repo, pull_request_id=pullrequest_id |
| 316 | + ).capture(): |
315 | 317 | if pr_comment is None: |
316 | 318 | resp = client.create_comment( |
317 | 319 | repo=repo.name, |
|
0 commit comments