Skip to content

Commit

Permalink
green specs and looks like it`s ok on ruby 1.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nofxx committed Mar 19, 2011
1 parent 5b85fe9 commit 7f4450b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 30 deletions.
17 changes: 17 additions & 0 deletions lib/ticgit-ng.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
require 'rubygems'
# requires git >= 1.0.5
require 'git'

# FIXME: Monkeypatch git until fixed upstream
module Git
class Lib
def config_get(name)
do_get = lambda do |name|
command('config', ['--get', name])
end
if @git_dir
Dir.chdir(@git_dir, &do_get)
else
build_list.call
end
end
end
end

require 'ticgit-ng/base'
require 'ticgit-ng/cli'

Expand Down
14 changes: 7 additions & 7 deletions lib/ticgit-ng/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ def ticket_recent(ticket_id = nil)
def ticket_revparse(ticket_id)
if ticket_id
ticket_id = ticket_id.strip

if /^[0-9]*$/ =~ ticket_id
if t = @last_tickets[ticket_id.to_i - 1]
return t
return t
end
else # partial or full sha
regex = /^#{Regexp.escape(ticket_id)}/
Expand Down Expand Up @@ -281,11 +281,11 @@ def sync_tickets(repo='origin', push=true, verbose=true )
puts "Fetching #{repo}" if verbose
@git.fetch(repo)
puts "Syncing tickets with #{repo}" if verbose
remote_branches=@git.branches.remote.map{|b|
b.full.gsub('remotes/', '')[Regexp.new("^#{Regexp.escape(repo)}/.*")]
remote_branches=@git.branches.remote.map{|b|
b.full.gsub('remotes/', '')[Regexp.new("^#{Regexp.escape(repo)}/.*")]
}.compact
remote_branches.include?("#{repo}/ticgit-ng") ? r_ticgit='ticgit-ng' : r_ticgit='ticgit'
in_branch(false) do
in_branch(false) do
repo_g=git.remote(repo)
git.pull(repo_g, repo+'/'+r_ticgit)
git.push(repo_g, "#{which_branch?}:"+r_ticgit ) if push
Expand All @@ -302,7 +302,7 @@ def read_tickets

bs = git.lib.branches_all.map{|b| b.first }

unless (bs.include?(which_branch?) || bs.include?(which_branch?)) &&
unless (bs.include?(which_branch?) || bs.include?(which_branch?)) &&
File.directory?(@tic_working)
init_ticgitng_branch(bs.include?(which_branch?))
end
Expand Down Expand Up @@ -356,7 +356,7 @@ def in_branch(branch_exists = true)
git.lib.change_head_branch(which_branch?)
git.with_index(@tic_index) do
git.with_working(@tic_working) do |wd|
git.lib.checkout(which_branch?) if needs_checkout &&
git.lib.checkout(which_branch?) if needs_checkout &&
branch_exists
yield wd
end
Expand Down
5 changes: 3 additions & 2 deletions lib/ticgit-ng/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def usage(args = nil)
end
end

def get_editor_message(message_file = nil)
message_file = Tempfile.new('ticgitng_message').path if !message_file
def get_editor_message(comments = nil)
message_file = Tempfile.new('ticgitng_message').path
File.open(message_file, 'w') { |f| f.puts comments } if comments

editor = ENV["EDITOR"] || 'vim'
system("#{editor} #{message_file}");
Expand Down
2 changes: 1 addition & 1 deletion lib/ticgit-ng/command/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def execute
elsif file
tic.ticket_comment(File.read(file), tid)
else
return unless message = get_editor_message
return unless message = get_editor_message(tic)
tic.ticket_comment(message.join(''), tid)
end
end
Expand Down
13 changes: 5 additions & 8 deletions lib/ticgit-ng/command/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ def execute
ticket_show(tic.ticket_new(title, options.to_hash))
else
# interactive
message_file = Tempfile.new('ticgit_message').path
File.open(message_file, 'w') do |f|
f.puts "\n# ---"
f.puts "tags:"
f.puts "# first line will be the title of the tic, the rest will be the first comment"
f.puts "# if you would like to add initial tags, put them on the 'tags:' line, comma delim"
end
if message = get_editor_message(message_file)
comment = "\n# ---\ntags:\n"
comment += "# first line will be the title of the tic, the rest will be the first comment\n"
comment += "# if you would like to add initial tags, put them on the 'tags:' line, comma delim"

if message = get_editor_message(comment)
title = message.shift
if title && title.chomp.length > 0
title = title.chomp
Expand Down
10 changes: 8 additions & 2 deletions lib/ticgit-ng/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ class Ticket
attr_accessor :comments, :tags, :attachments # arrays

def initialize(base, options = {})
options[:user_name] ||= base.git.config('user.name')
options[:user_email] ||= base.git.config('user.email')
# FIXME: what/where/who/how changed config to hash?
if (cfg = base.git.config).is_a? Hash
options[:user_name] ||= cfg["user.name"]
options[:user_email] ||= cfg["user.email"]
else
options[:user_name] ||= cfg("user.name")
options[:user_email] ||= cfg("user.email")
end

@base = base
@opts = options || {}
Expand Down
8 changes: 8 additions & 0 deletions spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
tic.state.should_not eql('resolve')
end

describe "Testing a ticket" do
let(:tic) { @ticgitng.ticket_list.first }

it "should get username from git" do
tic.opts.should be_a Hash
end
end

it "should be able to change to whom the ticket is assigned" do
tic = @ticgitng.ticket_list.first
@ticgitng.ticket_assign('pope', tic.ticket_id)
Expand Down
20 changes: 10 additions & 10 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
Please specify at least one action to execute.
Usage: ti COMMAND [FLAGS] [ARGS]
The available ticgit commands are:
recent List recent activities
assign Assings a ticket to someone
attach Attach file to ticket
checkout Checkout a ticket
tag Modify tags of a ticket
comment Comment on a ticket
list List tickets
milestone List and modify milestones
assign Assings a ticket to someone
sync Sync tickets
new Create a new ticket
points Assign points to a ticket
state Change state of a ticket
recent List recent activities
show Show a ticket
new Create a new ticket
attach Attach file to ticket
list List tickets
state Change state of a ticket
tag Modify tags of a ticket
sync Sync tickets
Common options:
-v, --version Show the version number
-h, --help Display this help
Expand Down

0 comments on commit 7f4450b

Please sign in to comment.