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:
Diffstat (limited to 'lib/gitlab/bitbucket_import/ref_converter.rb')
-rw-r--r--lib/gitlab/bitbucket_import/ref_converter.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/gitlab/bitbucket_import/ref_converter.rb b/lib/gitlab/bitbucket_import/ref_converter.rb
new file mode 100644
index 00000000000..1159159a76d
--- /dev/null
+++ b/lib/gitlab/bitbucket_import/ref_converter.rb
@@ -0,0 +1,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