git-contest 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +21 -3
  3. data/README.md +5 -0
  4. data/Rakefile +8 -0
  5. data/appveyor.yml +21 -0
  6. data/bin/git-contest +4 -33
  7. data/bin/git-contest-config +4 -241
  8. data/bin/git-contest-finish +4 -151
  9. data/bin/git-contest-init +4 -65
  10. data/bin/git-contest-list +4 -64
  11. data/bin/git-contest-rebase +4 -64
  12. data/bin/git-contest-start +4 -57
  13. data/bin/git-contest-submit +4 -183
  14. data/git-contest.gemspec +2 -1
  15. data/lib/contest/driver/base.rb +7 -4
  16. data/lib/git/contest/command_line.rb +10 -0
  17. data/lib/git/contest/command_line/command.rb +117 -0
  18. data/lib/git/contest/command_line/main_command.rb +56 -0
  19. data/lib/git/contest/command_line/sub_commands.rb +35 -0
  20. data/lib/git/contest/command_line/sub_commands/config_command.rb +258 -0
  21. data/lib/git/contest/command_line/sub_commands/finish_command.rb +161 -0
  22. data/lib/git/contest/command_line/sub_commands/init_command.rb +79 -0
  23. data/lib/git/contest/command_line/sub_commands/list_command.rb +89 -0
  24. data/lib/git/contest/command_line/sub_commands/rebase_command.rb +87 -0
  25. data/lib/git/contest/command_line/sub_commands/start_command.rb +77 -0
  26. data/lib/git/contest/command_line/sub_commands/submit_command.rb +220 -0
  27. data/lib/git/contest/common.rb +6 -6
  28. data/lib/git/contest/git.rb +160 -156
  29. data/lib/git/contest/version.rb +1 -1
  30. data/spec/command/t004_git_contest_submit_spec.rb +254 -0
  31. data/spec/command/t005_git_contest_branching_spec.rb +90 -0
  32. data/spec/command/t007_git_contest_start_spec.rb +95 -0
  33. data/spec/command/t008_git_contest_finish_spec.rb +171 -0
  34. data/spec/command/t009_git_contest_init_spec.rb +85 -0
  35. data/spec/command/t012_git_contest_list_spec.rb +123 -0
  36. data/spec/command/t013_git_contest_config_spec.rb +186 -0
  37. data/spec/{lib/contest/driver → contest_driver}/t001_aizu_online_judge_spec.rb +1 -1
  38. data/spec/{lib/contest/driver → contest_driver}/t002_codeforces_spec.rb +1 -1
  39. data/spec/{lib/contest/driver → contest_driver}/t003_uva_online_judge_spec.rb +1 -1
  40. data/spec/{lib/contest/driver → contest_driver}/t010_kattis_spec.rb +1 -1
  41. data/spec/{lib/contest/driver → contest_driver}/t011_utils_spec.rb +0 -0
  42. data/spec/spec_helper.rb +18 -12
  43. data/spec/t006_config_spec.rb +37 -31
  44. metadata +57 -33
  45. data/spec/bin/t004_git_contest_submit_spec.rb +0 -223
  46. data/spec/bin/t005_git_contest_branching_spec.rb +0 -70
  47. data/spec/bin/t007_git_contest_start_spec.rb +0 -88
  48. data/spec/bin/t008_git_contest_finish_spec.rb +0 -162
  49. data/spec/bin/t009_git_contest_init_spec.rb +0 -55
  50. data/spec/bin/t012_git_contest_list_spec.rb +0 -99
  51. data/spec/bin/t013_git_contest_config_spec.rb +0 -149
  52. data/spec/spec_list.txt +0 -1
data/bin/git-contest-init CHANGED
@@ -8,70 +8,9 @@
8
8
  # Licensed under the MIT-License.
9
9
  #
10
10
 
11
- $:.unshift File.expand_path('../../lib', __FILE__)
12
- require 'git/contest/common'
13
- require 'trollop'
14
- require 'highline/import'
11
+ require_relative "../lib/git/contest/command_line"
15
12
 
