-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(repos): Add audit logs when auto syncing repositories #112056
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| """ | ||
| Audit log helpers for repository sync operations. | ||
| """ | ||
|
|
||
| from sentry import audit_log | ||
| from sentry.integrations.services.repository.model import RpcRepository | ||
| from sentry.utils.audit import create_system_audit_entry | ||
|
|
||
|
|
||
| def log_repo_change( | ||
| *, event_name: str, organization_id: int, repo: RpcRepository, source: str, provider: str | ||
| ) -> None: | ||
| create_system_audit_entry( | ||
| organization_id=organization_id, | ||
| target_object=repo.id, | ||
| event=audit_log.get_event_id(event_name), | ||
| data={ | ||
| "repo_name": repo.name, | ||
| "external_id": repo.external_id, | ||
| "source": source, | ||
| "provider": provider, | ||
| }, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,13 +240,21 @@ def create_repositories( | |
| self, | ||
| configs: list[RepositoryInputConfig], | ||
| organization: RpcOrganization, | ||
| ): | ||
| ) -> tuple[list[RpcRepository], list[RpcRepository], list[RepositoryConfig]]: | ||
| """ | ||
| Create or update repositories from configs. | ||
| Returns (created, reactivated, missing) — newly created repos, repos that | ||
| were reactivated or updated from a hidden/unlinked state, and repo configs | ||
| that could not be created because a repository with that configuration | ||
| already exists. | ||
| """ | ||
| external_id_to_repo_config: dict[str, RepositoryConfig] = {} | ||
| for config in configs: | ||
| result = self.build_repository_config(organization=organization, data=config) | ||
| external_id_to_repo_config[result["external_id"]] = result | ||
|
|
||
| repos_to_update: list[RpcRepository] = [] | ||
| created_repos: list[RpcRepository] = [] | ||
|
|
||
| hidden_repos = repository_service.get_repositories( | ||
| organization_id=organization.id, | ||
|
|
@@ -272,6 +280,7 @@ def create_repositories( | |
| organization_id=organization.id, create=create_repository | ||
| ) | ||
| if new_repository is not None: | ||
| created_repos.append(new_repository) | ||
| continue | ||
|
|
||
| missing_repos.append(repo_config) | ||
|
|
@@ -299,8 +308,7 @@ def create_repositories( | |
| updates=repos_to_update, | ||
| ) | ||
|
|
||
| if missing_repos: | ||
| raise RepoExistsError(repos=missing_repos) | ||
| return created_repos, repos_to_update, missing_repos | ||
|
Contributor
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. Spurious REPO_ENABLED logs for already-active reposLow Severity The second return value of Additional Locations (2)Reviewed by Cursor Bugbot for commit 784ec6e. Configure here. |
||
|
|
||
| def dispatch(self, request: Request, organization, **kwargs): | ||
| try: | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.