Sha256: 3e0013a7577fd53dcd1fc5ce9665315bcd39242657a53422881bc98e8aab1591

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents


module MultiRepo::Helpers
  class UpdateMilestone
    attr_reader :repo_name, :title, :due_on, :close, :github

    def initialize(repo_name, title:, due_on:, close:, dry_run: false, **)
      raise ArgumentError, "due_on must be specified" if due_on.nil? && !close

      @repo_name = repo_name
      @title     = title
      @due_on    = MultiRepo::Service::Github.parse_milestone_date(due_on) if due_on
      @close     = close
      @github    = MultiRepo::Service::Github.new(dry_run: dry_run)
    end

    def run
      existing = github.find_milestone_by_title(repo_name, title)
      if close
        if existing
          puts "Closing milestone #{title.inspect} (#{existing.number})"
          github.close_milestone(repo.name, title, existing.number)
        end
      elsif existing
        puts "Updating milestone #{title.inspect} (#{existing.number}) with due date #{due_on_str.inspect}"
        github.update_milestone(repo.name, existing.number, due_on)
      else
        puts "Creating milestone #{title.inspect} with due date #{due_on_str.inspect}"
        github.create_milestone(repo.name, title, due_on)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
multi_repo-0.1.1 lib/multi_repo/helpers/update_milestone.rb
multi_repo-0.1.0 lib/multi_repo/helpers/update_milestone.rb