class Rdv::Issues
Attributes
client[RW]
repo[RW]
Public Class Methods
create_from(client, repo, themes)
click to toggle source
# File lib/rdv/issues.rb, line 66 def self.create_from client, repo, themes new(client, repo).create_issues(themes) end
new(client, repo)
click to toggle source
# File lib/rdv/issues.rb, line 5 def initialize client, repo self.client = client self.repo = repo end
Public Instance Methods
create_issue(issue)
click to toggle source
# File lib/rdv/issues.rb, line 25 def create_issue issue # Serialize the issue to compare it to existing ones serialized = serialize_issue(issue.name, issue.tags) # If issue already exist, don't create it if (existing = existing_issues[serialized]) puts ("Issue \"#{ issue.name }\" not created, already exists " + "as ##{ existing.number } / #{ existing.html_url }").red return end # Create issue in repo client.create_issue(repo, issue.name, issue.content, { labels: issue.tags, assignee: issue.user }) rescue Octokit::UnprocessableEntity => e data = e.response_body # Tell that issue couldn't be created puts "Couldn't create issue \"#{ issue.name }\", #{ data.message }.".red # Display each field with errors data.errors.each do |error| puts "- #{ error.code } #{ error.field } #{ error.value }".red end # Ensure nil is returned so compacting issues array will remove it # from created ones nil end
create_issues(themes)
click to toggle source
Creates issues from the current themes
# File lib/rdv/issues.rb, line 11 def create_issues themes issues = themes.reduce([]) do |issues, theme| main_label = theme.name issues + theme.list.map do |issue| # Add theme as the first issue's tag issue.tags.unshift(main_label) # Create issue create_issue(issue) end end issues.compact end
existing_issues()
click to toggle source
Retrieves all existing issues for the current repo and stores them in a hash with the key being some kind of unique identifier
# File lib/rdv/issues.rb, line 54 def existing_issues @existing_issues ||= client.list_issues(repo).reduce({}) do |hash, issue| hash[serialize_issue(issue.title, issue.labels.map(&:name))] = issue hash end end
serialize_issue(title, labels)
click to toggle source
# File lib/rdv/issues.rb, line 62 def serialize_issue title, labels "#{ title }-#{ labels.sort.join(":") }" end