grade_runner 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f83e35368d549636de5841a719e1c81f211fedf13572bdd27a819b24b04ebbeb
4
- data.tar.gz: 5f237a123364f57d1cb83ed9c98134391600fa57b020d7e2d05346a8676c4cc8
3
+ metadata.gz: a8287f06bead27eb7200e42fd3e95c5b59a3d6b20a2ec243ec0208a3833fa5b2
4
+ data.tar.gz: c37414bdcf6726a2c0cc4303d8a03de1b6d96f5d9fb6c8cc114f5d5dd1ddd8b6
5
5
  SHA512:
6
- metadata.gz: 343919cd54317ce463d9fccbc4a3eca37d0faafe36c31fa294ed911e96aecdec637b6a4e728dde8f7fab3a945a86054bc02717ddc659e56f75bcfcea9661b280
7
- data.tar.gz: 5f13ed69664ba6a817247be6933306aa610267b37f04f1bb259036fc64a4798006b74fad7ec42b250ddc6e9f2242e6a715738034aafddd7d2cab9c797d459c81
6
+ metadata.gz: 2249bf710cf8ee1dd932784084dd95f9468a0b5bc878a8bc097424c4ecfdfbda7857212941b7ffc4644b3abd889890bec073f3a73ed7e952a91f43043e417108
7
+ data.tar.gz: 6ab0d79a82276c71709f6903207d12cddf3130eedc96ea5816efbeeefda54f21a9c7440333a3c5494d84e66da00cde91b30d407e6c74615c007c17141c48e881
data/Gemfile CHANGED
@@ -1,14 +1,17 @@
1
1
  source "https://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
4
+ gem "activesupport", ">= 2.3.5"
5
+ gem "oj", "~> 3.13.12"
6
+ gem "octokit", "~> 5.0"
7
+ gem "faraday-retry", "~> 1.0.3"
8
+ gem "rake", "~> 13"
6
9
  # Add dependencies to develop your gem here.
7
10
  # Include everything needed to run rake, tests, features, etc.
8
11
  group :development do
9
12
  gem "rspec", "~> 3.5.0"
10
13
  gem "rdoc", "~> 3.12"
11
- gem "bundler", "~> 1.0"
14
+ gem "bundler", "~> 2.1.4"
12
15
  gem "juwelier", "~> 2.1.0"
13
16
  gem "simplecov", ">= 0"
14
17
  gem "pry", "~> 0"
data/Gemfile.lock CHANGED
@@ -1,29 +1,60 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- addressable (2.6.0)
5
- public_suffix (>= 2.0.2, < 4.0)
6
- binding_of_caller (0.8.0)
4
+ activesupport (7.0.4.3)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (>= 1.6, < 2)
7
+ minitest (>= 5.1)
8
+ tzinfo (~> 2.0)
9
+ addressable (2.8.4)
10
+ public_suffix (>= 2.0.2, < 6.0)
11
+ binding_of_caller (1.0.0)
7
12
  debug_inspector (>= 0.0.1)
8
- builder (3.2.3)
9
- byebug (11.0.1)
10
- coderay (1.1.2)
11
- debug_inspector (0.0.3)
13
+ builder (3.2.4)
14
+ byebug (11.1.3)
15
+ coderay (1.1.3)
16
+ concurrent-ruby (1.2.2)
17
+ debug_inspector (1.1.0)
12
18
  descendants_tracker (0.0.4)
13
19
  thread_safe (~> 0.3, >= 0.3.1)
14
- diff-lcs (1.3)
15
- docile (1.3.2)
16
- faraday (0.15.4)
17
- multipart-post (>= 1.2, < 3)
18
- git (1.5.0)
19
- github_api (0.18.2)
20
+ diff-lcs (1.5.0)
21
+ docile (1.4.0)
22
+ faraday (1.10.3)
23
+ faraday-em_http (~> 1.0)
24
+ faraday-em_synchrony (~> 1.0)
25
+ faraday-excon (~> 1.1)
26
+ faraday-httpclient (~> 1.0)
27
+ faraday-multipart (~> 1.0)
28
+ faraday-net_http (~> 1.0)
29
+ faraday-net_http_persistent (~> 1.0)
30
+ faraday-patron (~> 1.0)
31
+ faraday-rack (~> 1.0)
32
+ faraday-retry (~> 1.0)
33
+ ruby2_keywords (>= 0.0.4)
34
+ faraday-em_http (1.0.0)
35
+ faraday-em_synchrony (1.0.0)
36
+ faraday-excon (1.1.0)
37
+ faraday-httpclient (1.0.1)
38
+ faraday-multipart (1.0.4)
39
+ multipart-post (~> 2)
40
+ faraday-net_http (1.0.1)
41
+ faraday-net_http_persistent (1.2.0)
42
+ faraday-patron (1.0.0)
43
+ faraday-rack (1.0.0)
44
+ faraday-retry (1.0.3)
45
+ git (1.18.0)
46
+ addressable (~> 2.8)
47
+ rchardet (~> 1.8)
48
+ github_api (0.19.0)
20
49
  addressable (~> 2.4)
