Class: Dependabot::PullRequestCreator::MessageBuilder::IssueLinker
- Inherits:
-
Object
- Object
- Dependabot::PullRequestCreator::MessageBuilder::IssueLinker
- Defined in:
- lib/dependabot/pull_request_creator/message_builder/issue_linker.rb
Constant Summary collapse
- TAG_REGEX =
/(?<tag>(?:\#|GH-)\d+)/.freeze
- ISSUE_LINK_REGEXS =
[ /(?<=[^A-Za-z0-9\[\\]|^)\\*#{TAG_REGEX}(?=[^A-Za-z0-9\-]|$)/.freeze, /\[#{TAG_REGEX}\](?=[^A-Za-z0-9\-\(])/.freeze, /\[(?<tag>(?:\#|GH-)?\d+)\]\(\)/.freeze ].freeze
Instance Attribute Summary collapse
-
#source_url ⇒ Object
readonly
Returns the value of attribute source_url.
Instance Method Summary collapse
-
#initialize(source_url:) ⇒ IssueLinker
constructor
A new instance of IssueLinker.
- #link_issues(text:) ⇒ Object
Constructor Details
#initialize(source_url:) ⇒ IssueLinker
Returns a new instance of IssueLinker.
18 19 20 |
# File 'lib/dependabot/pull_request_creator/message_builder/issue_linker.rb', line 18 def initialize(source_url:) @source_url = source_url end |
Instance Attribute Details
#source_url ⇒ Object (readonly)
Returns the value of attribute source_url.
16 17 18 |
# File 'lib/dependabot/pull_request_creator/message_builder/issue_linker.rb', line 16 def source_url @source_url end |
Instance Method Details
#link_issues(text:) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dependabot/pull_request_creator/message_builder/issue_linker.rb', line 22 def link_issues(text:) # Loop through each of the issue link regexes, replacing any instances # of them with an absolute link that uses the source URL ISSUE_LINK_REGEXS.reduce(text) do |updated_text, regex| updated_text.gsub(regex) do |issue_link| tag = issue_link. match(/(?<tag>(?:\#|GH-)?\d+)/). named_captures.fetch("tag") number = tag.match(/\d+/).to_s "[#{tag}](#{source_url}/issues/#{number})" end end end |