summaryrefslogtreecommitdiff
path: root/app/models/error_tracking/project_error_tracking_setting.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-06-29 14:14:01 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-06-29 14:14:01 +0000
commita5baa12bfff6c41f6c9cf156edcf8e621f71848e (patch)
tree1a7f51da1300bca04a1bd070f12e66bc4955c832 /app/models/error_tracking/project_error_tracking_setting.rb
parentbb51b8a098aa17b226d1e7941218512f8c835e08 (diff)
downloadgitlab-ce-a5baa12bfff6c41f6c9cf156edcf8e621f71848e.tar.gz
Add latest changes from gitlab-org/security/gitlab@15-1-stable-ee
Diffstat (limited to 'app/models/error_tracking/project_error_tracking_setting.rb')
-rw-r--r--app/models/error_tracking/project_error_tracking_setting.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/app/models/error_tracking/project_error_tracking_setting.rb b/app/models/error_tracking/project_error_tracking_setting.rb
index 3ecfb895dac..30382a1c205 100644
--- a/app/models/error_tracking/project_error_tracking_setting.rb
+++ b/app/models/error_tracking/project_error_tracking_setting.rb
@@ -125,17 +125,22 @@ module ErrorTracking
def issue_details(opts = {})
with_reactive_cache('issue_details', opts.stringify_keys) do |result|
+ ensure_issue_belongs_to_project!(result[:issue].project_id)
result
end
end
def issue_latest_event(opts = {})
with_reactive_cache('issue_latest_event', opts.stringify_keys) do |result|
+ ensure_issue_belongs_to_project!(result[:latest_event].project_id)
result
end
end
def update_issue(opts = {})
+ issue_to_be_updated = sentry_client.issue_details(issue_id: opts[:issue_id])
+ ensure_issue_belongs_to_project!(issue_to_be_updated.project_id)
+
handle_exceptions do
{ updated: sentry_client.update_issue(opts) }
end
@@ -177,6 +182,25 @@ module ErrorTracking
private
+ def ensure_issue_belongs_to_project!(project_id_from_api)
+ raise 'The Sentry issue appers to be outside of the configured Sentry project' if Integer(project_id_from_api) != ensure_sentry_project_id!
+ end
+
+ def ensure_sentry_project_id!
+ return sentry_project_id if sentry_project_id.present?
+
+ raise("Couldn't find project: #{organization_name} / #{project_name} on Sentry") if sentry_project.nil?
+
+ update!(sentry_project_id: sentry_project.id)
+ sentry_project_id
+ end
+
+ def sentry_project
+ strong_memoize(:sentry_project) do
+ sentry_client.projects.find { |project| project.name == project_name && project.organization_name == organization_name }
+ end
+ end
+
def add_gitlab_issue_details(issue)
issue.gitlab_commit = match_gitlab_commit(issue.first_release_version)
issue.gitlab_commit_path = project_commit_path(project, issue.gitlab_commit) if issue.gitlab_commit