lib/jira_sync/plugin.rb in danger-jira_sync-0.0.3 vs lib/jira_sync/plugin.rb in danger-jira_sync-0.0.4

- old
+ new

@@ -74,11 +74,11 @@ labels = fetch_labels_from_issues(issue_keys) return if labels.empty? create_missing_github_labels(labels) - github.api.add_labels_to_an_issue(repo, issue_number, labels) + add_labels_to_issue(labels) labels end private @@ -91,10 +91,12 @@ @issue_number ||= github.pr_json["number"] end def github_labels @github_labels ||= github.api.labels(repo) + rescue Octokit::Error => e + warn "#{e.response_status} Error while retrieving GitHub labels: #{e.message}" end def extract_issue_keys_from_pull_request(key_prefixes) # Match all key_prefixes followed by a dash then numbers, e.g. "DEV-12345" re = Regexp.new(/((#{key_prefixes.join("|")})-\d+)/) @@ -124,11 +126,21 @@ def create_missing_github_labels(labels) missing_labels = labels - github_labels missing_labels.each do |label| color = SecureRandom.hex(3) - github.api.add_label(repo, label, color) + begin + github.api.add_label(repo, label, color) + rescue Octokit::Error => e + warn "#{e.response_status} Error while creating GitHub label \"#{label}\" with color \"#{color}\": #{e.message}" + end end missing_labels + end + + def add_labels_to_issue(labels) + github.api.add_labels_to_an_issue(repo, issue_number, labels) + rescue Octokit::Error => e + warn "#{e.response_status} Error while adding labels [#{labels}] to GitHub issue: #{e.message}" end end end