lib/pt-flow/ui.rb in pt-flow-0.4.2 vs lib/pt-flow/ui.rb in pt-flow-0.5.0

- old
+ new

@@ -1,109 +1,114 @@ -class PT::Flow::UI < PT::UI - def my_work #default command - help - end +module PT::Flow + class UI < PT::UI - def start - tasks = @client.get_work(@project) - table = PT::TasksTable.new(tasks) - title("Available tasks in #{project_to_s}") - task = select("Please select a task to start working on", table) + def my_work #default command + help + 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, @local_config[:user_name]) - start_task(task) - run("git checkout -B #{current_target}-#{task.id}") - end + def start + tasks = @client.get_work(@project) + table = PT::TasksTable.new(tasks) + title("Available tasks in #{project_to_s}") + task = select("Please select a task to start working on", table) + estimate_task(task, ask("How many points do you estimate for it? (#{@project.point_scale})")) if task.estimate && task.estimate < 0 + assign_task(task, @local_config[:user_name]) + start_task(task) + run("git checkout -b #{current_target}-#{task.id}") + end - def finish - run("git push origin #{current_branch}") - task = PivotalTracker::Story.find(current_task_id, @project.id) - title = task.name.gsub('"',"'") + " [##{task.id}]" - run("hub pull-request -b #{github_user}:#{current_target} \"#{title}\"") - finish_task(task) - end + def finish + run("git push origin #{current_branch}") + task = PivotalTracker::Story.find(current_task_id, @project.id) + title = task.name.gsub('"',"'") + " [##{task.id}]" + run("hub pull-request -b #{repo.user}:#{current_target} \"#{title}\"") + finish_task(task) + end - def deliver - run('git fetch') - run("git checkout #{current_target}") - run("git pull --rebase origin #{current_target}") - run("git merge #{current_branch}") - run("git push origin #{current_target}") - run("git push origin :#{current_branch}") - run("git branch -d #{current_branch}") - task = PivotalTracker::Story.find(current_task_id, @project.id) - deliver_task(task) - end + def deliver + run('git fetch') + run("git checkout #{current_target}") + run("git pull --rebase origin #{current_target}") + run("git merge #{current_branch}") + run("git push origin #{current_target}") + run("git push origin :#{current_branch}") + run("git branch -d #{current_branch}") + task = PivotalTracker::Story.find(current_task_id, @project.id) + deliver_task(task) + end - def cleanup - # Update our list of remotes - run("git fetch") - run("git remote prune origin") + def review + table = PullRequestsTable.new(repo.pull_requests) + pull_request = select("Please select a pull request to review", table) + run("git fetch") + run("git checkout #{pull_request.head.ref}") + run("open #{pull_request.html_url}") + rescue Github::Error::Unauthorized => e + error("Error from github: #{e.message}") + end - # Remove local branches fully merged with origin/master - run("git branch --merged origin/master | grep -v 'master$' | xargs git branch -D") + def cleanup + # Update our list of remotes + run("git fetch") + run("git remote prune origin") - # Remove remote branches fully merged with origin/master - run("git branch -r --merged origin/master | sed 's/ *origin\\///' | grep -v 'master$' | xargs -I% git push origin :%") + # Remove local branches fully merged with origin/master + run("git branch --merged origin/master | grep -v 'master$' | xargs git branch -D") - congrats('All clean!') - end + # Remove remote branches fully merged with origin/master + run("git branch -r --merged origin/master | sed 's/ *origin\\///' | grep -v 'master$' | xargs -I% git push origin :%") - def help - if ARGV[0] && ARGV[0] != 'help' - message("Command #{ARGV[0]} not recognized. Showing help.") + congrats('All clean!') end - title("Command line usage") - puts("flow start # start working on a story") - puts("flow finish # finish a story and create a pull request") - puts("flow deliver # merge current story branch and clean up") - puts("flow cleanup # deleted merged local branches and prune origin") - end + def help + if ARGV[0] && ARGV[0] != 'help' + message("Command #{ARGV[0]} not recognized. Showing help.") + end - private - - def assign_task(task, owner) - result = @client.assign_task(@project, task, owner) - if result.errors.any? - error(result.errors.errors) - else - congrats("Task assigned to #{owner}") + title("Command line usage") + puts("flow start # start working on a story") + puts("flow finish # finish a story and create a pull request") + puts("flow review # review a pull request") + puts("flow deliver # merge current branch and clean up") + puts("flow cleanup # deleted merged local/remote branches and prune origin") end - end - def github_user - github_stub.split('/').first - end + private - def github_repo - github_stub.split('/').last - end + def repo + Repo.new + end - def github_stub - @github_stub ||= `git config --get remote.origin.url`.strip.match(/:(\S+\/\S+)\.git/)[1] - end + def assign_task(task, owner) + result = @client.assign_task(@project, task, owner) + if result.errors.any? + error(result.errors.errors) + else + congrats("Task assigned to #{owner}") + end + end - def current_branch - @current_branch ||= `git rev-parse --abbrev-ref HEAD`.strip - end + def current_branch + @current_branch ||= `git rev-parse --abbrev-ref HEAD`.strip + end - def current_target - current_branch.sub(current_task_id, '').chomp('-') - end + def current_target + current_branch.sub(current_task_id, '').chomp('-') + end - def current_task_id - current_branch[/\d+$/] || '' - end + def current_task_id + current_branch[/\d+$/] || '' + end - def run(command) - title(command) - error("Error running: #{command}") unless system(command) - end + def run(command) + title(command) + error("Error running: #{command}") unless system(command) + end - def error(*msg) - super - exit(false) - end + def error(*msg) + super + exit(false) + end + end end