Class: Gitcamp::Cli
- Inherits:
-
Thor
- Object
- Thor
- Gitcamp::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/gitcamp/cli.rb
Instance Method Summary collapse
Instance Method Details
#milestone ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/gitcamp/cli.rb', line 87 def milestone say "\n Creating a GitHub milestone & issues from a Basecamp todo list" say " Press ^C at any time to abort\n\n" # Authenticate with Basecamp auth = Gitcamp::Basecamp::Auth.new auth.login # Get all active projects projects = BasecampClassic::Project.all.select { |project| project.status == 'active' } # Ask user to select a project say "\n Which Basecamp project is the todo list in?\n\n" choose do || .prompt = 'Enter a number from the list above:' projects.each do |project| .choice "#{project.name}" do @project = project end end end say "Chosen project: #{@project.name}" todolists = BasecampClassic::TodoList.all(@project.id) # Ask user to select a todolist to use say "\n Which Basecamp todo list do you want to import?\n\n" choose do || .prompt = 'Enter a number from the list above:' todolists.each do |todolist| .choice "#{todolist.name} (#{todolist.uncompleted_count} incomplete todos)" do @todolist = todolist end end end say "Chosen todo list: #{@todolist.name}" # Authenicate with Github auth = Gitcamp::Github::Auth.new @github = auth.login # What repo are we adding to? repo = ask 'Enter a GitHub repo name (eg. owner/repo) to create the milestone in:' # Confirm pending operation to user? say "\n Read and confirm the action below:\n\n" if yes? "Are you sure you want to create (or update) a GitHub milestone named '#{@todolist.name}' in the repo '#{repo}' and add the #{@todolist.uncompleted_count} todos in Basecamp todo list '#{@todolist.name}' as issues? (y/n)", Thor::Shell::Color::CYAN # Find or create a milestone milestone = Gitcamp::Github::Milestone.new(github: @github, repo: repo, todolist: @todolist) milestone.save todo_items = BasecampClassic::TodoItem.find(:all, :params => { :todo_list_id => @todolist.id }) todo_items.each do |todo_item| next if todo_item.completed issue = Gitcamp::Github::Issue.new(github: @github, milestone: milestone, repo: repo, todo: todo_item, todolist: @todolist) issue.save end else say 'No action taken, exiting' exit true end end |
#todolist ⇒ Object
8 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 80 81 82 83 84 |
# File 'lib/gitcamp/cli.rb', line 8 def todolist say "\n Creating a Basecamp todo list from a milestone of GitHub issues" say " Press ^C at any time to abort\n\n" # Authenicate with Github auth = Gitcamp::Github::Auth.new @github = auth.login # 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 say "\n Which GitHub milestone do you want to import?\n\n" choose do || .prompt = 'Enter a number from the list above:' milestones.each do |milestone| .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.login # Get all active projects projects = BasecampClassic::Project.all.select { |project| project.status == 'active' } # Ask user to select a project say "\n Which Basecamp project do you want to create the todo list in?\n\n" choose do || .prompt = 'Enter a number from the list above:' projects.each do |project| .choice "#{project.name}" do @project = project end end end say "Chosen project: #{@project.name}" say "\n Read and confirm the action below:\n\n" # Confirm pending operation to user? if yes? "Are you sure you want to create (or update) a Basecamp todo list named '#{@milestone.title}' in the '#{@project.name}' project and add the #{@milestone.open_issues} GitHub issues as Basecamp todo items? (y/n)", Thor::Shell::Color::CYAN # Try to find an existing TodoList in Basecamp todo_lists = BasecampClassic::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 = BasecampClassic::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 |