Skip to content
Browse files

Merge branch 'master' into new_ui

Conflicts:
	lib/gitcycle.rb
  • Loading branch information...
2 parents 80f2e79 + 66b6891 commit 3bc4270dd4c2b2c20e160ad4e86eee93123f62bf @winton committed Jul 9, 2013
Showing with 125 additions and 38 deletions.
  1. +1 −0 .ruby-gemset
  2. +1 −0 .ruby-version
  3. +14 −1 README.md
  4. +5 −5 features/setup.feature
  5. +1 −1 features/steps/gitcycle_steps.rb
  6. +3 −1 features/support/env.rb
  7. +3 −1 gitcycle.gemspec
  8. +97 −29 lib/gitcycle.rb
View
1 .ruby-gemset
@@ -0,0 +1 @@
+gitcycle
View
1 .ruby-version
@@ -0,0 +1 @@
+ruby-2.0.0-p247
View
15 README.md
@@ -76,6 +76,13 @@ When the branch is ready for code review:
This will label the pull request as "Pending Review".
+Open
+----
+
+If you want to view the pull request without updating the ticket:
+
+ gitc open
+
Code Review
-----------
@@ -142,6 +149,12 @@ Checkout a branch from a ticket URL:
gitc checkout [TICKET URL]
+### From Ticket Number
+
+Checkout a branch from a ticket #:
+
+ gitc checkout [TICKET NUMBER]
+
### From User's Fork
gitc checkout user/branch
@@ -169,4 +182,4 @@ Nice to haves:
$ gitc st - shortcut
* gitc clean # to clean up old branches
* fail should change to inactive
-* gitc pull: shouldnt matter who does it, it should update the latest br/rc, not working https://gist.github.com/22b1e248e8dba7a32288
+* gitc pull: shouldnt matter who does it, it should update the latest br/rc, not working https://gist.github.com/22b1e248e8dba7a32288
View
10 features/setup.feature
@@ -1,10 +1,10 @@
Feature: Setup
-Scenario: Setup
- When I execute gitcycle setup
- And gitcycle runs
- Then output includes "Configuration saved."
- And gitcycle.yml should be valid
+# Scenario: Setup
+# When I execute gitcycle setup
+# And gitcycle runs
+# Then output includes "Configuration saved."
+# And gitcycle.yml should be valid
Scenario: Gitcycle command on non-repo
When I cd to a non-repo
View
2 features/steps/gitcycle_steps.rb
@@ -155,7 +155,7 @@ def repos(reload=false)
def run_gitcycle(cmd)
@output = ''
- @gitcycle = Gitcycle.new
+ @gitcycle = Gitcycle.new(nil, :recurse_directories => false)
@gitcycle.stub(:puts) do |str|
str = str.gsub(/\e\[\d{1,2}m/, '')
@output << "#{str}\n"
View
4 features/support/env.rb
@@ -1,2 +1,4 @@
require 'simplecov'
-SimpleCov.start
+SimpleCov.start
+
+# require 'cucumber/rspec/doubles'
View
4 gitcycle.gemspec
@@ -6,7 +6,7 @@ $:.unshift lib unless $:.include?(lib)
Gem::Specification.new do |s|
s.name = "gitcycle"
- s.version = '0.2.31'
+ s.version = '0.3.0'
s.platform = Gem::Platform::RUBY
s.authors = [ 'Winton Welsh' ]
s.email = [ 'mail@wintoni.us' ]
@@ -28,4 +28,6 @@ Gem::Specification.new do |s|
s.add_dependency "launchy", "= 2.0.5"
s.add_dependency "yajl-ruby", "= 1.1.0"
+ s.add_dependency "httpclient", "= 2.1.5"
+ s.add_dependency "httpi", "= 0.9.6"
end
View
126 lib/gitcycle.rb
@@ -1,9 +1,10 @@
require 'rubygems'
require 'fileutils'
-require 'open-uri'
require 'uri'
require 'yaml'
+require 'httpclient'
+require 'httpi'
gem 'launchy', '= 2.0.5'
require 'launchy'
@@ -19,13 +20,14 @@ class Gitcycle
API =
if ENV['ENV'] == 'development'
- "http://127.0.0.1:8080/api"
+ "http://127.0.0.1:3000/api"
else
"http://gitcycle.bleacherreport.com/api"
end
- def initialize(args=nil)
+ def initialize(args=nil, options={})
$remotes = {}
+ @options = options
if ENV['CONFIG']
@config_path = File.expand_path(ENV['CONFIG'])
@@ -90,23 +92,23 @@ def branch(*args)
:branch => branch['source'],
:target => name
)
+
+ puts "Sending branch information to gitcycle.".green
+ get('branch',
+ 'branch[home]' => branch['home'],
+ 'branch[name]' => branch['name'],
+ 'branch[rename]' => name != branch['name'] ? name : nil,
+ 'branch[source]' => branch['source']
+ )
rescue SystemExit, Interrupt
puts "\nDeleting branch from gitcycle.\n".green
- branch = get('branch',
+ get('branch',
'branch[name]' => branch['name'],
'create' => 0,
'reset' => 1
)
end
- puts "Sending branch information to gitcycle.".green
- get('branch',
- 'branch[home]' => branch['home'],
- 'branch[name]' => branch['name'],
- 'branch[rename]' => name != branch['name'] ? name : nil,
- 'branch[source]' => branch['source']
- )
-
puts "\n"
end
@@ -126,6 +128,24 @@ def checkout(*args)
puts "\nBranch not found!\n".red
puts "\nDid you mean: gitc branch #{args[0]}\n".yellow
end
+ elsif args[0] =~ /^\d*$/
+ puts "\nLooking for a branch for LH ticket ##{args[0]}.\n".green
+ results = branches(:array => true).select {|b| b.include?("-#{args[0]}-") }
+ if results.size == 0
+ puts "\nNo matches for ticket ##{args[0]} found.\n".red
+ elsif results.size == 1
+ branch = results.first
+ if branch.strip == branches(:current => true).strip
+ puts "Already on Github branch for LH ticket ##{args[0]} (#{branch})".yellow
+ else
+ puts "\nSwitching to branch '#{branch}'\n".green
+ run("git checkout #{branch}")
+ end
+ else
+ puts "\nFound #{results.size} matches with that LH ticket number:\n".yellow
+ puts results
+ puts "\nDid not switch branches. Please check your ticket number.\n".red
+ end
else
remote, branch = args[0].split('/')
remote, branch = nil, remote if branch.nil?
@@ -252,6 +272,19 @@ def discuss(*issues)
end
end
+ def load_config
+ load_git
+
+ if File.exists?(@config_path)
+ @config = YAML.load(File.read(@config_path))
+
+ @login = @config['repos']["#{@git_login}/#{@git_repo}"] rescue nil
+ @token = @config['auth'][@login] rescue nil
+ else
+ @config = {}
+ end
+ end
+
def pull(*args)
exec_git(:pull, args) if args.length > 0
@@ -507,10 +540,38 @@ def review(pass_fail, *issues)
end
end
+ def open(*issues)
+ require_git && require_config
+
+ if issues.empty?
+ branch = create_pull_request
+
+ if branch == false
+ puts "Branch not found.\n".red
+ elsif branch['issue_url']
+ puts "\nOpening the pull request in GitHub\n".green
+
+ puts "Opening issue: #{branch['issue_url']}\n".green
+ Launchy.open(branch['issue_url'])
+ else
+ puts "You must push code before opening a pull request.\n".red
+ end
+ else
+ puts "\nRetrieving branch information from gitcycle.\n".green
+
+ get('branch', 'issues' => issues, 'scope' => 'repo').each do |branch|
+ if branch['issue_url']
+ puts "Opening issue: #{branch['issue_url']}\n".green
+ Launchy.open(branch['issue_url'])
+ end
+ end
+ end
+ end
+
def setup(login, token)
@config['auth'] ||= {}
@config['auth'][login] = token
-
+
save_config
end
@@ -559,6 +620,8 @@ def branches(options={})
b.match(/\*\s+(.+)/)[1] rescue nil
elsif options[:match]
b.match(/([\s]+|origin\/)(#{options[:match]})$/)[2] rescue nil
+ elsif options[:array]
+ b.split(/\n/).map{|b| b[2..-1]}
else
b
end
@@ -762,9 +825,12 @@ def get(path, hash={})
:login => @login,
:owner => @git_login,
:repo => @git_repo,
- :token => @token
+ :token => @token,
+ :uid => (0...20).map{ ('a'..'z').to_a[rand(26)] }.join
)
+ puts "\nTransaction ID: #{hash[:uid]}".green
+
params = ''
hash[:session] = 0
hash.each do |k, v|
@@ -778,8 +844,10 @@ def get(path, hash={})
begin
$stdout.puts "#{API}/#{path}.json?#{params}"
- json = open("#{API}/#{path}.json?#{params}").read
- rescue Exception
+ req = HTTPI::Request.new "#{API}/#{path}.json?#{params}"
+ json = HTTPI.get(req).body
+ rescue Exception => error
+ puts error.to_s
puts "\nCould not connect to Gitcycle.".red
puts "\nPlease verify your Internet connection and try again later.\n".yellow
exit
@@ -798,24 +866,24 @@ def get(path, hash={})
end
end
- def load_config
- load_git
-
- if File.exists?(@config_path)
- @config = YAML.load(File.read(@config_path))
-
- @login = @config['repos']["#{@git_login}/#{@git_repo}"] rescue nil
- @token = @config['auth'][@login] rescue nil
- else
- @config = {}
+ def git_config_path(path)
+ config = "#{path}/.git/config"
+ $stdout.puts config
+ if File.exists?(config)
+ return config
+ elsif path == '/'
+ return nil
+ elsif @options[:recurse_directories] != false
+ path = File.expand_path(path + '/..')
+ git_config_path(path)
end
end
def load_git
- path = "#{Dir.pwd}/.git/config"
- if File.exists?(path)
+ path = git_config_path(Dir.pwd)
+ if path && File.exists?(path)
@git_url = File.read(path).match(/\[remote "origin"\][^\[]*url = ([^\n]+)/m)[1] rescue nil
- @git_repo = @git_url.match(/\/(.+)\./)[1] rescue nil
+ @git_repo = @git_url.match(/\/(.+)/)[1].sub(/.git$/,'') rescue nil
@git_login = @git_url.match(/:(.+)\//)[1] rescue nil
end
end

0 comments on commit 3bc4270

Please sign in to comment.
Something went wrong with that request. Please try again.