submit_hw 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/submit_hw +192 -12
- metadata +55 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fe0b4d00bf33cad21a46e12a00f1e172fc2596a
|
4
|
+
data.tar.gz: 4d2726dff1336853609eb8f1b7133f438d2436b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d8afe66783582c979410b1855a6003d11b70b11ec7a23457e876f6f3b73898218e74cbe46243c6e0de2a2836fd50f324753401d98103d96371e5bab140fb8ce
|
7
|
+
data.tar.gz: 03fc8a1e7ebb8acf115a1400ff7dc21cc35b9725552c477f1956f2b72b8cdac36063ceb761b02a65ca8509b55b2d9abfaabe16e5ad83a2bbf4e124cd153790b7
|
data/bin/submit_hw
CHANGED
@@ -1,23 +1,203 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'json'
|
3
2
|
|
4
|
-
|
3
|
+
# require dependencies
|
4
|
+
require "octokit"
|
5
|
+
require "colorize"
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
# require standard libraries
|
8
|
+
require "json"
|
9
|
+
require "yaml"
|
10
|
+
require "io/console"
|
11
|
+
|
12
|
+
# require development dependencies (#TODO add a verbose format for debugging)
|
13
|
+
if ARGV[0] == "--debug"
|
14
|
+
puts "(running in debug mode...)".yellow
|
15
|
+
require "pry"
|
16
|
+
def debug(output); puts "[DEBUG] #{output.chomp}".yellow; end
|
17
|
+
else
|
18
|
+
def debug(output); return false; end
|
19
|
+
end
|
20
|
+
if ["-h","--help"].include? ARGV[0]
|
21
|
+
puts "This must be run from the Class Repo; it submits a " + \
|
22
|
+
"Pull Request for homework."
|
23
|
+
puts "If you are having trouble, run in debug mode:"
|
24
|
+
puts "$ submit_hw --debug"
|
25
|
+
exit(true)
|
26
|
+
end
|
27
|
+
ARGV.clear # clean out arguments from $stdin so they don't get `gets`-ed below
|
28
|
+
|
29
|
+
# TODO (phlco) remove Hub dependency and use github gem/api directly...
|
30
|
+
|
31
|
+
# NOTE: Removed in order to clean up the bash profile (this shouldn't touch it)
|
32
|
+
# storing data in the ~/.gitconfig instead
|
33
|
+
#
|
34
|
+
# unless ENV['HUMAN_NAME']
|
35
|
+
# puts "Please enter your full name (first and last)"
|
36
|
+
# human_name = gets.chomp.strip.downcase.gsub(' ', '_')
|
37
|
+
# system("export HUMAN_NAME=#{human_name}")
|
38
|
+
# system("echo '\nexport HUMAN_NAME=#{human_name}\n' >> ~/.bash_profile")
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# def prompt_to_reload
|
42
|
+
# puts "WARNING: this script changed your ~/.bash_profile file." + \
|
43
|
+
# " When possible immediately run the following command:".yellow
|
44
|
+
# puts " $ reload"
|
45
|
+
# puts "or, if that fails:".yellow
|
46
|
+
# puts " $ source ~/.bash_profile"
|
47
|
+
# end
|
48
|
+
|
49
|
+
# Gracefully exit on error.
|
50
|
+
def exit_script
|
51
|
+
puts "\nPlease type 'submit_hw' and restart the submission process.".red
|
8
52
|
exit(false)
|
9
53
|
end
|
10
54
|
|
55
|
+
# Check if their gitconfig has a "human_name" entry, and if not, add it.
|
56
|
+
# The purpose of the human_name is to make their commits more readable for
|
57
|
+
# the IAs.
|
58
|
+
output = `git config --get user.humanname`
|
59
|
+
debug "user.humanname: #{output}"
|
60
|
+
if output.empty?
|
61
|
+
print "Please enter your full, human name: "
|
62
|
+
human_name = gets.chomp
|
63
|
+
output = `git config --add user.humanname '#{human_name}'`
|
64
|
+
debug "new user.humanname: #{output}"
|
65
|
+
end
|
66
|
+
|
67
|
+
# Ensure their gitconfig has a "name" entry with their GH username, and if not,
|
68
|
+
# add it.
|
69
|
+
output = `git config --get user.name`
|
70
|
+
debug "user.name: #{output}"
|
71
|
+
if output.empty?
|
72
|
+
puts "Please enter your Github username (it is case sensitive)."
|
73
|
+
github_username = gets.chomp
|
74
|
+
output = `git config --add user.name '#{github_username}'`
|
75
|
+
debug "new user.name: #{output}"
|
76
|
+
end
|
77
|
+
|
78
|
+
# Check to see if they have a hub config file, which stores an auth token that
|
79
|
+
# allows the hub command to act on their behalf with GitHub. If not, use Octokit
|
80
|
+
# to get an auth token and save it in a new hub config file.
|
81
|
+
unless File.exists? File.expand_path(".config/hub","~")
|
82
|
+
puts "You haven't used the GitHub API with Hub before."
|
83
|
+
puts "We need your credentials (one time)."
|
84
|
+
print "Please enter your GitHub username: "
|
85
|
+
username = gets.chomp
|
86
|
+
print "Please enter your GitHub password: "
|
87
|
+
password = $stdin.noecho(&:gets).chomp
|
88
|
+
debug "uname:pass #{username}:#{password}" || puts # spacin' out bru!
|
89
|
+
|
90
|
+
client = Octokit::Client.new \
|
91
|
+
:login => username,
|
92
|
+
:password => password
|
93
|
+
|
94
|
+
begin
|
95
|
+
client.user # check for bad auth and fail
|
96
|
+
rescue
|
97
|
+
puts "Authentication error. Check your username and password."
|
98
|
+
exit_script
|
99
|
+
end
|
100
|
+
|
101
|
+
# add random number to token name to allow multiple tokens
|
102
|
+
random_number = (Random.rand * 10000).to_i
|
103
|
+
|
104
|
+
response = client.create_authorization \
|
105
|
+
:scopes => ["user","repo"],
|
106
|
+
:note => "hub token added by submit_hw [#{random_number}]"
|
107
|
+
|
108
|
+
hub_config = {
|
109
|
+
"github.com" => [
|
110
|
+
{
|
111
|
+
"oauth_token" => response[:token],
|
112
|
+
"user" => username
|
113
|
+
}
|
114
|
+
]
|
115
|
+
}.to_yaml
|
116
|
+
|
117
|
+
debug "hub yaml: #{hub_config}"
|
118
|
+
|
119
|
+
# ensure ~/.config exists
|
120
|
+
FileUtils.mkdir_p File.expand_path(".config","~")
|
121
|
+
|
122
|
+
File.write(File.expand_path(".config/hub","~"), hub_config)
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
# Get data from students for HW metrics.
|
11
127
|
data = {}
|
12
128
|
|
13
|
-
|
14
|
-
data["completeness"] = gets
|
129
|
+
print "How many parts of the homework did you finish? "
|
130
|
+
data["completeness"] = gets
|
131
|
+
begin
|
132
|
+
data["completeness"] = Integer(data["completeness"])
|
133
|
+
raise ArgumentError if data["completeness"] < 0
|
134
|
+
rescue ArgumentError
|
135
|
+
puts "Invalid: not an integer (0 or greater)".red
|
136
|
+
exit_script
|
137
|
+
end
|
138
|
+
|
139
|
+
# TODO (CentroDL) Confirm what data we want to capture
|
140
|
+
# print "\nDid you finish the all of the required parts of the homework? (y/n)"
|
141
|
+
# data["completeness"] = gets
|
142
|
+
|
143
|
+
# unless ["y","n"].include? data["completeness"].downcase
|
144
|
+
# puts "Must enter 'y' or 'n'".red
|
145
|
+
# exit_script
|
146
|
+
# end
|
15
147
|
|
16
|
-
|
17
|
-
data["comfortability"] = gets.gsub(/\W+/, '')
|
148
|
+
# print "Comfortability [1 - 5]? "
|
149
|
+
# data["comfortability"] = gets.gsub(/\W+/, '').to_i
|
18
150
|
|
19
|
-
|
20
|
-
|
21
|
-
|
151
|
+
# unless (1..5).member?(data["comfortability"])
|
152
|
+
# puts "Invalid numbers (only 1 - 5)".red
|
153
|
+
# exit_script
|
154
|
+
# end
|
22
155
|
|
23
|
-
|
156
|
+
debug "data: #{data}"
|
157
|
+
|
158
|
+
# Get the necessary metadata to submit the push and PR to GitHub.
|
159
|
+
begin
|
160
|
+
upstream = `git config --get remote.upstream.url`
|
161
|
+
upstream = upstream.strip.match(/:(.*)\.git/).captures.first
|
162
|
+
rescue NoMethodError
|
163
|
+
# Upstream has not been set
|
164
|
+
puts ("You haven't configured a remote that points to the " + \
|
165
|
+
"upstream repository!").red
|
166
|
+
puts "\nRun the following then try again:".red
|
167
|
+
puts " $ git remote add upstream CLASS_REPO_SSH_URL"
|
168
|
+
exit_script
|
169
|
+
end
|
170
|
+
|
171
|
+
# Get the necessary data to form a commit message.
|
172
|
+
human_name = `git config --get user.humanname`.chomp
|
173
|
+
github_name = `git config --get user.name`.chomp
|
174
|
+
branch = "#{upstream}:#{github_name}"
|
175
|
+
submitted_at = Time.now.strftime("%H:%m")
|
176
|
+
submitted_on = Time.now.strftime('%Y-%m-%d')
|
177
|
+
message = "HW for #{human_name}: #{submitted_on} at #{submitted_at}" + \
|
178
|
+
"\n\n#{data.to_json}"
|
179
|
+
debug "message: #{message.split("\n").first}"
|
180
|
+
|
181
|
+
# Push to their fork.
|
182
|
+
puts "Pushing your work to your fork...\n"
|
183
|
+
push_msg = `git push origin master 2>&1`
|
184
|
+
debug "push_message: #{push_msg}" #|| puts # spacin' it out bru
|
185
|
+
|
186
|
+
# Submit PR to class repo in their GH named branch
|
187
|
+
puts "Submitting a pull request...\n"
|
188
|
+
submission_msg = `hub pull-request -m '#{message}' -b '#{branch}' 2>&1`
|
189
|
+
debug "pr_message: #{submission_msg}"
|
190
|
+
|
191
|
+
# Check the submission message to ensure there were no errors
|
192
|
+
if submission_msg.include? "pull request already exists"
|
193
|
+
puts ("You already have an outstanding pull request which the instructors" + \
|
194
|
+
"\nhave yet to merge! Have a great day.").yellow
|
195
|
+
elsif submission_msg.include? "pull request: Unprocessable Entity (HTTP 422)"
|
196
|
+
puts ("We may not have an upstream branch for you yet. " + \
|
197
|
+
"Contact your Instructors!").yellow
|
198
|
+
elsif submission_msg.include? "No commits between"
|
199
|
+
# NOTE: (phlco) we'll ignore this for now bc we probably won't get this error.
|
200
|
+
puts "You haven't commited any changes.".red
|
201
|
+
else
|
202
|
+
puts "Thanks for submitting your homework.".green
|
203
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,65 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: submit_hw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeffrey Konowitch
|
8
|
+
- PJ Hughes
|
9
|
+
- Phillip Lamplugh
|
10
|
+
- Travis Vander Hoop
|
11
|
+
- Neel Patel
|
8
12
|
autorequire:
|
9
13
|
bindir: bin
|
10
14
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
15
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: hub
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "~>"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '1.12'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - "~>"
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.12'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: octokit
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - "~>"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - "~>"
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '3.0'
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: colorize
|
47
|
+
requirement: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - "~>"
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 0.7.3
|
52
|
+
type: :runtime
|
53
|
+
prerelease: false
|
54
|
+
version_requirements: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - "~>"
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 0.7.3
|
13
59
|
description: ''
|
14
|
-
email:
|
60
|
+
email:
|
61
|
+
- jeff.konowitch@ga.co
|
62
|
+
- pj@ga.co
|
15
63
|
executables:
|
16
64
|
- submit_hw
|
17
65
|
extensions: []
|
@@ -19,7 +67,7 @@ extra_rdoc_files: []
|
|
19
67
|
files:
|
20
68
|
- "./bin/submit_hw"
|
21
69
|
- bin/submit_hw
|
22
|
-
homepage: https://github.com/
|
70
|
+
homepage: https://github.com/ga-instructors/submit_hw
|
23
71
|
licenses:
|
24
72
|
- MIT
|
25
73
|
metadata: {}
|
@@ -39,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
87
|
version: '0'
|
40
88
|
requirements: []
|
41
89
|
rubyforge_project:
|
42
|
-
rubygems_version: 2.2.
|
90
|
+
rubygems_version: 2.2.2
|
43
91
|
signing_key:
|
44
92
|
specification_version: 4
|
45
|
-
summary:
|
93
|
+
summary: A script to submit homework for GA's WDI.
|
46
94
|
test_files: []
|