summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpereira2 <rpereira@gitlab.com>2018-12-13 15:03:01 +0100
committerPeter Leitzen <pleitzen@gitlab.com>2019-01-02 19:42:05 +0100
commit3a3a2db4ba3315498ea6344376f0e6e074eccf92 (patch)
tree8b060f33fb1be46732ef09639edd3379ffbec470
parent978173b4a4295284e4ddb9f3885869d3567a12aa (diff)
downloadgitlab-ce-3a3a2db4ba3315498ea6344376f0e6e074eccf92.tar.gz
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