Skip to content

Commit

Permalink
Adds #label_choices
Browse files Browse the repository at this point in the history
  • Loading branch information
NickLaMuro committed Jul 30, 2014
1 parent e5fb250 commit b2a57c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/octopolo/scripts/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def ask_title

# Private: Ask for a label for the pull request
def ask_label
labels = Octopolo::GitHub::Label.all
response = cli.ask(label_prompt, Octopolo::GitHub::Label.get_names(labels).unshift("Don't know yet"))
self.label = Hash[labels.map{|l| [l.name,l]}][response]
choices = Octopolo::GitHub::Label.get_names(label_choices).concat(["None"])
response = cli.ask(label_prompt, choices)
self.label = Hash[label_choices.map{|l| [l.name,l]}][response]
end
private :ask_label

Expand Down Expand Up @@ -123,6 +123,10 @@ def label_prompt
'Label:'
end

def label_choices
Octopolo::GitHub::Label.all
end

def update_pivotal
pivotal_ids.each do |story_id|
Pivotal::StoryCommenter.new(story_id, pull_request.url).perform
Expand Down
17 changes: 14 additions & 3 deletions spec/octopolo/scripts/pull_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ module Scripts
context "#ask_label" do
let(:label1) {Octopolo::GitHub::Label.new(name: "low-risk", color: '151515')}
let(:label2) {Octopolo::GitHub::Label.new(name: "high-risk", color: '151515')}
let(:choices) {["Don't know yet", "low-risk","high-risk"]}
let(:choices) {["low-risk","high-risk","None"]}

it "asks for and capture a label" do
allow(Octopolo::GitHub::Label).to receive(:all) {[label1,label2]}
allow(Octopolo::GitHub::Label).to receive(:get_names) {choices}
expect(cli).to receive(:ask).with("Label:",choices)
expect(cli).to receive(:ask).with("Label:", choices)
subject.send(:ask_label)
end

Expand Down Expand Up @@ -192,6 +192,17 @@ module Scripts
end
end

context "#label_choices" do
let(:label1) { Octopolo::GitHub::Label.new(name: "low-risk", color: '151515') }
let(:label2) { Octopolo::GitHub::Label.new(name: "high-risk", color: '151515') }
let(:github_labels) { [label1, label2] }

it "returns the labels plus 'None'" do
allow(Octopolo::GitHub::Label).to receive(:all) { github_labels }
expect(subject.send(:label_choices)).to eq github_labels
end
end

context "#update_pivotal" do
before do
subject.pivotal_ids = %w(123 234)
Expand Down

0 comments on commit b2a57c3

Please sign in to comment.