git-contest 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +13 -5
  2. data/.travis.yml +1 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +22 -25
  5. data/bin/git-contest +2 -2
  6. data/bin/git-contest-finish +2 -2
  7. data/bin/git-contest-init +2 -2
  8. data/bin/git-contest-rebase +2 -2
  9. data/bin/git-contest-start +2 -2
  10. data/bin/git-contest-submit +34 -17
  11. data/git-contest.gemspec +2 -2
  12. data/lib/contest/driver.rb +3 -0
  13. data/lib/contest/driver/aizu_online_judge.rb +12 -12
  14. data/lib/contest/driver/base.rb +44 -19
  15. data/lib/contest/driver/codeforces.rb +21 -15
  16. data/lib/contest/driver/common.rb +21 -5
  17. data/lib/contest/driver/driver_event.rb +1 -1
  18. data/lib/contest/driver/kattis.rb +168 -0
  19. data/lib/contest/driver/uva_online_judge.rb +14 -11
  20. data/lib/git/contest/version.rb +2 -2
  21. data/spec/bin/t004_git_contest_submit_spec.rb +143 -69
  22. data/spec/lib/contest/driver/t001_aizu_online_judge_spec.rb +46 -29
  23. data/spec/lib/contest/driver/t002_codeforces_spec.rb +185 -20
  24. data/spec/lib/contest/driver/t003_uva_online_judge_spec.rb +157 -10
  25. data/spec/lib/contest/driver/t010_kattis_spec.rb +207 -0
  26. data/spec/mock/default_config/plugins/driver_dummy.rb +31 -11
  27. data/spec/mock/t002/codeforces_after_submit.html +45 -0
  28. data/spec/mock/t002/codeforces_enter.html +67 -0
  29. data/spec/mock/t002/codeforces_submit.html +110 -0
  30. data/spec/mock/t002/codeforces_wait_result.html +58 -0
  31. data/spec/mock/t003/uva_after_quick_submit.html +17 -0
  32. data/spec/mock/t003/uva_home.html +39 -0
  33. data/spec/mock/t003/uva_my_submissions.html +111 -0
  34. data/spec/mock/t003/uva_quick_submit.html +67 -0
  35. data/spec/mock/t010/open_kattis_com_login.html +20 -0
  36. data/spec/mock/t010/open_kattis_com_submit.html +54 -0
  37. data/spec/mock/t010/open_kattis_com_user_submissions.html +28 -0
  38. data/spec/mock/t010/user_submission_111111.html +30 -0
  39. data/spec/mock/t010/user_submission_222222.html +79 -0
  40. data/spec/mock/t010/user_submissions.html +39 -0
  41. metadata +58 -27
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d9380d569b25210d2ba83322e33665663b897a23
4
- data.tar.gz: 29d1b93735dd8e5dc0bd6a3cb69f6dd3595ffe29
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZGQ2NTE5NDhhOWRkNzE0NzFmZjUzNzJkNjJlYWY1OGFiNzhkOThjNw==
5
+ data.tar.gz: !binary |-
6
+ NGM5NDUwYzU4MjY4MDM0Mjg1ZDcxZmEzZWIyNzE1ZmUxZmFjNWFjYg==
5
7
  SHA512:
6
- metadata.gz: a0be028034d747a1d3702c80e48ca7b9ca91fec51b8b13d4bb452655d6a5b356993cda8eb383435e5e23061382f04cfb85486dbcb8575959600c2b7187b5bdb8
7
- data.tar.gz: 01b766f664b1f742938d5ac1aeb7f278cba8e2a7b3e530a9a224fbeefa7236c06e60e1c0d9dd68e1daa921cb61899a97e2f998310b59ae5dfa51a4a3598a2898
8
+ metadata.gz: !binary |-
9
+ NTBjYTRhYjdmMmQ1MDJiNzNjYmQwNTdjZThmYTczNmQ5Y2JkYTZiMmE3NzY3
10
+ NjBmMmJmNzkxNzFkNDJjM2NmZTBlMTA0Mjg2Mzk0OTBmZWJmMGY3ZTMzYjAw
11
+ ZjQyM2ExYzExNjYwZWMzNDhhMWYyZmMwZTViM2M5Y2QyMGY5MzU=
12
+ data.tar.gz: !binary |-
13
+ MzhiOTBkOWI2OTQ5Y2Q0YmQ0Y2E1OGY3Mjk0NDU1M2QyYWM1YWE0YjQzMzg0
14
+ ZTI2NGE1NTQ4MjQ4NTkwMjljYTM4NDE1YTg2ZTIyZjQ1MTU1MWViODI4NGY3
15
+ NzI5ZmRkYjFmNTE4ZTUyMjBlMGYzMDY3NmYyZjQwYzA0MzJkOWU=
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.1.0
3
4
  - 2.0.0
