Skip to content

Commit

Permalink
Retrieving ticket titles successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Nov 28, 2011
1 parent a0eaa25 commit 8280c0f
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
GitCycle Gitcycle
======== ========


Tame your development cycle. Tame your development cycle.
Expand Down
15 changes: 14 additions & 1 deletion bin/gitcycle
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,16 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby


require File.expand_path("../../lib/gitcycle", __FILE__) require File.expand_path("../../lib/gitcycle", __FILE__)

gitcycle = Gitcycle.new
command = ARGV.shift

if command.nil?
puts "\nNo command specified\n".red
elsif gitcycle.respond_to?(command)
gitcycle.send(command, *ARGV)
elsif ARGV.empty?
gitcycle.pull_request(command)
else
puts "\nCommand \"#{command}\" not found\n".red
end
2 changes: 2 additions & 0 deletions gitcycle.gemspec
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ Gem::Specification.new do |s|
s.test_files = `cd #{root} && git ls-files -- {features,test,spec}/*`.split("\n") s.test_files = `cd #{root} && git ls-files -- {features,test,spec}/*`.split("\n")


s.add_development_dependency "rspec", "~> 1.0" s.add_development_dependency "rspec", "~> 1.0"

s.add_dependency "yajl-ruby", "= 1.1.0"
end end
20 changes: 20 additions & 0 deletions lib/ext/string.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,20 @@
class String

# Colors

def blue
"\e[34m#{self}\e[0m"
end

def green
"\e[32m#{self}\e[0m"
end

def red
"\e[31m#{self}\e[0m"
end

def yellow
"\e[33m#{self}\e[0m"
end
end
97 changes: 96 additions & 1 deletion lib/gitcycle.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,99 @@
require 'open-uri'
require 'uri'
require 'yaml'

gem 'yajl-ruby', '= 1.1.0'
require 'yajl'

$:.unshift File.dirname(__FILE__) $:.unshift File.dirname(__FILE__)


module Gitcycle require "ext/string"

class Gitcycle

API =
if ENV['ENV'] == 'development'
"http://127.0.0.1:8080/api"
else
"http://gitcycle.com/api"
end

def initialize
@config_path = File.expand_path("~/.gitcycle.yml")
load_config
load_git
end

def pull_request(url_or_desc)
require_git && require_config
if url_or_desc.strip[0..3] == 'http'
ticket = get('ticket',
:login => @git_login,
:token => @token,
:url => url_or_desc
)
title = ticket['ticket']['title']
else
title = url_or_desc
end
puts title
end

def setup(login, repo, token)
@config[login] ||= {}
@config[login][repo] = token
save_config
end

private

def get(path, hash)
params = ''
hash.each do |k, v|
params << "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}&"
end
params.chop! # trailing &

json = open("#{API}/#{path}.json?#{params}").read
Yajl::Parser.parse(json)
end

def load_config
if File.exists?(@config_path)
@config = YAML.load(File.read(@config_path))
else
@config = {}
end
end

def load_git
path = "#{Dir.pwd}/.git/config"
if File.exists?(path)
@git_url = File.read(path).match(/\[remote "origin"\].*url = ([^\n]+)/m)[1]
@git_repo = @git_url.match(/\/(.+)\./)[1]
@git_login = @git_url.match(/:(.+)\//)[1]
@token = @config[@git_login][@git_repo]
end
end

def require_config
unless @token
puts "\ngitcycle configuration not found.".red
puts "Are you in the right repository?"
puts "Have you set up this repository at http://gitcycle.com?\n\n"
end
end

def require_git
unless @git_url && @git_repo && @git_login
puts "\n.git/config origin entry not found!".red
puts "Are you sure you are in a git repository?\n\n"
end
end

def save_config
File.open(@config_path, 'w') do |f|
f.write(YAML.dump(@config))
end
end
end end

0 comments on commit 8280c0f

Please sign in to comment.