Class: Onair::TaskLink
- Inherits:
-
Data
- Object
- Data
- Onair::TaskLink
- Defined in:
- lib/onair/task_link.rb
Overview
Optional, tracker-agnostic task linking. Configured entirely by the user:
task:
pattern: 'ABC-\d+'
url: 'https://acme.atlassian.net/browse/{task}'
Any regex match in a commit subject becomes a link to the templated URL (task is replaced with the matched text). No config — no behavior.
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#url_template ⇒ Object
readonly
Returns the value of attribute url_template.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern
12 13 14 |
# File 'lib/onair/task_link.rb', line 12 def pattern @pattern end |
#url_template ⇒ Object (readonly)
Returns the value of attribute url_template
12 13 14 |
# File 'lib/onair/task_link.rb', line 12 def url_template @url_template end |
Class Method Details
.from_config(section) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/onair/task_link.rb', line 13 def self.from_config(section) return nil if section.nil? pattern = section["pattern"].to_s url = section["url"].to_s raise Error, "task config needs both `pattern` and `url`" if pattern.empty? || url.empty? raise Error, "task.url must contain the {task} placeholder" unless url.include?("{task}") new(pattern: Regexp.new(pattern), url_template: url) rescue RegexpError => e raise Error, "invalid task.pattern: #{e.}" end |
Instance Method Details
#find(subject) ⇒ Object
26 27 28 |
# File 'lib/onair/task_link.rb', line 26 def find(subject) subject&.[](pattern) end |
#url_for(task_id) ⇒ Object
30 31 32 |
# File 'lib/onair/task_link.rb', line 30 def url_for(task_id) url_template.gsub("{task}", task_id) end |