16
- init
17
-
18
- sub_commands = %w()
19
- options = Trollop::options do
20
- version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
21
- opt(
22
- :defaults,
23
- "Use default branch naming conventions.",
24
- :type => :flag,
25
- :default => false,
26
- :required => false,
27
- )
28
- opt(
29
- :force,
30
- "force setting of git-contest branches, even if already configured.",
31
- :short => :f,
32
- :type => :flag,
33
- :default => false,
34
- :required => false,
35
- )
36
- stop_on sub_commands
37
- end
38
-
39
- if git_contest_is_initialized && ! options[:force]
40
- puts "Already initialized for git-contest."
41
- puts "To force reinitialization, use: git contest init -f"
42
- exit 0
43
- end
44
-
45
- # run commands
46
- if ! git_do_no_echo 'rev-parse --git-dir'
47
- git_do 'init'
48
- end
49
-
50
- # init main
51
- if git_contest_has_master_configured
52
- master_branch = git_do 'config --get git.contest.branch.master'
53
- elsif options[:defaults]
54
- master_branch = 'master'
55
- else
56
- master_branch = ask('Master branch name: ') do |q|
57
- q.default = 'master'
58
- end
59
- end
60
-
61
- if options[:defaults]
62
- prefix = 'contest'
63
- else
64
- prefix = ask('Prefix of contest branch name: ') do |q|
65
- q.default = 'contest'
66
- end
67
- end
68
-
69
- if git_repo_is_headless
70
- git_do 'symbolic-ref', 'HEAD', "\"refs/heads/#{master_branch}\""
71
- git_do 'commit --allow-empty --quiet -m "Initial commit"'
72
- end
73
-
74
- # save config
75
- git_do 'config', 'git.contest.branch.master', master_branch
76
- git_do 'config', 'git.contest.branch.prefix', prefix
13
+ cli = CommandLine::SubCommands::InitCommand.new(ARGV)
14
+ cli.init
15
+ cli.run
77
16
 
data/bin/git-contest-list CHANGED
@@ -8,68 +8,8 @@
8
8
  # Licensed under the MIT-License.
9
9
  #
10
10
 
11
- $:.unshift File.expand_path('../../lib', __FILE__)
12
- require 'git/contest/common'
13
- require 'trollop'
14
-
15
- # Show Banner
16
- def usage
17
- puts get_banner
18
- return 0
19
- end
20
-
21
- # Get Banner Text
22
- def get_banner
23
- res = ""
24
- res += "usage: git contest list <type>\n"
25
- res += "\n"
26
- res += "Available types are:\n"
27
- res += " %-8s: show sites\n" % "sites"
28
- res += " %-8s: show drivers\n" % "drivers"
29
- res += " \n"
30
- return res
31
- end
32
-
33
- init
34
- Contest::Driver::Utils.load_plugins
35
-
36
- $config = get_config() || {}
37
- $sites = {}
38
- if $config.has_key? 'sites'
39
- $sites = $config["sites"]
40
- end
41
-
42
- sub_commands = %w(sites drivers)
43
- $options = Trollop::options do
44
- version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
45
- banner get_banner
46
- stop_on sub_commands
47
- end
48
-
49
- type = ARGV.shift.to_s.strip
50
-
51
- case type
52
- when "drivers"
53
- # show all drivers
54
- puts "#"
55
- puts "# Available Drivers"
56
- puts "#"
57
- puts ""
58
- drivers = Contest::Driver::Utils.get_all_drivers
59
- drivers.each {|driver_info|
60
- puts " #{driver_info[:class_name]}"
61
- puts " #{driver_info[:site_info][:desc]}"
62
- puts ""
63
- }
64
- when "sites"
65
- # show all sites
66
- $sites.keys.each do |site_name|
67
- puts "# #{site_name}"
68
- keys = ["driver", "user"]
69
- keys.each {|key| puts " %-8s: %s" % [ key, $sites[site_name][key] ] }
70
- puts " \n"
71
- end
72
- else
73
- usage
74
- end
11
+ require_relative "../lib/git/contest/command_line"
75
12
 
13
+ cli = CommandLine::SubCommands::ListCommand.new(ARGV)
14
+ cli.init
15
+ cli.run
@@ -8,69 +8,9 @@
8
8
  # Licensed under the MIT-License.
9
9
  #
10
10
 
11
- $:.unshift File.expand_path('../../lib', __FILE__)
12
- require 'git/contest/common'
13
- require 'trollop'
11
+ require_relative "../lib/git/contest/command_line"
14
12
 