21
50
  descendants_tracker (~> 0.0.4)
22
- faraday (~> 0.8)
51
+ faraday (>= 0.8, < 2)
23
52
  hashie (~> 3.5, >= 3.5.2)
24
53
  oauth2 (~> 1.0)
25
54
  hashie (3.6.0)
26
- highline (2.0.2)
55
+ highline (2.1.0)
56
+ i18n (1.12.0)
57
+ concurrent-ruby (~> 1.0)
27
58
  interception (0.5)
28
59
  json (1.8.6)
29
60
  juwelier (2.1.3)
@@ -36,41 +67,49 @@ GEM
36
67
  rake
37
68
  rdoc
38
69
  semver
39
- jwt (2.2.1)
40
- method_source (0.9.2)
41
- mini_portile2 (2.4.0)
42
- multi_json (1.13.1)
70
+ jwt (2.7.0)
71
+ method_source (1.0.0)
72
+ mini_portile2 (2.8.1)
73
+ minitest (5.18.0)
74
+ multi_json (1.15.0)
43
75
  multi_xml (0.6.0)
44
- multipart-post (2.1.1)
45
- nokogiri (1.10.3)
46
- mini_portile2 (~> 2.4.0)
47
- oauth2 (1.4.1)
48
- faraday (>= 0.8, < 0.16.0)
76
+ multipart-post (2.3.0)
77
+ nokogiri (1.14.3)
78
+ mini_portile2 (~> 2.8.0)
79
+ racc (~> 1.4)
80
+ oauth2 (1.4.11)
81
+ faraday (>= 0.17.3, < 3.0)
49
82
  jwt (>= 1.0, < 3.0)
50
83
  multi_json (~> 1.3)
51
84
  multi_xml (~> 0.5)
52
- rack (>= 1.2, < 3)
53
- pry (0.12.2)
54
- coderay (~> 1.1.0)
55
- method_source (~> 0.9.0)
56
- pry-byebug (3.7.0)
85
+ rack (>= 1.2, < 4)
86
+ octokit (5.6.1)
87
+ faraday (>= 1, < 3)
88
+ sawyer (~> 0.9)
89
+ oj (3.13.23)
90
+ pry (0.14.1)
91
+ coderay (~> 1.1)
92
+ method_source (~> 1.0)
93
+ pry-byebug (3.10.1)
57
94
  byebug (~> 11.0)
58
- pry (~> 0.10)
95
+ pry (>= 0.13, < 0.15)
59
96
  pry-doc (0.13.5)
60
97
  pry (~> 0.11)
61
98
  yard (~> 0.9.11)
62
99
  pry-remote (0.1.8)
63
100
  pry (~> 0.9)
64
101
  slop (~> 3.0)
65
- pry-rescue (1.5.0)
102
+ pry-rescue (1.5.2)
66
103
  interception (>= 0.5)
67
104
  pry (>= 0.12.0)
68
- pry-stack_explorer (0.4.9.3)
69
- binding_of_caller (>= 0.7)
70
- pry (>= 0.9.11)
71
- public_suffix (3.1.0)
72
- rack (2.0.7)
73
- rake (12.3.2)
105
+ pry-stack_explorer (0.6.1)
106
+ binding_of_caller (~> 1.0)
107
+ pry (~> 0.13)
108
+ public_suffix (5.0.1)
109
+ racc (1.6.2)
110
+ rack (3.0.7)
111
+ rake (13.0.6)
112
+ rchardet (1.8.0)
74
113
  rdoc (3.12.2)
75
114
  json (~> 1.4)
76
115
  rspec (3.5.0)
@@ -86,31 +125,45 @@ GEM
86
125
  diff-lcs (>= 1.2.0, < 2.0)
87
126
  rspec-support (~> 3.5.0)
88
127
  rspec-support (3.5.0)
