lib/octopolo/github/label.rb in octopolo-0.1.0 vs lib/octopolo/github/label.rb in octopolo-0.1.1

- old
+ new

@@ -1,6 +1,5 @@ -require_relative "../github" require "yaml" require "octokit" module Octopolo module GitHub @@ -8,23 +7,23 @@ extend ConfigWrapper attr_accessor :name attr_accessor :color - def initialize(name, color) - self.name = name - self.color = color + def initialize(args) + self.name = args[:name] + self.color = args[:color] end def == (obj) (self.name == obj.name) ? true : false end # Public: Grabs all labels from either file or github # This is the method to override for labels from files - def self.all_labels - from_github + def self.all + all_from_repo end # Public: Gets the names of labels # # label_array - an array of labels @@ -36,51 +35,31 @@ # Public: Checks to see if label exists on remote, if not makes one. # # label - a label object def self.first_or_create(label) - unless all_labels.include?(label) + unless all.include?(label) GitHub.add_label(config.github_repo, label.name, label.color) end end - # Public: Adds labels to a pull-request + # Public: Finds or creates each of the passed in labels # - # labels - an array of labels - # pull_number - number of the pull_request to add label to - def self.add_to_pull(pull_number, *labels) - built_labels = build_label_array(labels) - GitHub.add_labels_to_pull(config.github_repo, pull_number, get_names(built_labels) ) - end - - # Private: takes in a hash, out puts a label - # - # label_hash - a hashed label + # labels - label objects, can be a single label, an array of labels, + # or a list of labels # - # returns - a label - def self.to_label(label_hash) - Label.new(label_hash[:name], label_hash[:color]) + # returns - an array of labels. + def self.build_label_array(*labels) + Array(labels).flatten.each {|label| first_or_create(label)} end - private_class_method :to_label # Private: Gets all the labels from given repository on github # # returns - an array of labels - def self.from_github - GitHub.labels(config.github_repo).map{ |label_hash| to_label(label_hash) } + def self.all_from_repo + GitHub.labels(config.github_repo).map{ |label_hash| new(label_hash) } end - private_class_method :from_github + private_class_method :all_from_repo - # Private: Finds or creates each of the passed in labels - # - # labels - label objects, can be a single label, an array of labels, - # or a list of labels - # - # returns - an array of labels. - def self.build_label_array(*labels) - Array(labels).flatten.each {|label| first_or_create(label)} - end - private_class_method :build_label_array - end end -end \ No newline at end of file +end