Class: PT::Flow::UI

Inherits:
UI
  • Object
show all
Defined in:
lib/pt-flow/ui.rb

Instance Method Summary collapse

Constructor Details

#initialize(command, args = []) ⇒ UI

Returns a new instance of UI.



4
5
6
# File 'lib/pt-flow/ui.rb', line 4

def initialize(command, args = [])
  super [command] + (args)
end

Instance Method Details

#cleanupObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pt-flow/ui.rb', line 55

def cleanup
  title("Cleaning merged story branches for [#{branch.target}]")

  # Update our list of remotes
  run("git fetch")
  run("git remote prune origin")

  # Only clean out merged story branches for current topic
  filter = "^ *#{branch.target}.\\+[0-9]\\+$"

  # Remove local branches fully merged with origin/current_target
  run("git branch --merged origin/#{branch.target} | grep '#{filter}' | xargs git branch -D")

  # Remove remote branches fully merged with origin/master
  run("git branch -r --merged origin/#{branch.target} | sed 's/ *origin\\///' | grep '#{filter}' | xargs -I% git push origin :%")

  congrats("Deleted branches merged with [#{branch.target}]")
end

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pt-flow/ui.rb', line 27

def create
  name = @params[0] || ask("Name for the new story:")
  types = { 'c' => 'chore', 'b' => 'bug', 'f' => 'feature' }
  task_type = types[ask('Type? (c)hore, (b)ug, (f)eature')]
  task = @project.stories.create(name: name, requested_by: user_name, story_type: task_type)
  if task.errors.any?
    error(task.errors.errors)
  else
    congrats("#{task_type} created: #{task.url}")
    task
  end
end

#finishObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pt-flow/ui.rb', line 40

def finish
  @options = Trollop::options(@params.dup) do
    opt :deliver, 'Merge branch automatically'
    opt :wip, 'submits [WIP] pull request'
  end

  run "git push origin #{branch} -u"
  if @options[:deliver]
    deliver!
  else
    finish_task(current_task) unless @options[:wip]
    open_url pull_request_url
  end
end

#startObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pt-flow/ui.rb', line 8

def start
  @options = Trollop::options(@params.dup) do
    opt :filter, 'Allow filtering tasks', type: :string
  end

  if @params[0] && !@params[0].start_with?('--')
    task = create
  else
    filter = filters[@options[:filter]] || { current_state: 'unstarted,started' }
    table = TasksTable.new @project.stories.all(filter)
    title("Available tasks in #{project_to_s}")
    task = select("Please select a task to start working on", table)
  end
  estimate_task(task, ask("How many points do you estimate for it? (#{@project.point_scale})")) if task.estimate && task.estimate < 0
  assign_task(task, user_name)
  start_task(task)
  run("git checkout -b #{Branch.from_task(task)}")
end