lib/github_labeler.rb
def execute_changes(changes, options = {})
    @logger.debug "Executing changes"

    if !is_remaining_rate_limit_sufficient?(changes.size)
      @logger.error "Remaining rate limit is not enough to make all changes. Wait for the limit to refresh and try again."
      return []
    end

    changes = validate_changes(changes, options)

    changes.each do |change|
      @logger.debug "Executing change: #{change_string(change)}"

      if change[:type] == "add"
        success = @client.add_label(change[:repo], change[:label][:name], change[:label][:color])

        if !@repo_labels[change[:repo]].nil?
          @repo_labels[change[:repo]][success[:name].downcase] = {:name => success[:name], :color => success[:color]}
        end

        @logger.debug "Change succeded"
        next
      end

      if change[:type] == "update"
        new_label = {:name => change[:label][:new_name] || change[:label][:name]}
        if !change[:label][:color].nil?
          new_label[:color] = change[:label][:color]
        end

        success = @client.update_label(change[:repo], change[:label][:name], new_label)

        if !@repo_labels[change[:repo]].nil?
          @repo_labels[change[:repo]][success[:name].downcase] = {:name => success[:name], :color => success[:color]}
        end

        @logger.debug "Change succeded"
        next
      end

      if change[:type] == "delete"
        success = @client.delete_label!(change[:repo], change[:label][:name])

        if !@repo_labels[change[:repo]].nil?
          @repo_labels[change[:repo]][change[:label][:name].downcase] = nil
        end

        @logger.debug "Change succeded"
        next
      end
    end

    @logger.debug "Done executing changes"

    return changes
  end
#
# Executes a list of label changes. Each change has the following format:
#
# {
#   :type => "update/create/delete",
#   :repo => "testrename/testing",
#   :label => {:color => "fc2929", :name => "design", :new_name => "ui"}
# }
#
Executes a list of label changes.
Executes a list of label changes .
def execute_changes(changes, options = {})
    @logger.debug "Executing changes"
    if !is_remaining_rate_limit_sufficient?(changes.size)
      @logger.error "Remaining rate limit is not enough to make all changes. Wait for the limit to refresh and try again."
      return []
    end
    changes = validate_changes(changes, options)
    changes.each do |change|
      @logger.debug "Executing change: #{change_string(change)}"
      if change[:type] == "add"
        success = @client.add_label(change[:repo], change[:label][:name], change[:label][:color])
        if !@repo_labels[change[:repo]].nil?
          @repo_labels[change[:repo]][success[:name].downcase] = {:name => success[:name], :color => success[:color]}
        end
        @logger.debug "Change succeded"
        next
      end
      if change[:type] == "update"
        new_label = {:name => change[:label][:new_name] || change[:label][:name]}
        if !change[:label][:color].nil?
          new_label[:color] = change[:label][:color]
        end
        success = @client.update_label(change[:repo], change[:label][:name], new_label)
        if !@repo_labels[change[:repo]].nil?
          @repo_labels[change[:repo]][success[:name].downcase] = {:name => success[:name], :color => success[:color]}
        end
        @logger.debug "Change succeded"
        next
      end
      if change[:type] == "delete"
        success = @client.delete_label!(change[:repo], change[:label][:name])
        if !@repo_labels[change[:repo]].nil?
          @repo_labels[change[:repo]][change[:label][:name].downcase] = nil
        end
        @logger.debug "Change succeded"
        next
      end
    end
    @logger.debug "Done executing changes"
    return changes
  end
def execute_changes ( changes , options = { } ) @logger . debug "Executing changes" if ! is_remaining_rate_limit_sufficient? ( changes . size ) @logger . error "Remaining rate limit is not enough to make all changes. Wait for the limit to refresh and try again." return [ ] end changes = validate_changes ( changes , options ) changes . each do | change | @logger . debug "Executing change: #{change_string(change)}" if change [ :type ] == "add" success = @client . add_label ( change [ :repo ] , change [ :label ] [ :name ] , change [ :label ] [ :color ] ) if ! @repo_labels [ change [ :repo ] ] . nil? @repo_labels [ change [ :repo ] ] [ success [ :name ] . downcase ] = { :name => success [ :name ] , :color => success [ :color ] } end @logger . debug "Change succeded" next end if change [ :type ] == "update" new_label = { :name => change [ :label ] [ :new_name ] || change [ :label ] [ :name ] } if ! change [ :label ] [ :color ] . nil? new_label [ :color ] = change [ :label ] [ :color ] end success = @client . update_label ( change [ :repo ] , change [ :label ] [ :name ] , new_label ) if ! @repo_labels [ change [ :repo ] ] . nil? @repo_labels [ change [ :repo ] ] [ success [ :name ] . downcase ] = { :name => success [ :name ] , :color => success [ :color ] } end @logger . debug "Change succeded" next end if change [ :type ] == "delete" success = @client . delete_label! ( change [ :repo ] , change [ :label ] [ :name ] ) if ! @repo_labels [ change [ :repo ] ] . nil? @repo_labels [ change [ :repo ] ] [ change [ :label ] [ :name ] . downcase ] = nil end @logger . debug "Change succeded" next end end @logger . debug "Done executing changes" return changes end
Executes a list of label changes.
Executes a list of label changes .
changes
options