Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpereira2 <rpereira@gitlab.com>2018-12-13 17:03:01 +0300
committerrpereira2 <rpereira@gitlab.com>2018-12-13 17:03:01 +0300
commitb7fdab6fc8d32ac83b0bceb8b34170ef3e73bdf2 (patch)
tree69e0effcd29646aeb37beb7a4d2abd50ee566cbd
parent361bca7f0babd5d13118126afe62602fbb97fb4a (diff)
Map json issues to ErrorTracking::Errors objects
-rw-r--r--app/services/error_tracking/sentry_issues_service.rb45
1 files changed, 44 insertions, 1 deletions
diff --git a/app/services/error_tracking/sentry_issues_service.rb b/app/services/error_tracking/sentry_issues_service.rb
index 43345c6bd26..d084a56fe23 100644
--- a/app/services/error_tracking/sentry_issues_service.rb
+++ b/app/services/error_tracking/sentry_issues_service.rb
@@ -8,17 +8,60 @@ module ErrorTracking
end
def execute(limit: 20, issue_status: 'unresolved')
+ issues = get_issues(limit, issue_status)
+ map_to_errors(issues)
+ end
+
+ private
+
+ def get_issues(limit, issue_status)
sentry_query = {
query: "is:#{issue_status}",
limit: limit
}
# "query=is:unresolved&limit=#{limit}&sort=date&statsPeriod=24h&shortIdLookup=1"
- Gitlab::HTTP.get(@url.to_s,
+ resp = Gitlab::HTTP.get(@url.to_s,
query: sentry_query,
headers: {
'Authorization' => "Bearer #{@token}"
})
+
+ if resp.code == 200
+ resp.as_json
+ else
+ # TODO: Handle non 200 status (error)
+ []
+ end
+ end
+
+ def map_to_errors(issues)
+ issues.map do |issue|
+ map_to_error(issue)
+ end
+ end
+
+ def map_to_error(issue)
+ project = issue.fetch('project')
+ metadata = issue.fetch('metadata')
+
+ ErrorTracking::Error.new(
+ id: issue.fetch('id'),
+ first_seen: issue.fetch('firstSeen'),
+ last_seen: issue.fetch('lastSeen'),
+ title: issue.fetch('title'),
+ type: issue.fetch('type'),
+ user_count: issue.fetch('userCount'),
+ count: issue.fetch('count'),
+ message: metadata.fetch('value', nil),
+ culprit: issue.fetch('culprit'),
+ external_url: issue.fetch('permalink'),
+ short_id: issue.fetch('shortId'),
+ status: issue.fetch('status'),
+ project_id: project.fetch('id'),
+ project_name: project.fetch('name'),
+ project_slug: project.fetch('slug'),
+ )
end
end
end