Skip to content

Commit

Permalink
Moving to configuration via command line
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Nov 19, 2012
1 parent f4da050 commit 4ff5d35
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 133 deletions.
93 changes: 47 additions & 46 deletions features/branch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Feature: Branch
Scenario: Yes to all (easiest route)
Given a fresh set of repositories
When I cd to the user repo
And I enter "config.user"
And I execute gitcycle branch with a new URL or string
And I give default input
And gitcycle runs
Expand All @@ -20,50 +21,50 @@ Scenario: Yes to all (easiest route)
"""
And redis entries valid

Scenario: Custom branch name
Given a fresh set of repositories
When I cd to the user repo
And I execute gitcycle branch with a new URL or string
And I enter "y"
And I enter "n"
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 '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 'master-ticket.id-rename' from 'config.owner/config.repo/master'.
Fetching remote 'origin'.
Pushing 'origin/master-ticket.id-rename'.
Sending branch information to gitcycle.
"""
And redis entries valid
# Scenario: Custom branch name
# Given a fresh set of repositories
# When I cd to the user repo
# And I execute gitcycle branch with a new URL or string
# And I enter "y"
# And I enter "n"
# 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 '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 'master-ticket.id-rename' from 'config.owner/config.repo/master'.
# Fetching remote 'origin'.
# Pushing 'origin/master-ticket.id-rename'.
# Sending branch information to gitcycle.
# """
# And redis entries valid

Scenario: Change source branch
Given a fresh set of repositories
When I cd to the user repo
And I create a new branch "some_branch"
And I checkout some_branch
And I execute gitcycle branch with a new URL or string
And I enter "n"
And I enter "master"
And I enter "y"
And gitcycle runs
Then output includes
"""
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 'master-ticket.id'? (y/n)
Adding remote repo 'config.owner/config.repo'.
Fetching remote 'config.owner'.
Checking out remote branch 'master-ticket.id' from 'config.owner/config.repo/master'.
Fetching remote 'origin'.
Pushing 'origin/master-ticket.id'.
Sending branch information to gitcycle.
"""
And redis entries valid
# Scenario: Change source branch
# Given a fresh set of repositories
# When I cd to the user repo
# And I create a new branch "some_branch"
# And I checkout some_branch
# And I execute gitcycle branch with a new URL or string
# And I enter "n"
# And I enter "master"
# And I enter "y"
# And gitcycle runs
# Then output includes
# """
# 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 'master-ticket.id'? (y/n)
# Adding remote repo 'config.owner/config.repo'.
# Fetching remote 'config.owner'.
# Checking out remote branch 'master-ticket.id' from 'config.owner/config.repo/master'.
# Fetching remote 'origin'.
# Pushing 'origin/master-ticket.id'.
# Sending branch information to gitcycle.
# """
# And redis entries valid
56 changes: 55 additions & 1 deletion features/setup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,58 @@ Scenario: Setup
When I execute gitcycle setup
And gitcycle runs
Then output includes "Configuration saved."
And gitcycle.yml should be valid
And gitcycle.yml should be valid

Scenario: Gitcycle command on non-repo
When I cd to a non-repo
And I execute gitcycle with "pull"
And gitcycle runs
Then gitcycle exits
And output includes
"""
You are not in a git repository.
"""

Scenario: Gitcycle command on repo with invalid origin
When I cd to a non-repo
And I run "git init ."
And I execute gitcycle with "pull"
And gitcycle runs
Then gitcycle exits
And output includes
"""
Please make sure you have a valid 'origin' remote.
See http://gitref.org/remotes
"""

Scenario: Gitcycle command on repo with unauthenticated user
When I cd to a non-repo
And I run "git init ."
And I run "git remote add origin git@github.com:winton/gitcycle_test.git"
And I execute gitcycle with "pull"
And I enter "blah"
And gitcycle runs
Then gitcycle exits
And output includes
"""
What is your github username?
Please set up gitcycle for 'blah' at gitcycle.com/setup
"""
And open "http://gitcycle.com/setup" in browser