128
+ ruby2_keywords (0.0.5)
129
+ sawyer (0.9.2)
130
+ addressable (>= 2.3.5)
131
+ faraday (>= 0.17.3, < 3)
89
132
  semver (1.0.1)
90
- simplecov (0.16.1)
133
+ simplecov (0.21.2)
91
134
  docile (~> 1.1)
92
- json (>= 1.8, < 3)
93
- simplecov-html (~> 0.10.0)
94
- simplecov-html (0.10.2)
135
+ simplecov-html (~> 0.11)
136
+ simplecov_json_formatter (~> 0.1)
137
+ simplecov-html (0.12.3)
138
+ simplecov_json_formatter (0.1.4)
95
139
  slop (3.6.0)
96
140
  thread_safe (0.3.6)
97
- yard (0.9.19)
141
+ tzinfo (2.0.6)
142
+ concurrent-ruby (~> 1.0)
143
+ webrick (1.7.0)
144
+ yard (0.9.28)
145
+ webrick (~> 1.7.0)
98
146
 
99
147
  PLATFORMS
100
148
  ruby
101
149
 
102
150
  DEPENDENCIES
103
- bundler (~> 1.0)
151
+ activesupport (>= 2.3.5)
152
+ bundler (~> 2.1.4)
153
+ faraday-retry (~> 1.0.3)
104
154
  juwelier (~> 2.1.0)
155
+ octokit (~> 5.0)
156
+ oj (~> 3.13.12)
105
157
  pry (~> 0)
106
158
  pry-byebug (~> 3)
107
159
  pry-doc (~> 0)
108
160
  pry-remote (~> 0)
109
161
  pry-rescue (~> 1)
110
162
  pry-stack_explorer (~> 0)
163
+ rake (~> 13)
111
164
  rdoc (~> 3.12)
112
165
  rspec (~> 3.5.0)
113
166
  simplecov
114
167
 
115
168
  BUNDLED WITH
