Class: BBFlow::PullRequester
- Inherits:
-
Object
- Object
- BBFlow::PullRequester
- Extended by:
- Memoist
- Defined in:
- lib/bb_flow/pull_requester.rb
Constant Summary collapse
- ADVERTISEMENT =
"\n\n<sub>This pull request has been created using [bb-flow](https://github.com/brightbytes/bb-flow).</sub>"
Class Method Summary collapse
- .add_pull_request_to_cards(pull_request) ⇒ Object
- .create! ⇒ void
- .ensure_has_remote! ⇒ void
- .ensure_pushed! ⇒ void
- .move_cards_to_done_list ⇒ void
Class Method Details
.add_pull_request_to_cards(pull_request) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bb_flow/pull_requester.rb', line 75 def add_pull_request_to_cards(pull_request) puts 'Adding the pull request to the trello cards...' cards.reject { |card| card..map(&:url).include?(pull_request.html_url) }.each do |card| # Note that this title is formatted in a special way that makes Trello recognize it as # a GitHub PR instead of a regular attachment. title = "#{pull_request.head.repo.name} ##{pull_request.number} #{pull_request.title}" card.(pull_request.html_url, title) end end |
.create! ⇒ void
This method returns an undefined value.
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 |
# File 'lib/bb_flow/pull_requester.rb', line 11 def create! ensure_has_remote! ensure_pushed! existing_pull_request = Github.find_pull_request if existing_pull_request Printer.success("A pull request for this branch already exists.\n#{existing_pull_request.html_url}") else response = Github.create_pull_request(title, Misc.edit(body_template) + ADVERTISEMENT) unless labels.empty? Github.add_labels_to_pull_request(response.number, labels) end unless cards.empty? add_pull_request_to_cards(response) if Options.get(:base_branch) == Options.default(:base_branch) || Printer.simple_question("You're going to merge into a non-default branch. Would you still like me to move the #{Misc.pluralize('card', cards.size)}?") move_cards_to_done_list end end Printer.success('The pull request has been created, sir.') Misc.open_url(response.html_url) end rescue Octokit::Error => exception Printer.error(exception.) end |
.ensure_has_remote! ⇒ void
This method returns an undefined value.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bb_flow/pull_requester.rb', line 43 def ensure_has_remote! unless Github.has_branch? question = "The branch isn't pushed yet. Would you like me to push it for you?" if Printer.simple_question(question) Misc.execute("git push --set-upstream #{Github.remote_name} #{Misc.git.current_branch}") else puts "Sorry, you should push your local branch to remote before creating a pull request." puts 'Exiting...' exit end end end |
.ensure_pushed! ⇒ void
This method returns an undefined value.
58 59 60 61 62 63 64 65 66 |
# File 'lib/bb_flow/pull_requester.rb', line 58 def ensure_pushed! unless Github.pushed? question = "Your local branch is ahead of '#{Github.remote_branch}' by #{Github.unpushed_commits_number} commits. Would you like me to push it?" if Printer.simple_question(question) Misc.execute("git push --set-upstream #{Github.remote_name} #{Misc.git.current_branch}") end end end |
.move_cards_to_done_list ⇒ void
This method returns an undefined value.
69 70 71 72 |
# File 'lib/bb_flow/pull_requester.rb', line 69 def move_cards_to_done_list puts "Moving cards to the „#{Trello.done_list.name}“ list..." cards.each { |card| card.move_to_list(Trello.done_list) } end |