Class: NdrDevSupport::RakeCI::Redmine::TicketResolver
- Inherits:
-
Object
- Object
- NdrDevSupport::RakeCI::Redmine::TicketResolver
- Defined in:
- lib/ndr_dev_support/rake_ci/redmine/ticket_resolver.rb
Overview
This class encapsulates Redmine ticket logic
Constant Summary collapse
- CLOSE_REGEX =
/ ( (?:close[sd]?) # close, closes, closed | (?:resolve[sd]?) # resolve, resolves, resolved | (?:fix(?:e[sd])?) # fix, fixes, fixed ) /ix
- MEGA_REGEX =
/ #{CLOSE_REGEX} | (relate[sd]\sto) # relates to, related to | (?: \[? # optional square bracket \#(\d+) # ticket number with preceding hash character (?:\#note-\d+)? # optional note reference, ignored \]? # optional square bracket \b # word boundary ) /ix
Instance Method Summary collapse
- #each_ticket_from(message, &block) ⇒ Object
-
#initialize(api_key, hostname) ⇒ TicketResolver
constructor
A new instance of TicketResolver.
- #process_commit(user, revision, message, tests_passed) ⇒ Object
- #update_payload(message, user, revision, ticket_closed, resolved, tests_passed) ⇒ Object
Constructor Details
#initialize(api_key, hostname) ⇒ TicketResolver
Returns a new instance of TicketResolver.
31 32 33 34 35 36 37 |
# File 'lib/ndr_dev_support/rake_ci/redmine/ticket_resolver.rb', line 31 def initialize(api_key, hostname) @headers = { 'X-Redmine-API-Key' => api_key, 'Content-Type' => 'application/json' } @hostname = hostname end |
Instance Method Details
#each_ticket_from(message, &block) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ndr_dev_support/rake_ci/redmine/ticket_resolver.rb', line 51 def each_ticket_from(, &block) return enum_for(:each_ticket_from, ) unless block key_words = .scan(MEGA_REGEX).flatten.compact action_groups = key_words.slice_when { |_l, r| r.to_i.to_s != r }.to_a action_groups.each do |group| resolved = group.any? { |word| word =~ CLOSE_REGEX } tickets = group.select { |word| word.to_i.to_s == word }.uniq tickets.each { |ticket| yield(ticket, resolved) } end end |
#process_commit(user, revision, message, tests_passed) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ndr_dev_support/rake_ci/redmine/ticket_resolver.rb', line 39 def process_commit(user, revision, , tests_passed) resolved_tickets = [] each_ticket_from() do |ticket, resolved| update_ticket(, user, revision, ticket, resolved, tests_passed) resolved_tickets << ticket if resolved && tests_passed end resolved_tickets end |
#update_payload(message, user, revision, ticket_closed, resolved, tests_passed) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ndr_dev_support/rake_ci/redmine/ticket_resolver.rb', line 65 def update_payload(, user, revision, ticket_closed, resolved, tests_passed) if resolved && !ticket_closed && !tests_passed += "\n\n*Automated tests did not pass successfully, so ticket status left unchanged.*" end payload = { notes: "_#{resolved ? 'Resolved' : 'Referenced'} by #{user} in #{revision}_:" \ "#{resolved ? .gsub(CLOSE_REGEX, '+\1+') : }" } payload[:status_id] = 3 if resolved && !ticket_closed && tests_passed payload end |