Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make expedite's branch form more flexible #135

Merged
merged 9 commits into from
Nov 4, 2019
Merged
2 changes: 1 addition & 1 deletion lib/octopolo/commands/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
c.desc "Branch to create the pull request against"
c.flag [:d, :dest, :destination], :arg_name => "destination_branch", :default_value => Octopolo.config.deploy_branch

c.desc "Pass -x to skip the prompt and infer from branch. Expects the branch to be in this format: JIRA-123_describe_pr"
c.desc "Pass -x to skip the prompt and infer from branch. Expects the branch to be in this format: JIRA-123_describe_pr OR JIRA_123_describe_pr"
c.switch [:x, :expedite], :arg_name => "expedite"

c.desc "Use $EDITOR to update PR description before creating"
Expand Down
25 changes: 15 additions & 10 deletions lib/octopolo/scripts/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def execute
GitHub.connect do

if options[:expedite]
infer_questionaire
infer_questionnaire
else
ask_questionaire
ask_questionnaire
pete2786 marked this conversation as resolved.
Show resolved Hide resolved
end

create_pull_request
Expand All @@ -43,33 +43,38 @@ def execute
end

# Private: Ask questions to create a pull request
def ask_questionaire
def ask_questionnaire
alert_reserved_and_exit if git.reserved_branch?
announce
ask_title
ask_labels
ask_pivotal_ids if config.use_pivotal_tracker
ask_jira_ids if config.use_jira
end
private :ask_questionaire
private :ask_questionnaire

def infer_questionaire
def infer_questionnaire
alert_reserved_and_exit if git.reserved_branch?
check_branch_format
branch_arr = git.current_branch.split('_')
issue = branch_arr[0].upcase
descr = branch_arr[1..-1].join(' ')
if issue.include?('-')
descr = branch_arr[1..-1].join(' ')
else
issue = "#{issue}-#{branch_arr[1]}"
descr = branch_arr[2..-1].join(' ')
end

self.title = "#{issue} #{descr}"
self.title = "#{issue} #{descr.capitalize}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize the first letter of the description

self.pivotal_ids = [issue] if config.use_pivotal_tracker
self.jira_ids = [issue] if config.use_jira
end
private :infer_questionaire
private :infer_questionnaire

def check_branch_format
return if /.*-\d+_.*/ =~ git.current_branch
return if (/.*-\d+_.*/ =~ git.current_branch || /.*_\d+_.*/ =~ git.current_branch)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/[A-Za-z]+-\d+_.*/ and /[A-Za-z]+_\d+_.*/ for regex because we probably want them to always start with a letter.


cli.say "Branch must match format like 'iss-123_describe_branch' to expedite"
cli.say "Branch must match format like 'iss-123_describe_branch' or 'iss_123_describe_branch' to expedite"
exit 1
end
private :check_branch_format
Expand Down
30 changes: 20 additions & 10 deletions spec/octopolo/scripts/pull_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module Scripts
context "#execute" do
it "if connected to GitHub, asks some questions, creates the pull request, and opens it" do
GitHub.should_receive(:connect).and_yield
expect(subject).to receive(:ask_questionaire)
expect(subject).to receive(:ask_questionnaire)
expect(subject).to receive(:create_pull_request)
expect(subject).to receive(:update_pivotal)
expect(subject).to receive(:update_jira)
Expand All @@ -61,15 +61,15 @@ module Scripts
end
end

context "#ask_questionaire" do
context "#ask_questionnaire" do
it "asks appropriate questions to create a pull request" do
expect(subject).to receive(:announce)
expect(subject).to receive(:ask_title)
expect(subject).to receive(:ask_pivotal_ids)
expect(subject).to receive(:ask_jira_ids)
expect(subject).to receive(:ask_labels)

subject.send(:ask_questionaire)
subject.send(:ask_questionnaire)
end

context "when checking for staging branch" do
Expand All @@ -85,29 +85,39 @@ module Scripts

subject.should_receive(:alert_reserved_and_exit)

subject.send(:ask_questionaire)
subject.send(:ask_questionnaire)
end

it "should not ask if the branch is not staging" do
subject.git.stub(:reserved_branch?).and_return false

subject.should_not_receive(:alert_reserved_and_exit)

subject.send(:ask_questionaire)
subject.send(:ask_questionnaire)
end
end
end

context "#expedite" do
subject { PullRequest.new(nil, { expedite: true }) }

context 'good format' do
context 'good format 1' do
let(:current_branch) { 'abc-123_so_fast'}

it 'likes the issue-123_blah branch format' do
subject.send(:infer_questionaire)
subject.send(:infer_questionnaire)
expect(subject.jira_ids).to eq(['ABC-123'])
expect(subject.title).to eq('ABC-123 so fast')
expect(subject.title).to eq('ABC-123 So fast')
end
end

context 'good format 2' do
let(:current_branch) { 'abc_123_so_fast'}

it 'likes the issue-123_blah branch format' do
subject.send(:infer_questionnaire)
expect(subject.jira_ids).to eq(['ABC-123'])
expect(subject.title).to eq('ABC-123 So fast')
end
end

Expand All @@ -117,15 +127,15 @@ module Scripts
it 'does not like other branch format' do
subject.git.stub(:reserved_branch?).and_return false
cli.should_receive(:say)
expect { subject.send(:infer_questionaire) }.to raise_error(SystemExit)
expect { subject.send(:infer_questionnaire) }.to raise_error(SystemExit)
end
end

it 'does not process reserved' do
subject.git.stub(:reserved_branch?).and_return true
subject.should_receive(:alert_reserved_and_exit).and_call_original
cli.should_receive(:say)
expect { subject.send(:infer_questionaire) }.to raise_error(SystemExit)
expect { subject.send(:infer_questionnaire) }.to raise_error(SystemExit)
end
end

Expand Down