Permalink
Browse files

Cucumber scenarios for collaborating, still need to update ticket inf…

…o on collab gitc ready
  • Loading branch information...
1 parent 412a22d commit 4bbca750456ceb5543140ef19d84f35189b66027 @winton committed Feb 21, 2012
Showing with 110 additions and 29 deletions.
  1. +37 −10 features/branch.feature
  2. +4 −4 features/checkout.feature
  3. +2 −2 features/qa.feature
  4. +24 −1 features/ready.feature
  5. +29 −7 features/steps/gitcycle_steps.rb
  6. +14 −5 lib/gitcycle.rb
@@ -10,12 +10,12 @@ Scenario: Yes to all (easiest route)
"""
Your work will eventually merge into 'master'. Is this correct? (y/n)
Retrieving branch information from gitcycle.
- Would you like to name your branch 'ticket.id'? (y/n)
+ Would you like to name your branch 'master-ticket.id'? (y/n)
Adding remote repo 'config.owner/config.repo'.
Fetching remote 'config.owner'.
- Checking out remote branch 'ticket.id' from 'config.owner/config.repo/master'.
+ Checking out remote branch 'master-ticket.id' from 'config.owner/config.repo/master'.
Fetching remote 'origin'.
- Pushing 'origin/ticket.id'.
+ Pushing 'origin/master-ticket.id'.
Sending branch information to gitcycle.
"""
And redis entries valid
@@ -26,19 +26,19 @@ Scenario: Custom branch name
And I execute gitcycle branch with a new URL or string
And I enter "y"
And I enter "n"
- And I enter "ticket.id-rename"
+ And I enter "master-ticket.id-rename"
And gitcycle runs
Then output includes
"""
Your work will eventually merge into 'master'. Is this correct? (y/n)
Retrieving branch information from gitcycle.
- Would you like to name your branch 'ticket.id'? (y/n)
+ Would you like to name your branch 'master-ticket.id'? (y/n)
What would you like to name your branch?
Adding remote repo 'config.owner/config.repo'.
Fetching remote 'config.owner'.
- Checking out remote branch 'ticket.id-rename' from 'config.owner/config.repo/master'.
+ Checking out remote branch 'master-ticket.id-rename' from 'config.owner/config.repo/master'.
Fetching remote 'origin'.
- Pushing 'origin/ticket.id-rename'.
+ Pushing 'origin/master-ticket.id-rename'.
Sending branch information to gitcycle.
"""
And redis entries valid
@@ -58,12 +58,39 @@ Scenario: Change source branch
Your work will eventually merge into 'some_branch'. Is this correct? (y/n)
What branch would you like to eventually merge into?
Retrieving branch information from gitcycle.
- Would you like to name your branch 'ticket.id'? (y/n)
+ Would you like to name your branch 'master-ticket.id'? (y/n)
Adding remote repo 'config.owner/config.repo'.
Fetching remote 'config.owner'.
- Checking out remote branch 'ticket.id' from 'config.owner/config.repo/master'.
+ Checking out remote branch 'master-ticket.id' from 'config.owner/config.repo/master'.
Fetching remote 'origin'.
- Pushing 'origin/ticket.id'.
+ Pushing 'origin/master-ticket.id'.
+ Sending branch information to gitcycle.
+ """
+ And redis entries valid
+
+Scenario: Collaborator
+ Given a fresh set of repositories
+ When I cd to the owner repo
+ And I create a new branch "some_branch"
+ And I checkout some_branch
+ And I push some_branch
+ And I cd to the user repo
+ And I execute gitcycle branch with a new URL or string
+ And I enter "n"
+ And I enter "config.owner/some_branch"
+ And I enter "y"
+ And gitcycle runs
+ Then output includes
+ """
+ Your work will eventually merge into 'master'. Is this correct? (y/n)
+ What branch would you like to eventually merge into?
+ Retrieving branch information from gitcycle.
+ Would you like to name your branch 'config.owner-some_branch-ticket.id'? (y/n)
+ Adding remote repo 'config.owner/config.repo'.
+ Fetching remote 'config.owner'.
+ Checking out remote branch 'config.owner-some_branch-ticket.id' from 'config.owner/config.repo/some_branch'.
+ Fetching remote 'origin'.
+ Pushing 'origin/config.owner-some_branch-ticket.id'.
Sending branch information to gitcycle.
"""
And redis entries valid
@@ -10,9 +10,9 @@ Scenario: Existing branch
Then output includes
"""
Retrieving branch information from gitcycle.
- Checking out branch 'ticket.id'.
+ Checking out branch 'master-ticket.id'.
"""
- And current branch is "ticket.id"
+ And current branch is "master-ticket.id"
Scenario: Fresh repo
Given a fresh set of repositories
@@ -22,6 +22,6 @@ Scenario: Fresh repo
Then output includes
"""
Retrieving branch information from gitcycle.
- Tracking branch 'origin/last_ticket.id'.
+ Tracking branch 'origin/master-last_ticket.id'.
"""
- And current branch is "last_ticket.id"
+ And current branch is "master-last_ticket.id"
View
@@ -25,7 +25,7 @@ Scenario: QA issue
Pushing 'origin/qa_master_config.user'.
Adding remote repo 'config.user/config.repo'.
Fetching remote 'config.user'.
- Merging remote branch 'ticket.id' from 'config.user/config.repo'.
+ Merging remote branch 'master-ticket.id' from 'config.user/config.repo'.
Pushing branch 'qa_master_config.user'.
Type 'gitc qa pass' to approve all issues in this branch.
Type 'gitc qa fail' to reject all issues in this branch.
@@ -80,5 +80,5 @@ Scenario: QA issue list
Then output includes
"""
qa_master_config.user
- issue #issue.id\tconfig.user/last_ticket.id
+ issue #issue.id\tconfig.user/master-last_ticket.id
"""
@@ -17,7 +17,30 @@ Scenario: Ready issue
Merging remote branch 'master' from 'config.owner/config.repo'.
Adding remote repo 'config.user/config.repo'.
Fetching remote 'config.user'.
- Merging remote branch 'ticket.id' from 'config.user/config.repo'.
+ Merging remote branch 'master-ticket.id' from 'config.user/config.repo'.
Creating GitHub pull request.
Labeling issue as 'Pending Review'.
+ """
+
+Scenario: Collaborator
+ Given a fresh set of repositories
+ When I cd to the owner repo
+ And I create a new branch "some_branch"
+ And I checkout some_branch
+ And I push some_branch
+ And I cd to the user repo
+ And I execute gitcycle branch with a new URL or string
+ And I enter "n"
+ And I enter "config.owner/some_branch"
+ And I enter "y"
+ And gitcycle runs
+ And I commit something
+ And I execute gitcycle with "ready"
+ And gitcycle runs
+ Then output includes
+ """
+ Retrieving branch information from gitcycle.
+ Adding remote repo 'config.owner/config.repo'.
+ Fetching remote 'config.owner'.
+ Pushing branch 'config.owner/some_branch'.
"""
@@ -23,6 +23,7 @@
end
$url = url
end
+
@scenario_title = scenario.title
$execute = []
$input = []
@@ -150,6 +151,9 @@ def run_gitcycle(cmd)
@output << "#{str}\n"
puts str
end
+ if @scenario_title.include?('Collaborator')
+ @gitcycle.stub(:collab?).and_return(true)
+ end
if cmd
@gitcycle.start(Shellwords.split(cmd))
else
@@ -206,7 +210,6 @@ def type(text)
:title => "Test ticket"
)
$ticket.save
- $ticket.attributes['id'] = "master-#{$ticket.attributes['id']}"
$tickets ||= []
$tickets << $ticket
$execute << "#{cmd} #{$ticket.url}"
@@ -241,6 +244,11 @@ def type(text)
`git checkout #{branch} -q`
end
+When /^I push (.+)$/ do |branch|
+ branch = gsub_variables(branch)
+ `git push origin #{branch} -q`
+end
+
When /^gitcycle runs$/ do
run_gitcycle($execute.shift) until $execute.empty?
end
@@ -273,6 +281,7 @@ def type(text)
Then /^output includes$/ do |expected|
expected = gsub_variables(expected).gsub('\t', "\t")
+ $stdout.puts expected
@output.gsub(/\n+/, "\n").include?(expected).should == true
end
@@ -282,7 +291,20 @@ def type(text)
end
Then /^redis entries valid$/ do
- add = @scenario_title.include?('Custom branch name') ? "-rename" : ""
+ collab = @scenario_title.include?('Collaborator')
+ before =
+ if collab
+ "br-some_branch-"
+ else
+ "master-"
+ end
+ after =
+ if @scenario_title.include?('Custom branch name')
+ "-rename"
+ else
+ ""
+ end
+ ticket_id = "#{before}#{$ticket.attributes['id']}#{after}"
branch = $redis.hget(
[
"users",
@@ -291,19 +313,19 @@ def type(text)
"#{config['owner']}:#{config['repo']}",
"branches"
].join('/'),
- $ticket.attributes['id'] + add
+ ticket_id
)
branch = Yajl::Parser.parse(branch)
should = {
'lighthouse_url' => $ticket.url,
'body' => "<div><p>test</p></div>\n\n#{$ticket.url}",
- 'home' => ENV['REPO'] == 'owner' ? config['owner'] : config['user'],
- 'name' => $ticket.attributes['id'] + add,
- 'id' => $ticket.attributes['id'] + add,
+ 'home' => collab || ENV['REPO'] == 'owner' ? config['owner'] : config['user'],
+ 'name' => ticket_id,
+ 'id' => ticket_id,
'title' => $ticket.title,
'repo' => "#{config['owner']}:#{config['repo']}",
'user' => config['user'],
- 'source' => 'master'
+ 'source' => collab ? 'some_branch' : 'master'
}
if @scenario_title == 'No parameters and something committed'
should['issue_url'] = $github_url
View
@@ -405,12 +405,15 @@ def ready(*issues)
require_git && require_config
branch = pull
- branch = create_pull_request(branch)
+
+ if branch && !collab?(branch)
+ branch = create_pull_request(branch)
+ end
if branch == false
puts "Branch not found.\n".red
- elsif branch['name'].include?('/')
- remote, branch = branch['name'].split('/')
+ elsif collab?(branch)
+ remote, branch = branch['home'], branch['source']
puts "\nPushing branch '#{remote}/#{branch}'.\n".green
run("git push #{remote} #{branch} -q")
elsif branch['issue_url']
@@ -560,9 +563,15 @@ def checkout_remote_branch(options={})
end
def collab?(branch)
- branch &&
+ return false unless branch
+ owner =
+ if branch['repo'].is_a?(::Hash)
+ branch['repo']['owner']
+ else
+ branch['repo'].split(':')[0]
+ end
branch['home'] != branch['user'] &&
- branch['home'] != branch['repo'].split(':')[0]
+ branch['home'] != owner
end
def command_not_recognized

0 comments on commit 4bbca75

Please sign in to comment.