blob: 1159159a76d37a990a17b10dd93433bdf8fc7e62 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# frozen_string_literal: true
module Gitlab
module BitbucketImport
class RefConverter
REPO_MATCHER = 'https://bitbucket.org/%s'
PR_NOTE_ISSUE_NAME_REGEX = '(?<=/)[^/\)]+(?=\)[^/]*$)'
UNWANTED_NOTE_REF_HTML = "{: data-inline-card='' }"
attr_reader :project
def initialize(project)
@project = project
end
def convert_note(note)
repo_matcher = REPO_MATCHER % project.import_source
return note unless note.match?(repo_matcher)
note = note.gsub(repo_matcher, url_helpers.project_url(project))
.gsub(UNWANTED_NOTE_REF_HTML, '')
.strip
if note.match?('issues')
note.gsub!('issues', '-/issues')
note.gsub!(issue_name(note), '')
else
note.gsub!('pull-requests', '-/merge_requests')
note.gsub!('src', '-/blob')
note.gsub!('lines-', 'L')
end
note
end
private
def url_helpers
Rails.application.routes.url_helpers
end
def issue_name(note)
note.match(PR_NOTE_ISSUE_NAME_REGEX)[0]
end
end
end
end
|