4
5
  - 1.9.3
5
6
  - 1.9.2
@@ -1,7 +1,7 @@
1
1
 
2
2
  MIT License
3
3
 
4
- Copyright (c) 2013 Hiroyuki Sano
4
+ Copyright (c) 2013-2014 Hiroyuki Sano
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining
7
7
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -12,6 +12,8 @@ Currently support the following online judges:
12
12
  * [http://judge.u-aizu.ac.jp/onlinejudge/](http://judge.u-aizu.ac.jp/onlinejudge/)
13
13
  * UVa Online Judge
14
14
  * [http://uva.onlinejudge.org/](http://uva.onlinejudge.org/)
15
+ * Kattis
16
+ * [https://open.kattis.com/](https://open.kattis.com/)
15
17
 
16
18
  ## Branching Model
17
19
  ![image](https://googledrive.com/host/0Bz19k_5gA4wVZWJEcW1XS25NRWM/git-contest.png)
@@ -162,6 +164,10 @@ sites:
162
164
  driver: uva_online_judge
163
165
  user: your_uva_id
164
166
  password: your_uva_password
167
+ kattis:
168
+ driver: kattis
169
+ user: your_kattis_id
170
+ password: your_kattis_password
165
171
  ```
166
172
 
167
173
  #### About contest drivers
@@ -184,31 +190,23 @@ to be written here.
184
190
  4. Push to the branch (`git push origin my-new-feature`)
185
191
  5. Create new Pull Request
186
192
 
187
- ## Links
188
- `git-contest` is inspired by [nvie/gitflow](https://github.com/nvie/gitflow).
193
+ ## Contributors
189
194
 
190
- * A successful Git branching model
191
- * [http://nvie.com/posts/a-successful-git-branching-model/](http://nvie.com/posts/a-successful-git-branching-model/)
192
- * nvie/gitflow
193
- * [https://github.com/nvie/gitflow](https://github.com/nvie/gitflow)
194
- * ruby
195
- * [https://www.ruby-lang.org/](https://www.ruby-lang.org/)
196
- * git
197
- * [http://git-scm.com/](http://git-scm.com/)
195
+ * [Oskar Sundström](https://github.com/osund)
196
+ * Added Kattis Driver
198
197
 
199
198
  ## Author Information
199
+
200
200
  * [Hiroyuki Sano](http://yomogimochi.com/)
201
201
  * [GitHub - sh19910711](https://github.com/sh19910711)
202
202
  * [Google+](https://plus.google.com/+HiroyukiSano)
203
- * [Twitter - @sh19910711](https://twitter.com/sh19910711)
204
-
205
203
 
206
204
  ## License Information
207
205
  **git-contest** is licensed under the MIT-License, see details followings:
208
206
 
209
207
  The MIT License (MIT)
210
208
 
211
- Copyright (c) 2013 **Hiroyuki Sano** \<sh19910711 at gmail.com\>
209
+ Copyright (c) 2013-2014 **Hiroyuki Sano** \<sh19910711 at gmail.com\>
212
210
 
213
211
  Permission is hereby granted, free of charge, to any person obtaining a copy
214
212
  of this software and associated documentation files (the "Software"), to deal
@@ -228,16 +226,15 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
228
226
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
229
227
  THE SOFTWARE.
230
228
 
231
- ## Index
232
- * [Branching Model](#branching-model)
233
- * [Commit Message Examples](#commit-message-examples)
234
- * [Installation](#installation)
235
- * [Requirements](#requirements)
236
- * [Command Usage](#command-usage)
237
- * [More Documentation](#more-documentation)
238
- * [Configuration](#configuration)
239
- * [Contributing](#contributing)
240
- * [Links](#links)
241
- * [Author Information](#author-information)
242
- * [License Information](#license-information)
229
+ ## Links
230
+ `git-contest` is inspired by [nvie/gitflow](https://github.com/nvie/gitflow).
231
+
232
+ * A successful Git branching model
233
+ * [http://nvie.com/posts/a-successful-git-branching-model/](http://nvie.com/posts/a-successful-git-branching-model/)
234
+ * nvie/gitflow
235
+ * [https://github.com/nvie/gitflow](https://github.com/nvie/gitflow)
236
+ * ruby
237
+ * [https://www.ruby-lang.org/](https://www.ruby-lang.org/)
238
+ * git
239
+ * [http://git-scm.com/](http://git-scm.com/)
243
240
 
@@ -4,7 +4,7 @@
4
4
  # git-contest
5
5
  # https://github.com/sh19910711/git-contest
6
6
  #
7
- # Copyright (c) 2013 Hiroyuki Sano <sh19910711 at gmail.com>
7
+ # Copyright (c) 2013-2014 Hiroyuki Sano <sh19910711 at gmail.com>
8
8
  # Licensed under the MIT-License.
9
9
  #
10
10
 
@@ -28,7 +28,7 @@ init
28
28
 
29
29
  sub_commands = %w(init start finish submit rebase)
30
30
  global_opts = Trollop::options do
31
- version "git-contest #{Git::Contest::VERSION} (c) 2013 Hiroyuki Sano"
31
+ version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
32
32
  stop_on sub_commands
33
33
  end
34
34
 
@@ -4,7 +4,7 @@
4
4
  # git-contest-finish
5
5
  # https://github.com/sh19910711/git-contest
6
6
  #
7
- # Copyright (c) 2013 Hiroyuki Sano <sh19910711 at gmail.com>
7
+ # Copyright (c) 2013-2014 Hiroyuki Sano <sh19910711 at gmail.com>
8
8
  # Licensed under the MIT-License.
9
9
  #
10
10
 
@@ -62,7 +62,7 @@ init
62
62
 
63
63
  sub_commands = %w()
64
64
  $options = Trollop::options do
65
- version "git-contest #{Git::Contest::VERSION} (c) 2013 Hiroyuki Sano"
65
+ version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
66
66
  opt(
67
67
  :no_edit,
68
68
  "Use default commit message.",
@@ -4,7 +4,7 @@
4
4
  # git-contest-init
5
5
  # https://github.com/sh19910711/git-contest
6
6
  #
7
- # Copyright (c) 2013 Hiroyuki Sano <sh19910711 at gmail.com>
7
+ # Copyright (c) 2013-2014 Hiroyuki Sano <sh19910711 at gmail.com>
8
8
  # Licensed under the MIT-License.
9
9
  #
10
10
 
@@ -17,7 +17,7 @@ init
17
17
 
18
18
  sub_commands = %w()
19
19
  options = Trollop::options do
20
- version "git-contest #{Git::Contest::VERSION} (c) 2013 Hiroyuki Sano"
20
+ version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
21
21
  opt(
22
22
  :defaults,
23
23
  "Use default branch naming conventions.",
@@ -4,7 +4,7 @@
4
4
  # git-contest-rebase
5
5
  # https://github.com/sh19910711/git-contest
6
6
  #
7
- # Copyright (c) 2013 Hiroyuki Sano <sh19910711 at gmail.com>
7
+ # Copyright (c) 2013-2014 Hiroyuki Sano <sh19910711 at gmail.com>
8
8
  # Licensed under the MIT-License.
9
9
  #
10
10
 
@@ -48,7 +48,7 @@ init
48
48
 
49
49
  sub_commands = %w()
50
50
  $options = Trollop::options do
51
- version "git-contest #{Git::Contest::VERSION} (c) 2013 Hiroyuki Sano"
51
+ version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
52
52
  opt(
53
53
  :interactive,
54
54
  "Do an interactive rebase.",
@@ -4,7 +4,7 @@
4
4
  # git-contest-start
5
5
  # https://github.com/sh19910711/git-contest
6
6
  #
7
- # Copyright (c) 2013 Hiroyuki Sano <sh19910711 at gmail.com>
7
+ # Copyright (c) 2013-2014 Hiroyuki Sano <sh19910711 at gmail.com>
8
8
  # Licensed under the MIT-License.
9
9
  #
10
10
 
@@ -16,7 +16,7 @@ init
16
16
 
17
17
  sub_commands = %w()
18
18
  options = Trollop::options do
19
- version "git-contest #{Git::Contest::VERSION} (c) 2013 Hiroyuki Sano"
19
+ version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
20
20
  opt(
21
21
  :fetch,
22
22
  "fetch from origin before performing operation.",
@@ -4,7 +4,7 @@
4
4
  # git-contest-submit
5
5
  # https://github.com/sh19910711/git-contest
6
6
  #
7
- # Copyright (c) 2013 Hiroyuki Sano <sh19910711 at gmail.com>
7
+ # Copyright (c) 2013-2014 Hiroyuki Sano <sh19910711 at gmail.com>
8
8
  # Licensed under the MIT-License.
9
9
  #
10
10
 
@@ -12,14 +12,6 @@ $:.unshift File.expand_path('../../lib', __FILE__)
12
12
  require 'git/contest/common'
13
13
  require 'trollop'
14
14
 
15
- init
16
-
17
- $config = get_config() || {}
18
- $sites = {}
19
- if $config.has_key? 'sites'
20
- $sites = $config["sites"]
21
- end
22
-
23
15
  #
24
16
  # Load Plugins
25
17
  #
@@ -30,8 +22,6 @@ def load_plugins
30
22
  end
31
23
  end
32
24
 
33
- load_plugins
34
-
35
25
  #
36
26
  # Load Drivers
37
27
  #
@@ -45,9 +35,6 @@ def load_drivers
45
35
  end
46
36
  end
47
37
 
48
- $drivers = {}
49
- load_drivers
50
-
51
38
  #
52
39
  # Command Utils
53
40
  #
@@ -80,10 +67,23 @@ def get_git_add_target rule
80
67
  str
81
68
  end
82
69
 
70
+ init
71
+
72
+ $config = get_config() || {}
73
+ $sites = {}
74
+ if $config.has_key? 'sites'
75
+ $sites = $config["sites"]
76
+ end
77
+
78
+ load_plugins
79
+
80
+ $drivers = {}
81
+ load_drivers
82
+
83
83
  # check options
84
84
  sub_commands = $sites.keys
85
85
  global_opts = Trollop::options do
86
- version "git-contest #{Git::Contest::VERSION} (c) 2013 Hiroyuki Sano"
86
+ version "git-contest #{Git::Contest::VERSION} (c) 2013-2014 Hiroyuki Sano"
87
87
  banner get_banner
88
88
  stop_on sub_commands
89
89
  end
@@ -122,18 +122,21 @@ driver.on(
122
122
  puts "@start: submit"
123
123
  end
124
124
  )
125
+
125
126
  driver.on(
126
127
  'before_login',
127
128
  Proc.new do
128
129
  puts "@submit: logging in..."
129
130
  end
130
131
  )
132
+
131
133
  driver.on(
132
134
  'after_login',
133
135
  Proc.new do
134
136
  puts "@submit: login ok"
135
137
  end
136
138
  )
139
+
137
140
  driver.on(
138
141
  'before_submit',
139
142
  Proc.new do |submit_info|
@@ -141,24 +144,28 @@ driver.on(
141
144
  puts "@submit: doing..."
142
145
  end
143
146
  )
147
+
144
148
  driver.on(
145
149
  'after_submit',
146
150
  Proc.new do
147
151
  puts "@submit: done"
148
152
  end
149
153
  )
154
+
150
155
  driver.on(
151
156
  'before_wait',
152
157
  Proc.new do
153
158
  print "@result: waiting..."
154
159
  end
155
160
  )
161
+
156
162
  driver.on(
157
163
  'retry',
158
164
  Proc.new do
159
165
  print "."
160
166
  end
161
167
  )
168
+
162
169
  driver.on(
163
170
  'after_wait',
164
171
  Proc.new do |submission_info|
@@ -169,12 +176,14 @@ driver.on(
169
176
  puts " %s: %s" % ["submission id", "#{submission_info[:submission_id]}"]
170
177
  puts " %s: %s" % ["status", "#{submission_info[:status]}"]
171
178
  puts ""
179
+ p submission_info
172
180
  if git_contest_is_initialized
173
181
  git_do "add #{get_git_add_target($config["submit_rules"]["add"] || ".")}"
174
182
  git_do "commit --allow-empty -m '#{submission_info[:result]}'"
175
183
  end
176
184
  end
177
185
  )
186
+
178
187
  driver.on(
179
188
  'finish',
180
189
  Proc.new do
@@ -182,7 +191,15 @@ driver.on(
182
191
  end
183
192
  )
184
193
 
185
- opts = driver.get_opts()
186
- result = driver.submit $sites[site], "main.*", opts
194
+ # global config
195
+ $config["submit_rules"] ||= {}
196
+
197
+ # set config
198
+ driver.config = $sites[site]
199
+ driver.config.merge! $config
200
+
201
+ # parse driver options
202
+ driver.options = driver.get_opts()
187
203
 
204
+ result = driver.submit()
188
205
 
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.version = Git::Contest::VERSION
11
11
  spec.authors = ["Hiroyuki Sano"]
12
12
  spec.email = ["sh19910711@gmail.com"]
13
- spec.description = %q{the Git Extension for online judge (Codeforces, etc...)}
14
- spec.summary = %q{the Git Extension for online judge (Codeforces, etc...)}
13
+ spec.description = %q{The Git Extension for online judges (Codeforces, etc...)}
14
+ spec.summary = %q{The Git Extension for online judges (Codeforces, etc...)}
15
15
  spec.homepage = "https://github.com/sh19910711/git-contest"
16
16
  spec.license = "MIT"
17
17
 
@@ -13,3 +13,6 @@ require 'contest/driver/codeforces'
13
13
 
14
14
  # http://uva.onlinejudge.org/
15
15
  require 'contest/driver/uva_online_judge'
16
+
17
+ # https://open.kattis.com/
18
+ require 'contest/driver/kattis'
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # aizu_online_judge.rb
3
3
  #
4
- # Copyright (c) 2013 Hiroyuki Sano <sh19910711 at gmail.com>
4
+ # Copyright (c) 2013-2014 Hiroyuki Sano <sh19910711 at gmail.com>
5
5
  # Licensed under the MIT-License.
6
6
  #
7
7
 
@@ -57,29 +57,29 @@ module Contest
57
57
  when "javascript"
58
58
  return "JavaScript"
59
59
  else
60
- abort "unknown languag"
60
+ abort "unknown language"
61
61
  end
62
62
  end
63
63
 
64
- def submit_ext(config, source_path, options)
64
+ def submit_ext
65
65
  # start
66
66
  trigger 'start'
67
- problem_id = "%04d" % options[:problem_id]
67
+ problem_id = "%04d" % @options[:problem_id]
68
68
 
69
69
  @client = Mechanize.new {|agent|
70
70
  agent.user_agent_alias = 'Windows IE 7'
71
71
  }
72
72
 
73
73
  # submit
74
- trigger 'before_submit', options
74
+ trigger 'before_submit', @options
75
75
  submit_page = @client.get "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0000"
76
76
  submit_page.parser.encoding = "SHIFT_JIS"
77
77
  res_page = submit_page.form_with(:action => '/onlinejudge/servlet/Submit') do |form|
78
- form.userID = config["user"]
79
- form.password = config["password"]
78
+ form.userID = @config["user"]
79
+ form.password = @config["password"]
80
80
  form.problemNO = problem_id
81
- form.language = options[:language]
82
- form.sourceCode = File.read(source_path)
81
+ form.language = @options[:language]
82
+ form.sourceCode = File.read(@options[:source])
83
83
  end.submit
84
84
  trigger 'after_submit'
85
85
 
@@ -89,18 +89,18 @@ module Contest
89
89
  submission_id = get_submission_id status_page.body
90
90
 
91
91
  # wait result
92
- status = get_status_wait config["user"], submission_id
92
+ status = get_status_wait @config["user"], submission_id
93
93
  trigger(
94
94
  'after_wait',
95
95
  {
96
96
  :submission_id => submission_id,
97
97
  :status => status,
98
- :result => get_commit_message($config["submit_rules"]["message"], status, options),
98
+ :result => get_commit_message(status),
99
99
  }
100
100
  )
101
101
  trigger 'finish'
102
102
 
103
- return "AOJ %s: %s\nhttp://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=#{submission_id}" % [problem_id, status]
103
+ get_commit_message(status)
104
104
  end
105
105
 
106
106
  def get_status_wait(user_id, submission_id)