15
- def use_current_branch
16
- current_branch = git_current_branch
17
- if current_branch.start_with? $PREFIX
18
- $BRANCH = current_branch.strip
19
- $NAME = $BRANCH[$PREFIX.length+1..-1]
20
- else
21
- puts "The current HEAD is no feature branch."
22
- puts "Please spefcify a <name> argument."
23
- abort ''
24
- end
25
- end
26
-
27
- def expand_nameprefix_arg name, prefix
28
- expanded_name = git_contest_resolve_nameprefix name, prefix
29
- exitcode = $?.to_i
30
- if $? == 0
31
- $NAME = expanded_name
32
- $BRANCH = "#{$PREFIX}/#{$NAME}"
33
- else
34
- return 1
35
- end
36
- end
37
-
38
- def expand_nameprefix_arg_or_current
39
- if ARGV.length > 0
40
- expand_nameprefix_arg ARGV[0], $PREFIX
41
- require_branch "#{$PREFIX}/#{$NAME}"
42
- else
43
- use_current_branch
44
- end
45
- end
46
-
47
- init
48
-
49
- sub_commands = %w()
50
- $options = Trollop::options do
51
- version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
52
- opt(
53
- :interactive,
54
- "Do an interactive rebase.",
55
- :type => :flag,
56
- :default => false,
57
- :required => false,
58
- )
59
- stop_on sub_commands
60
- end
61
-
62
- expand_nameprefix_arg_or_current
63
-
64
- puts "Will try to rebase '#{$NAME}'..."
65
-
66
- require_clean_working_tree
67
- require_branch $BRANCH
68
-
69
- git_do "checkout -q \"#{$BRANCH}\""
70
- rebase_options = ""
71
- if $options[:interactive]
72
- rebase_options += " -i"
73
- end
74
-
75
- puts git_do "rebase #{rebase_options} #{$MASTER}"
13
+ cli = CommandLine::SubCommands::RebaseCommand.new(ARGV)
14
+ cli.init
15
+ cli.run
76
16
 
@@ -8,61 +8,8 @@
8
8
  # Licensed under the MIT-License.
9
9
  #
10
10
 
11
- $:.unshift File.expand_path('../../lib', __FILE__)
12
- require 'git/contest/common'
13
- require 'trollop'
14
-
15
- init
16
-
17
- sub_commands = %w()
18
- options = Trollop::options do
19
- version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
20
- opt(
21
- :fetch,
22
- "fetch from origin before performing operation.",
23
- :type => :flag,
24
- :default => false,
25
- :required => false,
26
- )
27
- stop_on sub_commands
28
- end
29
-
30
- if ARGV.length == 0
31
- puts "Missing argument <name>"
32
- exit 1
33
- end
34
-
35
- base_branch_name = $MASTER
36
- # specify based branch
37
- if ARGV.length == 2
38
- base_branch_name = ARGV[1]
39
- end
40
- contest_branch_name = "#{ARGV[0]}"
41
- contest_branch = "#{$PREFIX}/#{contest_branch_name}"
42
- require_branch_absent contest_branch
43
-
44
- # fetch origin/master
45
- if options[:fetch]
46
- git_do "fetch -q \"#{$ORIGIN}\""
47
- end
48
-
49
- # require equal
50
- if git_branch_exists "#{$ORIGIN}/#{$MASTER}"
51
- require_branches_equal "#{$MASTER}", "#{$ORIGIN}/#{$MASTER}"
52
- end
53
-
54
- # create branch
55
- if ! git_do "checkout -b \"#{contest_branch}\" \"#{base_branch_name}\""
56
- abort "Could not create contest branch #{contest_branch}"
57
- end
58
-
59
- puts ""
60
- puts "Summary of actions:"
61
- puts "- A new branch \"#{contest_branch}\" was created, based on \"#{base_branch_name}\""
62
- puts "- You are now on branch \"#{contest_branch}\""
63
- puts ""
64
- puts "Now, start committing on your contest. When done, use:"
65
- puts ""
66
- puts " git contest finish #{contest_branch_name}"
67
- puts ""
11
+ require_relative "../lib/git/contest/command_line"
68
12
 
13
+ cli = CommandLine::SubCommands::StartCommand.new(ARGV)
14
+ cli.init
15
+ cli.run
@@ -8,188 +8,9 @@
8
8
  # Licensed under the MIT-License.
9
9
  #
10
10
 
11
- $:.unshift File.expand_path('../../lib', __FILE__)
12
- require 'git/contest/common'
13
- require 'trollop'
11
+ require_relative "../lib/git/contest/command_line"
14
12
 
