lib/jira_sync/plugin.rb in danger-jira_sync-0.0.6 vs lib/jira_sync/plugin.rb in danger-jira_sync-0.0.7
- old
+ new
@@ -59,22 +59,30 @@
# Labels the Pull Request with Jira Project Keys and Component Names
#
# @param issue_prefixes [Array<String>] An array of issue key prefixes;
# this is often the project key. These must be present in the title or
# body of the Pull Request
+ # @param project [Boolean] Label using the Jira Ticket's Project Key?
+ # @param components [Boolean] Label using the Jira Ticket's Component Names?
+ # @param labels [Boolean] Label using the Jira Ticket's Labels?
#
# @return [Array<String>, nil] The list of project & component labels
# that were applied or nil if no issue or labels were found
#
- def autolabel_pull_request(issue_prefixes)
+ def autolabel_pull_request(issue_prefixes, project: true, components: true, labels: false)
raise NotConfiguredError unless @jira_client
raise(ArgumentError, "issue_prefixes cannot be empty") if issue_prefixes.empty?
issue_keys = extract_issue_keys_from_pull_request(issue_prefixes)
return if issue_keys.empty?
- labels = fetch_labels_from_issues(issue_keys)
+ labels = fetch_labels_from_issues(
+ issue_keys,
+ project: project,
+ components: components,
+ labels: labels
+ )
return if labels.empty?
create_missing_github_labels(labels)
add_labels_to_issue(labels)
@@ -106,23 +114,24 @@
github.pr_title.gsub(re) { |match| keys << match }
github.pr_body.gsub(re) { |match| keys << match } if keys.empty?
keys.compact.uniq
end
- def fetch_labels_from_issues(issue_keys)
- labels = []
+ def fetch_labels_from_issues(issue_keys, project: true, components: true, labels: false)
+ issue_labels = []
issue_keys.each do |key|
begin
issue = @jira_client.Issue.find(key)
- labels << issue.project.key
- labels += issue.components.map(&:name)
+ issue_labels << issue.project.key if project
+ issue_labels += issue.components.map(&:name) if components
+ issue_labels += issue.fields["labels"] if labels
rescue JIRA::HTTPError => e
warn "#{e.code} Error while retrieving JIRA issue \"#{key}\": #{e.message}"
# No reason to continue if Unauthorized
break if e.code == 503
end
end
- labels.compact.uniq
+ issue_labels.compact.uniq
end
def create_missing_github_labels(labels)
missing_labels = labels - github_labels
missing_labels.each do |label|