Scenario: Gitcycle command on repo with authenticated user
When I cd to a non-repo
And I run "git init ."
And I run "git remote add origin git@github.com:winton/gitcycle_test.git"
And I execute gitcycle with "pull"
And I enter "config.user"
And I enter "config.lighthouse_token"
And gitcycle runs
Then output includes
"""
What is your github username?
Configuration saved.
Retrieving repo information from gitcycle.
What is your Lighthouse API token?
Gitcycle could not determine the branch you are on.
"""
53 changes: 33 additions & 20 deletions features/steps/gitcycle_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
$ticket = nil

File.open("#{BASE}/features/fixtures/gitcycle.yml", 'w') do |f|
yaml = {
"#{config['user']}/#{config['repo']}" => [ config['user'], config['token_dev'] ],
"#{config['owner']}/#{config['repo']}" => [ config['user'], config['token_qa'] ],
}
yaml = { 'auth' => {} }
yaml['auth'][config['user']] = config['token']
f.write(YAML.dump(yaml))
end
end
Expand Down Expand Up @@ -74,6 +72,7 @@ def gsub_variables(str)
str = str.gsub('config.owner', config['owner'])
str = str.gsub('config.repo', config['repo'])
str = str.gsub('config.user', config['user'])
str = str.gsub('config.lighthouse_token', config['lighthouse']['token'])
str
end

Expand All @@ -95,7 +94,9 @@ def repos(reload=false)
system [
"rm -rf #{fixtures}/owner_cache",
"rm -rf #{fixtures}/user_cache",
"rm -rf #{fixtures}/non_repo",
"mkdir -p #{fixtures}/owner_cache",
"mkdir -p #{fixtures}/non_repo",
"cd #{fixtures}/owner_cache",
"git init . -q",
"git remote add origin git@github.com:#{config['owner']}/#{config['repo']}.git",
Expand Down Expand Up @@ -197,14 +198,7 @@ def type(text)
$execute << [
"setup",
config['user'],
config['repo'],
config['token_dev']
].join(' ')
$execute << [
"setup",
config['user'],
"#{config['owner']}/#{config['repo']}",
config['token_qa']
config['token']
].join(' ')
end

Expand Down Expand Up @@ -232,6 +226,13 @@ def type(text)
Dir.chdir($repos[(ENV['REPO'] || user).to_sym])
end

When /^I cd to a non-repo$/ do
non_repo = "#{BASE}/features/fixtures/non_repo"
`rm -rf #{non_repo}`
`mkdir -p #{non_repo}`
Dir.chdir("#{BASE}/features/fixtures/non_repo")
end

When /^I enter "([^\"]*)"$/ do |input|
input = gsub_variables(input)
type(input)
Expand All @@ -256,7 +257,12 @@ def type(text)
end

When /^gitcycle runs$/ do
run_gitcycle($execute.shift) until $execute.empty?
@exited = false
begin
run_gitcycle($execute.shift) until $execute.empty?
rescue SystemExit => e
@exited = true
end
end

When /^I resolve the conflict/ do
Expand All @@ -269,6 +275,10 @@ def type(text)
sleep seconds.to_i
end

When /^I run "(.+)"$/ do |cmd|
`#{cmd}`
end

Then /^gitcycle runs with exit$/ do
$execute.each do |cmd|
lambda { run_gitcycle(cmd) }.should raise_error SystemExit
Expand All @@ -277,12 +287,7 @@ def type(text)

Then /^gitcycle\.yml should be valid$/ do
gitcycle = YAML.load(File.read(GITCYCLE))

repo = "#{config['user']}/#{config['repo']}"
gitcycle[repo].should == [ config['user'], config['token_dev'] ]

repo = "#{config['owner']}/#{config['repo']}"
gitcycle[repo].should == [ config['user'], config['token_qa'] ]
gitcycle['auth'][config['user']].should == config['token']
end

Then /^output includes \"([^\"]*)"$/ do |expected|
Expand Down Expand Up @@ -348,7 +353,7 @@ def type(text)
branch.should == should
end

Then /^current branch is \"([^\"]*)"$/ do |branch|
Then /^current branch is "([^\"]*)"$/ do |branch|
branches(:current => true).should == gsub_variables(branch)
end

Expand All @@ -362,4 +367,12 @@ def type(text)

Then /^URL is not the same as the last$/ do
$last_url.should_not == $url
end

Then /^gitcycle exits$/ do
@exited.should == true
end

Then /^open "(.*?)" in browser$/ do |url|
$url.should == url
end
Loading

0 comments on commit 4ff5d35

Please sign in to comment.