learn-submit 1.1.7 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/learn-submit.gemspec +1 -1
- data/lib/learn_submit/submission/git_interactor.rb +12 -2
- data/lib/learn_submit/submission.rb +114 -42
- data/lib/learn_submit/version.rb +1 -1
- data/lib/learn_submit.rb +1 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4525349457cadc91740d2369a91f63b874ebbd2a
|
4
|
+
data.tar.gz: 14730ab215f77ff68be6fd241119d72a2c4d8e80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db069a6647bad5ca8f68d66f0bd4a86b8e835cbc94a9833f1fe3a98cf323d2eee1d7f372067c1defdf1184efaa0042382bde5423731cbe7fd01b75d0f8f3a5f1
|
7
|
+
data.tar.gz: 778d96308cafa33a07974549390458a0b4ead388f8df4e1140729a5ab7c7e4138bb2075f62cdc71676006ef2f41cdb70556824550789890b729b1f9629b37cde
|
data/learn-submit.gemspec
CHANGED
@@ -23,11 +23,21 @@ module LearnSubmit
|
|
23
23
|
push!
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
|
26
|
+
def commit
|
27
|
+
add_changes
|
28
|
+
commit_changes
|
29
|
+
end
|
30
|
+
|
31
|
+
def repo_name(remote: remote_name)
|
32
|
+
url = git.remote(remote).url
|
28
33
|
url.match(/^.+\w+\/(.*?)(?:\.git)?$/)[1]
|
29
34
|
end
|
30
35
|
|
36
|
+
def org_name(remote: remote_name)
|
37
|
+
url = git.remote(remote).url
|
38
|
+
url.match(/^.+github\.com(?::|\/)(.+)\/.*?(?:\.git)?$/)[1]
|
39
|
+
end
|
40
|
+
|
31
41
|
def branch_name
|
32
42
|
git.branch.name
|
33
43
|
end
|
@@ -1,19 +1,22 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module LearnSubmit
|
2
4
|
class Submission
|
3
|
-
attr_reader :git, :client, :file_path, :message, :save
|
5
|
+
attr_reader :git, :client, :file_path, :message, :save, :token, :dot_learn
|
4
6
|
|
5
7
|
def self.create(message: nil, save: false)
|
6
8
|
new(message: message, save: save).create
|
7
9
|
end
|
8
10
|
|
9
11
|
def initialize(message:, save:)
|
10
|
-
_login, token = Netrc.read['learn-config']
|
12
|
+
_login, @token = Netrc.read['learn-config']
|
11
13
|
|
12
|
-
@client = LearnWeb::Client.new(token: token)
|
14
|
+
@client = LearnWeb::Client.new(token: @token)
|
13
15
|
@git = LearnSubmit::Submission::GitInteractor.new(username: user.username, message: message)
|
14
16
|
@file_path = File.expand_path('~/.learn-submit-tmp')
|
15
17
|
@message = message
|
16
18
|
@save = save
|
19
|
+
@dot_learn = YAML.load(File.read("#{FileUtils.pwd}/.learn")) if File.exist?("#{FileUtils.pwd}/.learn")
|
17
20
|
end
|
18
21
|
|
19
22
|
def create
|
@@ -41,62 +44,131 @@ module LearnSubmit
|
|
41
44
|
|
42
45
|
private
|
43
46
|
|
47
|
+
def simulate_submission!(retries=3)
|
48
|
+
begin
|
49
|
+
repo_name = git.repo_name(remote: 'origin')
|
50
|
+
org_name = git.org_name(remote: 'origin')
|
51
|
+
|
52
|
+
if retries == 3
|
53
|
+
puts 'Pushing changes to GitHub...'
|
54
|
+
sleep(1)
|
55
|
+
puts 'Submitting lesson...'
|
56
|
+
end
|
57
|
+
|
58
|
+
Timeout::timeout(15) do
|
59
|
+
client.submit_event(
|
60
|
+
event: 'pull_request',
|
61
|
+
action: 'opened',
|
62
|
+
learn_oauth_token: token,
|
63
|
+
repo_name: repo_name,
|
64
|
+
base_org_name: org_name,
|
65
|
+
forkee: { full_name: nil },
|
66
|
+
pull_request: {
|
67
|
+
head: {
|
68
|
+
repo: {
|
69
|
+
full_name: "#{org_name}/#{repo_name}",
|
70
|
+
name: repo_name
|
71
|
+
}
|
72
|
+
}
|
73
|
+
},
|
74
|
+
summary: {
|
75
|
+
action: 'opened'
|
76
|
+
}
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
after_ide_submission(repo_name)
|
81
|
+
rescue Timeout::Error
|
82
|
+
if retries > 0
|
83
|
+
puts "There was a problem submitting this lab. Retrying..."
|
84
|
+
simulate_submission!(retries-1)
|
85
|
+
else
|
86
|
+
puts "There is an issue connecting to Learn. Please try again."
|
87
|
+
File.write(file_path, 'ERROR: Error connecting to Learn')
|
88
|
+
exit
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
44
93
|
def commit_and_push!
|
45
94
|
File.write(file_path, 'Pushing your code to GitHub...')
|
46
|
-
|
95
|
+
|
96
|
+
if dot_learn && dot_learn['github'] == false
|
97
|
+
git.commit
|
98
|
+
else
|
99
|
+
git.commit_and_push
|
100
|
+
end
|
47
101
|
|
48
102
|
# Just to give GitHub a second to register the repo changes
|
49
103
|
sleep(1)
|
50
104
|
end
|
51
105
|
|
52
106
|
def submit!(retries=3)
|
53
|
-
if
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
107
|
+
if dot_learn && dot_learn['github'] == false
|
108
|
+
simulate_submission!
|
109
|
+
else
|
110
|
+
if retries >= 2
|
111
|
+
puts 'Submitting lesson...'
|
112
|
+
File.write(file_path, 'Opening a Pull Request...')
|
113
|
+
end
|
114
|
+
repo_name = git.repo_name
|
115
|
+
branch_name = git.branch_name
|
116
|
+
sleep(1)
|
60
117
|
|
61
|
-
|
62
|
-
|
63
|
-
|
118
|
+
begin
|
119
|
+
pr_response = Timeout::timeout(15) do
|
120
|
+
client.issue_pull_request(repo_name: repo_name, branch_name: branch_name, message: message)
|
121
|
+
end
|
122
|
+
rescue Timeout::Error
|
123
|
+
if retries > 0
|
124
|
+
puts "It seems like there's a problem connecting to Learn. Trying again..."
|
125
|
+
submit!(retries-1)
|
126
|
+
else
|
127
|
+
puts "Sorry, there's a problem reaching Learn right now. Please try again."
|
128
|
+
File.write(file_path, 'ERROR: Error connecting to learn.')
|
129
|
+
exit 1
|
130
|
+
end
|
64
131
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
132
|
+
|
133
|
+
case pr_response.status
|
134
|
+
when 200
|
135
|
+
puts "Done."
|
136
|
+
after_ide_submission(repo_name)
|
137
|
+
File.write(file_path, 'Done.')
|
138
|
+
exit
|
139
|
+
when 404
|
140
|
+
puts 'Sorry, it seems like there was a problem connecting with Learn. Please try again.'
|
71
141
|
File.write(file_path, 'ERROR: Error connecting to learn.')
|
72
142
|
exit 1
|
143
|
+
else
|
144
|
+
if retries > 0
|
145
|
+
sleep(2)
|
146
|
+
submit!(0)
|
147
|
+
else
|
148
|
+
puts pr_response.message
|
149
|
+
|
150
|
+
if pr_response.message.match(/looks the same/)
|
151
|
+
File.write(file_path, 'ERROR: Nothing to submit')
|
152
|
+
else
|
153
|
+
File.write(file_path, 'Done.')
|
154
|
+
end
|
155
|
+
|
156
|
+
exit 1
|
157
|
+
end
|
73
158
|
end
|
74
159
|
end
|
160
|
+
end
|
75
161
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
File.write(file_path, 'Done.')
|
80
|
-
exit
|
81
|
-
when 404
|
82
|
-
puts 'Sorry, it seems like there was a problem connecting with Learn. Please try again.'
|
83
|
-
File.write(file_path, 'ERROR: Error connecting to learn.')
|
84
|
-
exit 1
|
85
|
-
else
|
86
|
-
if retries > 0
|
87
|
-
sleep(2)
|
88
|
-
submit!(0)
|
89
|
-
else
|
90
|
-
puts pr_response.message
|
162
|
+
def after_ide_submission(repo_name)
|
163
|
+
return unless dot_learn && dot_learn['after_ide_submission']
|
164
|
+
return unless Socket.gethostname.end_with? '.students.learn.co'
|
91
165
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
File.write(file_path, 'Done.')
|
96
|
-
end
|
166
|
+
ide_user_home = "/home/#{ENV['USER']}"
|
167
|
+
path = "#{ide_user_home}/code/labs/#{repo_name}/"
|
168
|
+
url = dot_learn['after_ide_submission']
|
97
169
|
|
98
|
-
|
99
|
-
|
170
|
+
File.open("#{ide_user_home}/.fs_changes.log", 'a') do |f|
|
171
|
+
f.puts "#{path} LEARN_SUBMIT #{url}"
|
100
172
|
end
|
101
173
|
end
|
102
174
|
end
|
data/lib/learn_submit/version.rb
CHANGED
data/lib/learn_submit.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: learn-submit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flatiron School
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.
|
75
|
+
version: 1.5.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.
|
82
|
+
version: 1.5.0
|
83
83
|
description:
|
84
84
|
email:
|
85
85
|
- learn@flatironschool.com
|