15
- #
16
- # Load Drivers
17
- #
18
- def load_drivers
19
- driver_names = $sites.keys().map {|key| $sites[key]["driver"] }
20
- driver_names.uniq.each do |driver_name|
21
- class_name = driver_name.clone
22
- class_name.gsub!(/^[a-z]/) {|c| c.upcase }
23
- class_name.gsub!(/(_)([a-z])/) {|c, b| $2.upcase }
24
- $drivers[driver_name] = Contest::Driver.const_get "#{class_name}Driver"
25
- end
26
- end
27
-
28
- #
29
- # Command Utils
30
- #
31
- def usage
32
- puts get_banner
33
- return 0
34
- end
35
-
36
- def get_banner
37
- res = ""
38
- res += "usage: git contest submit <site>\n"
39
- res += "\n"
40
- res += "Available sites are:\n"
41
- $sites.keys().each do |site|
42
- if $drivers.has_key? $sites[site]["driver"]
43
- driver = $drivers[$sites[site]["driver"]].new
44
- res += " %-12s\t#{driver.get_desc}\n" % [site]
45
- else
46
- # TODO: driver not found
47
- end
48
- end
49
- res += "\n"
50
- res += "Try 'git contest submit <site> --help' for details.\n"
51
- return res
52
- end
53
-
54
- def get_git_add_target rule
55
- str = rule
56
- str = str.gsub('${source}', $submit_info[:source])
57
- str
58
- end
59
-
60
- init
61
-
62
- $config = get_config() || {}
63
- $sites = {}
64
- if $config.has_key? 'sites'
65
- $sites = $config["sites"]
66
- end
67
-
68
- Contest::Driver::Utils.load_plugins
69
-
70
- $drivers = {}
71
- load_drivers
72
-
73
- # check options
74
- sub_commands = $sites.keys
75
- global_opts = Trollop::options do
76
- version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
77
- banner get_banner
78
- stop_on sub_commands
79
- end
80
-
81
- # detect site
82
- site = ARGV.shift.to_s.strip
83
-
84
- unless $sites.has_key?(site)
85
- if site != ""
86
- puts "site not found"
87
- else
88
- usage
89
- end
90
- exit 0
91
- end
92
-
93
- # detect driver
94
- driver_name = $sites[site]["driver"]
95
-
96
- unless $drivers.has_key?(driver_name)
97
- puts "driver not found"
98
- exit
99
- end
100
-
101
- #
102
- # Submit Start
103
- #
104
- driver = $drivers[driver_name].new
105
-
106
- $submit_info = {}
107
-
108
- # set events
109
- driver.on(
110
- 'start',
111
- Proc.new do
112
- puts "@start: submit"
113
- end
114
- )
115
-
116
- driver.on(
117
- 'before_login',
118
- Proc.new do
119
- puts "@submit: logging in..."
120
- end
121
- )
122
-
123
- driver.on(
124
- 'after_login',
125
- Proc.new do
126
- puts "@submit: login ok"
127
- end
128
- )
129
-
130
- driver.on(
131
- 'before_submit',
132
- Proc.new do |submit_info|
133
- $submit_info = submit_info
134
- puts "@submit: doing..."
135
- end
136
- )
137
-
138
- driver.on(
139
- 'after_submit',
140
- Proc.new do
141
- puts "@submit: done"
142
- end
143
- )
144
-
145
- driver.on(
146
- 'before_wait',
147
- Proc.new do
148
- print "@result: waiting..."
149
- end
150
- )
151
-
152
- driver.on(
153
- 'retry',
154
- Proc.new do
155
- print "."
156
- end
157
- )
158
-
159
- driver.on(
160
- 'after_wait',
161
- Proc.new do |submission_info|
162
- puts ""
163
- next unless submission_info.is_a?(Hash)
164
- puts ""
165
- puts "@result: Submission Result"
166
- puts " %s: %s" % ["submission id", "#{submission_info[:submission_id]}"]
167
- puts " %s: %s" % ["status", "#{submission_info[:status]}"]
168
- puts ""
169
- if git_contest_is_initialized
170
- git_do "add #{get_git_add_target($config["submit_rules"]["add"] || ".")}"
171
- git_do "commit --allow-empty -m '#{submission_info[:result]}'"
172
- end
173
- end
174
- )
175
-
176
- driver.on(
177
- 'finish',
178
- Proc.new do
179
- puts "@finish"
180
- end
181
- )
182
-
183
- # global config
184
- $config["submit_rules"] ||= {}
185
- $config["file"] ||= {}
186
-
187
- # set config
188
- driver.config = $sites[site]
189
- driver.config.merge! $config
190
-
191
- # parse driver options
192
- driver.options = driver.get_opts()
193
-
194
- result = driver.submit()
13
+ cli = CommandLine::SubCommands::SubmitCommand.new ARGV
14
+ cli.init
15
+ cli.run
195
16