Class: Gitcamp::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/gitcamp/cli.rb

Instance Method Summary collapse

Instance Method Details

#todolistObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/gitcamp/cli.rb', line 9

def todolist

  # Authenicate with Github
  auth = Gitcamp::Github::Auth.new
  @github = auth.

  # What repo are we working from?
  repo = ask 'Enter a GitHub repo name (eg. owner/repo) to pick milestones from:'

  # Get all milestones
  milestones = @github.list_milestones(repo)

  # Ask user to select a milestone to use
  choose do |menu|
    menu.prompt = 'Which milestone do you want to import?'
    milestones.each do |milestone|
      menu.choice "#{milestone.title} (#{milestone.open_issues} open issues)" do
        @milestone = milestone
      end
    end
  end

  say "Chosen milestone: #{@milestone.title}"

  # Authenticate with Basecamp
  auth = Gitcamp::Basecamp::Auth.new
  auth.

  # Get all active projects
  projects = Basecamp::API::Classic::Project.all.select { |project| project.status == 'active' }

  # Ask user to select a project
  choose do |menu|
    menu.prompt = 'Which project do you want to create the TODO list in?'
    projects.each do |project|
      menu.choice "#{project.name}" do
        @project = project
      end
    end
  end

  say "Chosen project: #{@project.name}"

  # Confirm pending operation to user?
  if yes? "Are you sure you want to create a Todo list named '#{@milestone.title}' in the #{@project.name} Basecamp project and add the #{@milestone.open_issues} issues as Todo items? (y/n)", Thor::Shell::Color::CYAN

    # Try to find an existing TodoList in Basecamp
    todo_lists = Basecamp::API::Classic::TodoList.all(@project.id)
    todo_list = todo_lists.find { |tdl| tdl.name == @milestone.title }

    # If it doesn't exist, create one
    unless todo_list
      todo_list = Basecamp::API::Classic::TodoList.new(:name => @milestone.title, :description => @milestone.description, :project_id => @project.id)
      todo_list.save

      say "Created todo list: #{todo_list.name}"
    else
      say "Using existing todo list: #{todo_list.name}"
    end

    issues = @github.list_issues(repo, :milestone => @milestone.number)
    issues.each do |issue|
      todo = Gitcamp::Basecamp::Todo.new(list: todo_list, issue: issue)
      todo.save
    end

  else
    say 'No action taken, exiting'
    exit true
  end
end