Class: Apadmi::Grout::IssuesFromChangelogAction
- Inherits:
-
Object
- Object
- Apadmi::Grout::IssuesFromChangelogAction
- Defined in:
- lib/apadmi/grout/actions/issues_from_changelog_action.rb
Overview
Finds and returns a list of all the issues who’s ids exist in the given changelog
Instance Method Summary collapse
-
#initialize(board_service, ticket_prefix, logger) ⇒ IssuesFromChangelogAction
constructor
A new instance of IssuesFromChangelogAction.
-
#issue_ids_from_changelog(changelog) ⇒ Array<String>
List of issue ids from changelog.
-
#run(changelog) ⇒ Array<Apadmi::Grout::Issue>
List of issues from changelog.
Constructor Details
#initialize(board_service, ticket_prefix, logger) ⇒ IssuesFromChangelogAction
Returns a new instance of IssuesFromChangelogAction.
10 11 12 13 14 |
# File 'lib/apadmi/grout/actions/issues_from_changelog_action.rb', line 10 def initialize(board_service, ticket_prefix, logger) @board_service = board_service @logger = logger @ticket_prefix = ticket_prefix end |
Instance Method Details
#issue_ids_from_changelog(changelog) ⇒ Array<String>
Returns list of issue ids from changelog.
61 62 63 64 65 66 67 68 |
# File 'lib/apadmi/grout/actions/issues_from_changelog_action.rb', line 61 def issue_ids_from_changelog(changelog) # Changelog often has the pull request number in it, this can mess up the parsing so strip it out if we can changelog = changelog.gsub(/\(pull request.*\)/, "") changelog.scan(/(#{@ticket_prefix}\d+)/).flatten.uniq.filter do |id| Integer(id.delete_prefix(@ticket_prefix), exception: false) != 0 # Filter out tickets with ID 0 since these are always placeholders end end |
#run(changelog) ⇒ Array<Apadmi::Grout::Issue>
Returns list of issues from changelog.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/apadmi/grout/actions/issues_from_changelog_action.rb', line 18 def run(changelog) ids = issue_ids_from_changelog(changelog) @logger.("Found issue ids: #{ids.join(", ")}") found_issues = @board_service.find_issues_by_keys(ids) # ADO strips the '#' prefix from returned Issue#key (e.g. '#16' → '16'), # so check both forms when detecting missing tickets. found_keys_normalised = found_issues.to_set { |i| i.key.to_s } missing_ids = ids.reject do |id| normalised = id.delete_prefix(@ticket_prefix.to_s) found_keys_normalised.include?(id) || found_keys_normalised.include?(normalised) end return found_issues if missing_ids.empty? commit_lines = commit_line_for_ids(changelog) fallback_issues = missing_ids.map do |id| Apadmi::Grout::Issue.unclassified(id, commit_lines[id] || id) end found_issues + fallback_issues end |