Commit 4e533563 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'sy-global-integration' into 'master'

Display GitLab issues created via Sentry's global GitLab integration

See merge request gitlab-org/gitlab!26418
parents 68ef56d4 524eb1aa
---
title: Display GitLab issues created via Sentry global integration
merge_request: 26418
author:
type: fixed
......@@ -75,7 +75,21 @@ module Sentry
http_get(api_urls.issue_url(issue_id))[:body]
end
def parse_gitlab_issue(plugin_issues)
def parse_gitlab_issue(issue)
parse_issue_annotations(issue) || parse_plugin_issue(issue)
end
def parse_issue_annotations(issue)
issue
.fetch('annotations', [])
.reject(&:blank?)
.map { |annotation| Nokogiri.make(annotation) }
.find { |html| html['href']&.starts_with?(Gitlab.config.gitlab.url) }
.try(:[], 'href')
end
def parse_plugin_issue(issue)
plugin_issues = issue.fetch('pluginIssues', nil)
return unless plugin_issues
gitlab_plugin = plugin_issues.detect { |item| item['id'] == 'gitlab' }
......@@ -145,7 +159,7 @@ module Sentry
short_id: issue.fetch('shortId', nil),
status: issue.fetch('status', nil),
frequency: issue.dig('stats', '24h'),
gitlab_issue: parse_gitlab_issue(issue.fetch('pluginIssues', nil)),
gitlab_issue: parse_gitlab_issue(issue),
project_id: issue.dig('project', 'id'),
project_name: issue.dig('project', 'name'),
project_slug: issue.dig('project', 'slug'),
......
......@@ -254,6 +254,34 @@ describe Sentry::Client::Issue do
expect(subject.gitlab_issue).to eq('https://gitlab.com/gitlab-org/gitlab/issues/1')
end
context 'when issue annotations exist' do
before do
issue_sample_response['annotations'] = [
nil,
'',
"<a href=\"http://github.com/issues/6\">github-issue-6</a>",
"<div>annotation</a>",
"<a href=\"http://localhost/gitlab-org/gitlab/issues/2\">gitlab-org/gitlab#2</a>"
]
stub_sentry_request(sentry_request_url, body: issue_sample_response)
end
it 'has a correct GitLab issue url' do
expect(subject.gitlab_issue).to eq('http://localhost/gitlab-org/gitlab/issues/2')
end
end
context 'when no GitLab issue is linked' do
before do
issue_sample_response['pluginIssues'] = []
stub_sentry_request(sentry_request_url, body: issue_sample_response)
end
it 'does not find a GitLab issue' do
expect(subject.gitlab_issue).to be_nil
end
end
it 'has the correct tags' do
expect(subject.tags).to eq({ level: issue_sample_response['level'], logger: issue_sample_response['logger'] })
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment