grade_runner 0.0.7 → 0.0.8

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: a8287f06bead27eb7200e42fd3e95c5b59a3d6b20a2ec243ec0208a3833fa5b2
4
- data.tar.gz: c37414bdcf6726a2c0cc4303d8a03de1b6d96f5d9fb6c8cc114f5d5dd1ddd8b6
3
+ metadata.gz: c031fd9ea407f2ec344b80fd85ddbbce5a298e27e136694c68ae0e3f63ced2c5
4
+ data.tar.gz: 3e144eee25f1ddc7d09bf65f190a58933369a4904eec18d3ea8c3056d4ff8601
5
5
  SHA512:
6
- metadata.gz: 2249bf710cf8ee1dd932784084dd95f9468a0b5bc878a8bc097424c4ecfdfbda7857212941b7ffc4644b3abd889890bec073f3a73ed7e952a91f43043e417108
7
- data.tar.gz: 6ab0d79a82276c71709f6903207d12cddf3130eedc96ea5816efbeeefda54f21a9c7440333a3c5494d84e66da00cde91b30d407e6c74615c007c17141c48e881
6
+ metadata.gz: 7b1063120735c91a8c128b63c4fdc0e6505575fd1130e32dc38b6b98e711f0168fbcbf94c840036e05b6db458219f73a748120181f0b247501815400c1bbe186
7
+ data.tar.gz: 384e3fe3cd6bee52cf009b5d7bac62d01dfeebb53b7f17f89aea33efeb089f8acd988472fbb5f2b34796e0c6b47c033ee50940055dfb68557991975917ff23fa
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
data/grade_runner.gemspec CHANGED
@@ -2,16 +2,16 @@
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.7 ruby lib
5
+ # stub: grade_runner 0.0.8 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "grade_runner".freeze
9
- s.version = "0.0.7"
9
+ s.version = "0.0.8"
10
10
 
11
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
13
  s.authors = ["Raghu Betina".freeze, "Jelani Woods".freeze]
14
- s.date = "2023-04-19"
14
+ s.date = "2023-05-30"
15
15
  s.description = "This gem runs your RSpec test suite and posts the JSON output to grades.firstdraft.com.".freeze
16
16
  s.email = ["raghu@firstdraft.com".freeze, "jelani@firstdraft.com".freeze]
17
17
  s.extra_rdoc_files = [
data/lib/tasks/grade.rake CHANGED
@@ -14,8 +14,6 @@ namespace :grade do
14
14
  input_token = ARGV[1]
15
15
  file_token = nil
16
16
 
17
- sync_specs_with_source
18
-
19
17
  config_dir_name = find_or_create_config_dif
20
18
  config_file_name = "#{config_dir_name}/.ltici_apitoken.yml"
21
19
  student_config = {}
@@ -70,6 +68,10 @@ namespace :grade do
70
68
  update_config_file(config_file_name, student_config)
71
69
  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."
72
70
  else
71
+ full_reponame = upstream_repo(submission_url, token)
72
+ set_upstream_remote(full_reponame)
73
+ sync_specs_with_source(full_reponame)
74
+
73
75
  path = File.join(project_root, "/tmp/output/#{Time.now.to_i}.json")
74
76
  `bin/rails db:migrate RAILS_ENV=test` if defined?(Rails)
75
77
  `RAILS_ENV=test bundle exec rspec --order default --format JsonOutputFormatter --out #{path}`
@@ -129,10 +131,7 @@ namespace :grade do
129
131
 
130
132
  end
131
133
 
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
-
134
+ def sync_specs_with_source(full_reponame)
136
135
  if Octokit.repository?(full_reponame)
137
136
  repo_contents = Octokit.contents(full_reponame)
138
137
  remote_spec_folder = repo_contents.find { |git_object| git_object[:name] == 'spec' }
@@ -146,7 +145,7 @@ def sync_specs_with_source
146
145
  local_sha = `git ls-tree HEAD #{project_root.join('spec')}`.chomp.split[2]
147
146
 
148
147
  unless remote_sha == local_sha
149
- `git fetch upstream`
148
+ `git fetch upstream -q`
150
149
  # Remove local contents of spec folder
151
150
  `rm -rf spec/*`
152
151
  default_branch = `git remote show upstream | grep 'HEAD branch' | cut -d' ' -f5`.chomp
@@ -158,6 +157,15 @@ def sync_specs_with_source
158
157
  end
159
158
  end
160
159
 
160
+ def set_upstream_remote(repo_slug)
161
+ upstream = `git remote -v | grep -w upstream`.chomp
162
+ if upstream.blank?
163
+ `git remote add upstream https://github.com/#{repo_slug}`
164
+ else
165
+ `git remote set-url upstream https://github.com/#{repo_slug}`
166
+ end
167
+ end
168
+
161
169
  def update_config_file(config_file_name, config)
162
170
  File.write(config_file_name, YAML.dump(config))
163
171
  end
@@ -182,6 +190,20 @@ rescue => e
182
190
  return false
183
191
  end
184
192
 
193
+ def upstream_repo(root_url, token)
194
+ return false unless token.is_a?(String) && token =~ /^[1-9A-Za-z][^OIl]{23}$/
195
+ url = "#{root_url}/submissions/resource?token=#{token}"
196
+ uri = URI.parse(url)
197
+ req = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json')
198
+ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
199
+ http.request(req)
200
+ end
201
+ result = Oj.load(res.body)
202
+ result["repo_slug"]
203
+ rescue => e
204
+ return false
205
+ end
206
+
185
207
  def github_username(primary_email)
186
208
  username = `git config user.name`.chomp
187
209
  search_results = Octokit.search_users("#{primary_email} in:email").fetch(:items)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grade_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raghu Betina
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-05-04 00:00:00.000000000 Z
12
+ date: 2023-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport