Class: SSP::App::Pair

Inherits:
Thor
  • Object
show all
Defined in:
lib/ssp/application/pair.rb

Instance Method Summary collapse

Instance Method Details

#install_hookObject

Raises:

  • (Thor::Error)


79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ssp/application/pair.rb', line 79

def install_hook
  chek_dot_git!

  hook_file = ".git/hooks/pre-commit"
  raise Thor::Error, "a pre-commit hook file already exists" if File.exists?(hook_file)

  File.open(hook_file, "w") { |f| f.write "#!/bin/sh\nssp pair:status\n" }
  File.chmod(0755, hook_file)

  say "pre-commit hook is installed in #{hook_file}"
end

#set_author(pair = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ssp/application/pair.rb', line 15

def set_author(pair=nil)
  chek_dot_git!

  me = %x{git config --global user.name}.chomp
  my_email = sspdevs[me]
  devs = sspdevs.map {|name,_| name}.sort
  devs.delete(me)

  if pair.nil?
    say "Pairing?", :bold
    devs.each_with_index do |name, index|
      say_status "#{index + 1}:", name, :cyan
    end
    say_status "g:", "Gumikacsa", :cyan
    print "Enter the index of your pair or leave blank if not pairing: "

    while (choice = File.new("/dev/tty").readline.chomp) !~ /\A\d*|[Gg]\Z/
      say "Bad input `#{choice}'"
    end
  elsif pair =~ /^(|x|me|not)$/i
    choice = ""
  else
    pair = pair.downcase
    if pair == "g"
      choice = "g"
    else
      pair = devs.detect do |dev|
        initial = dev.split(" ").map {|x| x[0..0]}.join.downcase
        initial == pair or dev.downcase.split(" ").include?(pair)
      end
      raise Thor::Error, "No such pair" unless pair
      choice = devs.index(pair) + 1
    end
  end

  commit_name, commit_email = if choice == ''
    [me, my_email]
  else
    pair = choice.downcase == "g" ? "Gumikacsa" : devs[choice.to_i - 1]
    ["#{me} & #{pair}", options[:pair_email].sub('@', initials(me, pair)+'@')]
  end

  say "Setting #{shell.set_color("commit author", :bold)} to #{shell.set_color(commit_name, :green)}"
  %x{git config user.name '#{commit_name}'}
  say "Setting #{shell.set_color("commit email", :bold)} to #{shell.set_color(commit_email, :green)}"
  %x{git config user.email '#{commit_email}'}
end

#statusObject



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ssp/application/pair.rb', line 64

def status
  chek_dot_git!

  commit_name = %x{git config user.name}.chomp
  commit_email = %x{git config user.email}.chomp
  say "Current #{shell.set_color("commit author", :bold)} is #{shell.set_color(commit_name, :yellow, true)}"
  say "Current #{shell.set_color("commit email", :bold)} is #{shell.set_color(commit_email, :yellow, true)}"

  say "Is this ok? [Y/n] "
  unless File.new("/dev/tty").readline.chomp =~ /^(y(es)?)?$/i
    exit 1
  end
end