Module: Gitlab::Import::UsernameMentionRewriter
- Included in:
- BitbucketServerImport::Importers::PullRequestImporter, BitbucketServerImport::Importers::PullRequestNotes::BaseImporter, GithubImport::Importer::NoteImporter, GithubImport::Importer::PullRequestImporter, GithubImport::MarkdownText, Gitlab::ImportExport::Base::RelationFactory, LegacyGithubImport::CommentFormatter, LegacyGithubImport::IssuableFormatter, LegacyGithubImport::MilestoneFormatter
- Defined in:
- lib/gitlab/import/username_mention_rewriter.rb
Constant Summary collapse
- MENTION_REGEX =
Updates @username mentions in description and note text fields, wrapping them in backticks, so that they appear as code-formatted text in the UI. Handles trailing punctuation. Handles usernames containing -, _, /, or . characters Handles already code-formatted text blocks, e.g. ““‘Some example @text“`” or “`Some example @text`” remain unchanged. Handles @ instances in email addresses or urls See gitlab.com/gitlab-org/gitlab/-/issues/477097
Gitlab::UntrustedRegexp.new('(`+[^`]*`+)|((?:^|\s|\()@[\w\-#./]+)')
Instance Method Summary collapse
Instance Method Details
#update_username_mentions(relation_hash) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/gitlab/import/username_mention_rewriter.rb', line 17 def update_username_mentions(relation_hash) if relation_hash['description'] relation_hash['description'] = wrap_mentions_in_backticks(relation_hash['description']) end relation_hash['note'] = wrap_mentions_in_backticks(relation_hash['note']) if relation_hash['note'] end |
#wrap_mentions_in_backticks(text) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gitlab/import/username_mention_rewriter.rb', line 25 def wrap_mentions_in_backticks(text) return text unless text.present? if MENTION_REGEX.match?(text) text = MENTION_REGEX.replace_gsub(text) do |match| case match[0] when /^`/ match[0] when /^ / " `#{match[0].lstrip}`" when /^\(/ "(`#{match[0].sub(/^./, '')}`" else "`#{match[0]}`" end end end text end |