116
- 1.17.2
169
+ 2.1.4
data/README.markdown CHANGED
@@ -8,7 +8,7 @@ A Ruby client for [firstdraft Grades](https://grades.firstdraft.com)
8
8
  Add this line to your application's Gemfile:
9
9
 
10
10
  ```ruby
11
- gem "grade_runner", git: "https://github.com/firstdraft/web_git"
11
+ gem "grade_runner", github: "firstdraft/grade_runner"
12
12
  ```
13
13
 
14
14
  And then execute:
@@ -16,8 +16,44 @@ And then execute:
16
16
  $ bundle
17
17
  ```
18
18
 
19
+ ## Usage
20
+
21
+ ### Rails
22
+
23
+ After installed, run `rails grade` to run specs.
24
+
25
+ ### Ruby
26
+
27
+ In order to load and run the Rake task, you need to load it.
28
+
29
+ This is usually done by making a runnable file[^1], typically called `bin/rails`, with contents that look like this:
30
+
31
+ ```rb
32
+ #!/usr/bin/env ruby
33
+ require "rubygems"
34
+ require "bundler/setup"
35
+ require "rake"
36
+
37
+ dir = Gem::Specification.find_by_name("grade_runner").gem_dir
38
+
39
+ load "#{dir}/lib/tasks/grade.rake"
40
+ task_name = ARGV[0]
41
+
42
+ Rake::Task[task_name].invoke
43
+ ```
44
+
45
+ Then you can run `bin/rails grade` like before. You can even add this file to the `PATH` so you can run `rails grade` like with Rails apps.
46
+
47
+ ```bash
48
+ echo 'export PATH="$PATH:/path/to/project/bin/rails"' >> ~/.bashrc
49
+ source ~/.bashrc
50
+ ```
51
+
52
+ ---
53
+
54
+ [^1]: If you get file permissions errors when running `bin/rails grade` try updating the permissions with `chmod 755 bin/rails` first.
55
+
19
56
  Copyright
20
57
  ---------
21
58
 
22
- Copyright (c) 2018 Raghu Betina. See
23
- LICENSE.txt for further details.
59
+ Copyright (c) 2018 Raghu Betina. See [LICENSE.txt](LICENSE.txt) for further details.
data/Rakefile CHANGED
@@ -18,8 +18,8 @@ Juwelier::Tasks.new do |gem|
18
18
  gem.license = "MIT"
19
19
  gem.summary = %Q{A Ruby client for [firstdraft Grades](https://grades.firstdraft.com)}
20
20
  gem.description = %Q{This gem runs your RSpec test suite and posts the JSON output to grades.firstdraft.com.}
21
- gem.email = "raghu@firstdraft.com"
22
- gem.authors = ["Raghu Betina"]
21
+ gem.email = ["raghu@firstdraft.com", "jelani@firstdraft.com"]
22
+ gem.authors = ["Raghu Betina", "Jelani Woods"]
23
23
 
24
24
  # dependencies defined in Gemfile
25
25
  end
@@ -40,7 +40,7 @@ task :default => :spec
40
40
 
41
41
  require 'rdoc/task'
42
42
  Rake::RDocTask.new do |rdoc|
43
- version = File.file?('VERSION') ? File.read('VERSION') : ""
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
44
 
45
45
  rdoc.rdoc_dir = 'rdoc'
46
46
  rdoc.title = "grade_runner #{version}"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.7
data/grade_runner.gemspec CHANGED
@@ -2,18 +2,18 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: grade_runner 0.0.3.pre.3 ruby lib
5
+ # stub: grade_runner 0.0.7 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "grade_runner".freeze
9
- s.version = "0.0.3.pre.3"
9
+ s.version = "0.0.7"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1".freeze) if s.respond_to? :required_rubygems_version=
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
- s.authors = ["Raghu Betina".freeze]
14
- s.date = "2019-06-26"
13
+ s.authors = ["Raghu Betina".freeze, "Jelani Woods".freeze]
14
+ s.date = "2023-04-19"
15
15
  s.description = "This gem runs your RSpec test suite and posts the JSON output to grades.firstdraft.com.".freeze
16
- s.email = "raghu@firstdraft.com".freeze
16
+ s.email = ["raghu@firstdraft.com".freeze, "jelani@firstdraft.com".freeze]
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE.txt",
19
19
  "README.markdown"
@@ -37,41 +37,39 @@ Gem::Specification.new do |s|
37
37
  ]
38
38
  s.homepage = "http://github.com/firstdraft/grade_runner".freeze
39
39
  s.licenses = ["MIT".freeze]
40
- s.rubygems_version = "2.7.8".freeze
40
+ s.rubygems_version = "3.1.6".freeze
41
41
  s.summary = "A Ruby client for [firstdraft Grades](https://grades.firstdraft.com)".freeze
42
42
 
43
43
  if s.respond_to? :specification_version then
44
44
  s.specification_version = 4
45
+ end
45
46
 
46
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- s.add_development_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
48
- s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
49
- s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
50
- s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
51
- s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
52
- s.add_development_dependency(%q<pry>.freeze, ["~> 0"])
53
- s.add_development_dependency(%q<pry-byebug>.freeze, ["~> 3"])
54
- s.add_development_dependency(%q<pry-doc>.freeze, ["~> 0"])
55
- s.add_development_dependency(%q<pry-remote>.freeze, ["~> 0"])
56
- s.add_development_dependency(%q<pry-rescue>.freeze, ["~> 1"])
57
- s.add_development_dependency(%q<pry-stack_explorer>.freeze, ["~> 0"])
58
- else
59
- s.add_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
60
- s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
61
- s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
62
- s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
63
- s.add_dependency(%q<simplecov>.freeze, [">= 0"])
64
- s.add_dependency(%q<pry>.freeze, ["~> 0"])
65
- s.add_dependency(%q<pry-byebug>.freeze, ["~> 3"])
66
- s.add_dependency(%q<pry-doc>.freeze, ["~> 0"])
67
- s.add_dependency(%q<pry-remote>.freeze, ["~> 0"])
68
- s.add_dependency(%q<pry-rescue>.freeze, ["~> 1"])
69
- s.add_dependency(%q<pry-stack_explorer>.freeze, ["~> 0"])
70
- end
47
+ if s.respond_to? :add_runtime_dependency then
48
+ s.add_runtime_dependency(%q<activesupport>.freeze, [">= 2.3.5"])
49
+ s.add_runtime_dependency(%q<oj>.freeze, ["~> 3.13.12"])
50
+ s.add_runtime_dependency(%q<octokit>.freeze, ["~> 5.0"])
51
+ s.add_runtime_dependency(%q<faraday-retry>.freeze, ["~> 1.0.3"])
52
+ s.add_runtime_dependency(%q<rake>.freeze, ["~> 13"])
53
+ s.add_development_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
54
+ s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
55
+ s.add_development_dependency(%q<bundler>.freeze, ["~> 2.1.4"])
56
+ s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
57
+ s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
58
+ s.add_development_dependency(%q<pry>.freeze, ["~> 0"])
59
+ s.add_development_dependency(%q<pry-byebug>.freeze, ["~> 3"])
60
+ s.add_development_dependency(%q<pry-doc>.freeze, ["~> 0"])
61
+ s.add_development_dependency(%q<pry-remote>.freeze, ["~> 0"])
62
+ s.add_development_dependency(%q<pry-rescue>.freeze, ["~> 1"])
63
+ s.add_development_dependency(%q<pry-stack_explorer>.freeze, ["~> 0"])
71
64
  else
65
+ s.add_dependency(%q<activesupport>.freeze, [">= 2.3.5"])
66
+ s.add_dependency(%q<oj>.freeze, ["~> 3.13.12"])
67
+ s.add_dependency(%q<octokit>.freeze, ["~> 5.0"])
68
+ s.add_dependency(%q<faraday-retry>.freeze, ["~> 1.0.3"])
69
+ s.add_dependency(%q<rake>.freeze, ["~> 13"])
72
70
  s.add_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
73
71
  s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
74
- s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
72
+ s.add_dependency(%q<bundler>.freeze, ["~> 2.1.4"])
75
73
  s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
76
74
  s.add_dependency(%q<simplecov>.freeze, [">= 0"])
77
75
  s.add_dependency(%q<pry>.freeze, ["~> 0"])
@@ -1,11 +1,11 @@
1
- # require 'rails'
1
+ require 'rails'
2
2
 
3
3
  module GradeRunner
4
- # class Railtie < ::Rails::Railtie
4
+ class Railtie < ::Rails::Railtie
5
5
 
6
- # rake_tasks do
7
- # load "tasks/grade_runner.rake"
8
- # load "tasks/grade.rake"
9
- # end
10
- # end
6
+ rake_tasks do
7
+ load "tasks/grade_runner.rake"
8
+ load "tasks/grade.rake"
9
+ end
10
+ end
11
11
  end
@@ -1,4 +1,6 @@
1
1
  require "net/http"
2
+ require "oj"
3
+
2
4
  module GradeRunner
3
5
  class Runner
4
6
 
@@ -20,14 +22,14 @@ module GradeRunner
20
22
  private
21
23
 
22
24
  def post_to_grades
23
- puts "- Posting to URL: " + "#{@submission_url}"
24
25
  uri = URI.parse(@submission_url)
25
26
  req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
26
27
  req.body = data.to_json
27
28
  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
28
29
  http.request(req)
29
30
  end
30
- results_url = JSON.parse(res.body)["url"]
31
+
32
+ results_url = Oj.load(res.body)["url"]
31
33
  puts "- Done! Results URL: " + "#{results_url}"
32
34
  end
33
35
 
data/lib/grade_runner.rb CHANGED
@@ -1,3 +1,2 @@
1
1
  require "grade_runner/runner"
2
- require "grade_runner/railtie"
3
-
2
+ require "grade_runner/railtie" if defined?(Rails)
data/lib/tasks/grade.rake CHANGED
@@ -1,27 +1,31 @@
1
- require 'yaml'
2
- require 'net/http'
3
- require "json"
4
- require_relative "../grade_runner/runner"
1
+ require "active_support/core_ext/object/blank"
2
+ require "grade_runner/runner"
3
+ require "octokit"
4
+ require "yaml"
5
5
 
6
- # desc "Alias for \"grade:next\"."
7
- # task grade: "grade:all" do
8
- # end
6
+ desc "Alias for \"grade:next\"."
7
+ task grade: "grade:all" do
8
+ end
9
9
 
10
+ namespace :grade do
10
11
  desc "Run all tests and submit a build report."
11
- task :grade do
12
+ task :all do
12
13
  ARGV.each { |a| task a.to_sym do ; end }
13
14
  input_token = ARGV[1]
14
15
  file_token = nil
15
16
 
16
- config_file_name = File.join(project_root, "grades.yml")
17
+ sync_specs_with_source
18
+
19
+ config_dir_name = find_or_create_config_dif
20
+ config_file_name = "#{config_dir_name}/.ltici_apitoken.yml"
17
21
  student_config = {}
18
22
  student_config["submission_url"] = "https://grades.firstdraft.com"
19
23
 
20
- if File.file?(config_file_name)
24
+ if File.exist?(config_file_name)
21
25
  begin
22
26
  config = YAML.load_file(config_file_name)
23
27
  rescue
24
- abort "It looks like there's something wrong with your token in `/grades.yml`. Please delete that file and try `rake grade:all` again, and be sure to provide the access token for THIS project.".red
28
+ abort "It looks like there's something wrong with your token in `#{config_dir_name}/.ltici_apitoken.yml`. Please delete that file and try `rails grade` again, and be sure to provide the access token for THIS project.".red
25
29
  end
26
30
  submission_url = config["submission_url"]
27
31
  file_token = config["personal_access_token"]
@@ -29,16 +33,19 @@ require_relative "../grade_runner/runner"
29
33
  else
30
34
  submission_url = "https://grades.firstdraft.com"
31
35
  end
32
-
33
- if !input_token.nil? && input_token != "" && input_token != " "
36
+ if file_token.nil? && ENV.has_key?("LTICI_GITPOD_APITOKEN")
37
+ input_token = ENV.fetch("LTICI_GITPOD_APITOKEN")
38
+ end
39
+ if input_token.present?
34
40
  token = input_token
35
41
  student_config["personal_access_token"] = input_token
36
42
  update_config_file(config_file_name, student_config)
37
- elsif input_token.nil? && !file_token.nil?
43
+ elsif input_token.nil? && file_token.present?
38
44
  token = file_token
39
45
  elsif input_token.nil? && file_token.nil?
40
46
  puts "Enter your access token for this project"
41
47
  new_personal_access_token = ""
48
+
42
49
  while new_personal_access_token == "" do
43
50
  print "> "
44
51
  new_personal_access_token = $stdin.gets.chomp.strip
@@ -56,50 +63,111 @@ require_relative "../grade_runner/runner"
56
63
  end
57
64
  end
58
65
 
59
- if !token.nil? && token != "" && token != " "
66
+ if token.present?
67
+
60
68
  if is_valid_token?(submission_url, token) == false
61
69
  student_config["personal_access_token"] = nil
62
70
  update_config_file(config_file_name, student_config)
63
- puts "Your access token looked invalid, so we've reset it to be blank. Please re-run rake grade and, when asked, copy-paste your token carefully from the assignment page."
71
+ puts "Your access token looked invalid, so we've reset it to be blank. Please re-run rails grade and, when asked, copy-paste your token carefully from the assignment page."
64
72
  else
65
73
  path = File.join(project_root, "/tmp/output/#{Time.now.to_i}.json")
66
- # `bin/rails db:migrate RAILS_ENV=test`
67
- if Dir.exist?("bin")
68
- `bin/rake db:migrate`
69
- end
70
- # `RAILS_ENV=test bundle exec rspec --order default --format JsonOutputFormatter --out #{path}`
71
- `bundle exec rspec -I spec/support -f JsonOutputFormatter --out #{path}`
72
- rspec_output_json = JSON.parse(File.read(path))
73
- username = ""
74
- reponame = ""
75
- sha = ""
74
+ `bin/rails db:migrate RAILS_ENV=test` if defined?(Rails)
75
+ `RAILS_ENV=test bundle exec rspec --order default --format JsonOutputFormatter --out #{path}`
76
+ rspec_output_json = Oj.load(File.read(path))
77
+ github_email = `git config user.email`.chomp
78
+ username = github_username(github_email)
79
+ reponame = project_root.to_s.split("/").last
80
+ sha = `git rev-parse HEAD`.slice(0..7)
76
81
 
77
82
  GradeRunner::Runner.new(submission_url, token, rspec_output_json, username, reponame, sha, "manual").process
78
83
  end
79
84
  else
80
- puts "We couldn't find your access token, so we couldn't record your grade. Please click on the assignment link again and run the rake grade ... command shown there."
85
+ puts "We couldn't find your access token, so we couldn't record your grade. Please click on the assignment link again and run the rails grade ... command shown there."
86
+ end
87
+ end
88
+
89
+ desc "Run only the next failing test."
90
+ task :next do
91
+ path = File.join(project_root, "examples.txt")
92
+ if File.exist?(path)
93
+ `bin/rails db:migrate RAILS_ENV=test` if defined?(Rails)
94
+ puts `RAILS_ENV=test bundle exec rspec --next-failure --format HintFormatter`
95
+ else
96
+ puts `RAILS_ENV=test bundle exec rspec`
97
+ puts "Please rerun rails grade:next to run the first failing spec"
98
+ end
99
+ end
100
+
101
+ desc "Reset access token saved in YAML file."
102
+ task :reset_token do
103
+ config_dir_name = find_or_create_config_dif
104
+ config_file_name = "#{config_dir_name}/.ltici_apitoken.yml"
105
+ submission_url = "https://grades.firstdraft.com"
106
+
107
+ student_config = {}
108
+ student_config["submission_url"] = submission_url
109
+ puts "Enter your access token for this project"
110
+ new_personal_access_token = ""
111
+
112
+ while new_personal_access_token == "" do
113
+ print "> "
114
+ new_personal_access_token = $stdin.gets.chomp.strip
115
+ token_valid = is_valid_token?(submission_url, new_personal_access_token)
116
+ unless token_valid && !new_personal_access_token.empty?
117
+ puts "Please enter valid token"
118
+ new_personal_access_token = ""
119
+ end
120
+
121
+ unless new_personal_access_token.empty?
122
+ student_config["personal_access_token"] = new_personal_access_token
123
+ update_config_file(config_file_name, student_config)
124
+ token = new_personal_access_token
125
+ end
81
126
  end
127
+ puts "Grade token has been reset successfully."
82
128
  end
83
129
 
84
- # desc "Run only the next failing test."
85
- # task :next do
86
- # path = File.join(__dir__, "examples.txt")
87
- # if File.file?(path)
88
- # # `bin/rails db:migrate RAILS_ENV=test`
89
- # # puts `RAILS_ENV=test bundle exec rspec --next-failure --format HintFormatter`
90
- # puts `bundle exec rspec --next-failure --format HintFormatter`
91
- # else
92
- # # puts `RAILS_ENV=test bundle exec rspec`
93
- # puts `bundle exec rspec`
94
- # puts "Please rerun rake grade:next to run the first failing spec"
95
- # end
96
- # end
130
+ end
97
131
 
132
+ def sync_specs_with_source
133
+ reponame = `basename -s .git \`git config --get remote.origin.url\``.chomp
134
+ full_reponame = "appdev-projects/#{reponame}"
135
+
136
+ if Octokit.repository?(full_reponame)
137
+ repo_contents = Octokit.contents(full_reponame)
138
+ remote_spec_folder = repo_contents.find { |git_object| git_object[:name] == 'spec' }
139
+ if remote_spec_folder.blank?
140
+ abort("The project #{full_reponame} does not have specs.")
141
+ end
142
+ remote_sha = remote_spec_folder[:sha]
143
+ # Discard unstaged changes in spec folder
144
+ `git checkout spec -q`
145
+ `git clean spec -f -q`
146
+ local_sha = `git ls-tree HEAD #{project_root.join('spec')}`.chomp.split[2]
147
+
148
+ unless remote_sha == local_sha
149
+ `git fetch upstream`
150
+ # Remove local contents of spec folder
151
+ `rm -rf spec/*`
152
+ default_branch = `git remote show upstream | grep 'HEAD branch' | cut -d' ' -f5`.chomp
153
+ # Overwrite local contents of spec folder with contents from upstream branch
154
+ `git checkout upstream/#{default_branch} spec/ -q`
155
+ end
156
+ else
157
+ abort("The project #{full_reponame} does not exist.")
158
+ end
159
+ end
98
160
 
99
161
  def update_config_file(config_file_name, config)
100
162
  File.write(config_file_name, YAML.dump(config))
101
163
  end
102
164
 
165
+ def find_or_create_config_dif
166
+ config_dir_name = File.join(project_root, ".vscode")
167
+ Dir.mkdir(config_dir_name) unless Dir.exist?(config_dir_name)
168
+ config_dir_name
169
+ end
170
+
103
171
  def is_valid_token?(root_url, token)
104
172
  return false unless token.is_a?(String) && token =~ /^[1-9A-Za-z][^OIl]{23}$/
105
173
  url = "#{root_url}/submissions/validate_token?token=#{token}"
@@ -108,12 +176,21 @@ def is_valid_token?(root_url, token)
108
176
  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
109
177
  http.request(req)
110
178
  end
111
- result = JSON.parse(res.body)
179
+ result = Oj.load(res.body)
112
180
  result["success"]
113
181
  rescue => e
114
182
  return false
115
183
  end
116
184
 
185
+ def github_username(primary_email)
186
+ username = `git config user.name`.chomp
187
+ search_results = Octokit.search_users("#{primary_email} in:email").fetch(:items)
188
+ if search_results.present?
189
+ username = search_results.first.fetch(:login, username)
190
+ end
191
+ username
192
+ end
193
+
117
194
  def project_root
118
195
  if defined?(Rails)
119
196
  return Rails.root
@@ -122,6 +199,5 @@ def project_root
122
199
  if defined?(Bundler)
123
200
  return Bundler.root
124
201
  end
125
- p "project root" #REMOVE
126
202
  Dir.pwd
127
- end
203
+ end
@@ -1,16 +1,14 @@
1
- require 'yaml'
2
-
3
1
  namespace :grade_runner do
4
2
  desc "Grade project"
5
3
  task :runner do
6
4
  default_submission_url = "https://grades.firstdraft.com"
7
5
  config = {}
8
- path = File.join(__dir__,"grades.yml")
9
- if File.file?(path)
6
+ path = Rails.root.join("grades.yml")
7
+ if File.exist?(path)
10
8
  begin
11
9
  config = YAML.load_file(path)
12
10
  rescue
13
- abort "It looks like there's something wrong with your token in `/grades.yml`. Please delete that file and try `rake grade:all` again, and be sure to provide the access token for THIS project.".red
11
+ abort "It looks like there's something wrong with your token in `/grades.yml`. Please delete that file and try `rails grade:all` again, and be sure to provide the access token for THIS project.".red
14
12
  end
15
13
  end
16
14
  rspec_output_json = JSON.parse(File.read("#{ENV['CIRCLE_ARTIFACTS']}/output/rspec_output.json"))
@@ -18,15 +16,10 @@ namespace :grade_runner do
18
16
  reponame = ENV["CIRCLE_PROJECT_REPONAME"]
19
17
  sha = ENV["CIRCLE_SHA1"]
20
18
  token = ENV['GRADES_PERSONAL_ACCESS_TOKEN']
21
- if token != false &&
22
- token != "" &&
23
- token != " " &&
24
- !token.nil? &&
25
- token != [] &&
26
- token != {}
19
+ if token.present?
27
20
  GradeRunner::Runner.new('', config['submission_url'] || default_submission_url, token, rspec_output_json, username, reponame, sha, 'circle_ci').process
28
21
  else
29
- puts "We couldn't find your access token, so we couldn't record your grade. Please click on the assignment link again and run the rake grade ... command shown there."
22
+ puts "We couldn't find your access token, so we couldn't record your grade. Please click on the assignment link again and run the rails grade ... command shown there."
30
23
  end
31
24
  end
32
25
  end
metadata CHANGED
@@ -1,15 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grade_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raghu Betina
8
+ - Jelani Woods
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2019-07-08 00:00:00.000000000 Z
12
+ date: 2023-05-04 00:00:00.000000000 Z
12
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 2.3.5
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 2.3.5
28
+ - !ruby/object:Gem::Dependency
29
+ name: oj
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 3.13.12
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 3.13.12
42
+ - !ruby/object:Gem::Dependency
43
+ name: octokit
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '5.0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '5.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: faraday-retry
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.3
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.3
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '13'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '13'
13
84
  - !ruby/object:Gem::Dependency
14
85
  name: rspec
15
86
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +115,14 @@ dependencies:
44
115
  requirements:
45
116
  - - "~>"
46
117
  - !ruby/object:Gem::Version
47
- version: '1.0'
118
+ version: 2.1.4
48
119
  type: :development
49
120
  prerelease: false
50
121
  version_requirements: !ruby/object:Gem::Requirement
51
122
  requirements:
52
123
  - - "~>"
53
124
  - !ruby/object:Gem::Version
54
- version: '1.0'
125
+ version: 2.1.4
55
126
  - !ruby/object:Gem::Dependency
56
127
  name: juwelier
57
128
  requirement: !ruby/object:Gem::Requirement
@@ -165,7 +236,9 @@ dependencies:
165
236
  - !ruby/object:Gem::Version
166
237
  version: '0'
167
238
  description: This gem runs your RSpec test suite and posts the JSON output to grades.firstdraft.com.
168
- email: raghu@firstdraft.com
239
+ email:
240
+ - raghu@firstdraft.com
241
+ - jelani@firstdraft.com
169
242
  executables: []
170
243
  extensions: []
171
244
  extra_rdoc_files:
@@ -206,8 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
279
  - !ruby/object:Gem::Version
207
280
  version: '0'
208
281
  requirements: []
209
- rubyforge_project:
210
- rubygems_version: 2.7.8
282
+ rubygems_version: 3.1.6
211
283
  signing_key:
212
284
  specification_version: 4
213
285
  summary: A Ruby client for [firstdraft Grades](https://grades.firstdraft.com)