Class: MultiRepo::Helpers::UpdateMilestone

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_repo/helpers/update_milestone.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_name, title:, due_on:, close:, dry_run: false) ⇒ UpdateMilestone

Returns a new instance of UpdateMilestone.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
# File 'lib/multi_repo/helpers/update_milestone.rb', line 7

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

Instance Attribute Details

#closeObject (readonly)

Returns the value of attribute close.



5
6
7
# File 'lib/multi_repo/helpers/update_milestone.rb', line 5

def close
  @close
end

#due_onObject (readonly)

Returns the value of attribute due_on.



5
6
7
# File 'lib/multi_repo/helpers/update_milestone.rb', line 5

def due_on
  @due_on
end

#githubObject (readonly)

Returns the value of attribute github.



5
6
7
# File 'lib/multi_repo/helpers/update_milestone.rb', line 5

def github
  @github
end

#repo_nameObject (readonly)

Returns the value of attribute repo_name.



5
6
7
# File 'lib/multi_repo/helpers/update_milestone.rb', line 5

def repo_name
  @repo_name
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/multi_repo/helpers/update_milestone.rb', line 5

def title
  @title
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/multi_repo/helpers/update_milestone.rb', line 17

def run
  due_on_str = due_on.strftime("%Y-%m-%d").inspect

  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}"
    github.update_milestone(repo_name, existing.number, due_on)
  else
    puts "Creating milestone #{title.inspect} with due date #{due_on_str}"
    github.create_milestone(repo_name, title, due_on)
  end
end