commit-live-cli 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/clive +2 -2
- data/lib/commit-live/api.rb +53 -53
- data/lib/commit-live/cli.rb +50 -50
- data/lib/commit-live/lesson/current.rb +14 -6
- data/lib/commit-live/lesson/git-helper.rb +117 -103
- data/lib/commit-live/lesson/open.rb +29 -23
- data/lib/commit-live/lesson/parser.rb +19 -19
- data/lib/commit-live/lesson/status.rb +42 -0
- data/lib/commit-live/lesson/submit.rb +7 -7
- data/lib/commit-live/netrc-interactor.rb +23 -23
- data/lib/commit-live/options-sanitizer.rb +34 -34
- data/lib/commit-live/tests/runner.rb +68 -29
- data/lib/commit-live/tests/strategies/python-test.rb +13 -15
- data/lib/commit-live/tests/strategy.rb +9 -11
- data/lib/commit-live/user.rb +12 -8
- data/lib/commit-live/version.rb +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5b31aee6b82c9e1f200ed56ddeeb4a1872a9643
|
4
|
+
data.tar.gz: a30692eb817f2cfa092a814d74ecb6af3bdeb709
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8c435641b96def863e44a03c32ed8b87748ea43792e351826e300cb61258bcd20e859082bcb63c2a9d986618d34cee765ab483671608c81fcda7ddeef87b91a
|
7
|
+
data.tar.gz: 8711f052b2f9c80c979616fedac3c70dc534f35ef9e472de464515493a9145e12a8436c57274aba0e79ddbffd0f24b282f7bc9fb3bc4105e6c0d5936db9d7399
|
data/bin/clive
CHANGED
data/lib/commit-live/api.rb
CHANGED
@@ -1,66 +1,66 @@
|
|
1
1
|
require "faraday"
|
2
2
|
|
3
3
|
module CommitLive
|
4
|
-
|
5
|
-
|
4
|
+
class API
|
5
|
+
attr_reader :conn
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
URL = 'http://api.greyatom.com'
|
8
|
+
API_ROOT = '/api/v1'
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
def initialize()
|
11
|
+
@conn = Faraday.new(url: URL) do |faraday|
|
12
|
+
faraday.adapter Faraday.default_adapter
|
13
|
+
end
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def get(url, options = {})
|
17
|
+
request :get, url, options
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
def post(url, options = {})
|
21
|
+
request :post, url, options
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
26
|
+
def request(method, url, options = {})
|
27
|
+
begin
|
28
|
+
connection = options[:client] || @conn
|
29
|
+
connection.send(method) do |req|
|
30
|
+
req.url url
|
31
|
+
buildRequest(req, options)
|
32
|
+
end
|
33
|
+
rescue Faraday::ConnectionFailed
|
34
|
+
puts "Connection error. Please try again."
|
35
|
+
end
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
def buildRequest(request, options)
|
39
|
+
buildHeaders(request, options[:headers])
|
40
|
+
buildParams(request, options[:params])
|
41
|
+
buildBody(request, options[:body])
|
42
|
+
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
def buildHeaders(request, headers)
|
45
|
+
if headers
|
46
|
+
headers.each do |header, value|
|
47
|
+
request.headers[header] = value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
def buildParams(request, params)
|
53
|
+
if params
|
54
|
+
params.each do |param, value|
|
55
|
+
request.params[param] = value
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
def buildBody(request, body)
|
61
|
+
if body
|
62
|
+
request.body = Oj.dump(body, mode: :compat)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
66
|
end
|
data/lib/commit-live/cli.rb
CHANGED
@@ -7,56 +7,56 @@ require 'commit-live/lesson/parser'
|
|
7
7
|
require 'thor'
|
8
8
|
|
9
9
|
module CommitLive
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
class CLI < Thor
|
11
|
+
desc "hello", "This will greet you"
|
12
|
+
def hello()
|
13
|
+
puts "Hello World!"
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
desc "reset", "This will forget you"
|
35
|
-
def reset()
|
36
|
-
CommitLive::User.new().confirmAndReset
|
37
|
-
end
|
38
|
-
|
39
|
-
desc "open", "This will fork new work"
|
40
|
-
def open(*puzzle_name)
|
41
|
-
# Fork and Clone User's current lesson
|
42
|
-
lab_name = CommitLive::Puzzle::Parser.new(puzzle_name.join(' ')).parse!
|
43
|
-
CommitLive::Open.new().openALesson(lab_name)
|
44
|
-
end
|
45
|
-
|
46
|
-
desc "submit", "This will submit your work"
|
47
|
-
def submit()
|
48
|
-
CommitLive::Submit.new().run
|
49
|
-
end
|
50
|
-
|
51
|
-
desc "test", "This will test you"
|
52
|
-
def test()
|
53
|
-
puts 'Testing...'
|
54
|
-
CommitLive::Test.new().run
|
55
|
-
end
|
16
|
+
desc "setup", "This will ask for token"
|
17
|
+
def setup(retries: 5)
|
18
|
+
# Check if token already present
|
19
|
+
login, password = CommitLive::NetrcInteractor.new().read
|
20
|
+
if login.nil? || password.nil?
|
21
|
+
print 'Enter your github token here and press [ENTER]: '
|
22
|
+
password = STDIN.gets.chomp
|
23
|
+
if password.empty?
|
24
|
+
puts "No token provided."
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
end
|
28
|
+
# Check if token is valid
|
29
|
+
user = CommitLive::User.new()
|
30
|
+
user.validate(password)
|
31
|
+
user.setDefaultWorkspace
|
32
|
+
end
|
56
33
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
34
|
+
desc "reset", "This will forget you"
|
35
|
+
def reset()
|
36
|
+
CommitLive::User.new().confirmAndReset
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "open", "This will fork new work"
|
40
|
+
def open(*puzzle_name)
|
41
|
+
# Fork and Clone User's current lesson
|
42
|
+
lab_name = CommitLive::Puzzle::Parser.new(puzzle_name.join(' ')).parse!
|
43
|
+
CommitLive::Open.new().openALesson(lab_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "submit", "This will submit your work"
|
47
|
+
def submit()
|
48
|
+
CommitLive::Submit.new().run
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "test", "This will test you"
|
52
|
+
def test()
|
53
|
+
puts 'Testing...'
|
54
|
+
CommitLive::Test.new().run
|
55
|
+
end
|
56
|
+
|
57
|
+
desc 'version, -v, --version', 'Display the current version of the CommitLive gem'
|
58
|
+
def version
|
59
|
+
puts CommitLive::Cli::VERSION
|
60
|
+
end
|
61
|
+
end
|
62
62
|
end
|
@@ -1,21 +1,29 @@
|
|
1
1
|
require "commit-live/api"
|
2
|
+
require "commit-live/netrc-interactor"
|
2
3
|
require 'json'
|
3
4
|
|
4
5
|
module CommitLive
|
5
6
|
class Current
|
6
|
-
attr_accessor :lesson
|
7
|
+
attr_accessor :lesson, :netrc
|
8
|
+
|
9
|
+
def initialize()
|
10
|
+
@netrc = CommitLive::NetrcInteractor.new()
|
11
|
+
end
|
7
12
|
|
8
13
|
def getCurrentLesson(*puzzle_name)
|
9
14
|
begin
|
10
15
|
Timeout::timeout(15) do
|
11
|
-
|
16
|
+
netrc.read
|
17
|
+
token = netrc.password
|
18
|
+
response = CommitLive::API.new().get(
|
19
|
+
'/v1/current_lesson',
|
20
|
+
headers: { 'access-token' => "#{token}" }
|
21
|
+
)
|
12
22
|
if response.status == 200
|
13
23
|
@lesson = JSON.parse(response.body)
|
14
|
-
# @lessonRepo = lesson.fetch('github_repo')
|
15
|
-
# @lessonName = lesson.fetch('lesson_name')
|
16
24
|
else
|
17
|
-
|
18
|
-
|
25
|
+
puts "Something went wrong. Please try again."
|
26
|
+
exit 1
|
19
27
|
end
|
20
28
|
end
|
21
29
|
rescue Timeout::Error
|
@@ -1,122 +1,136 @@
|
|
1
1
|
require "commit-live/lesson/current"
|
2
|
+
require "commit-live/lesson/status"
|
2
3
|
require "commit-live/netrc-interactor"
|
3
4
|
require "commit-live/github"
|
4
5
|
|
5
6
|
module CommitLive
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
class Submit
|
8
|
+
class GitHelper
|
9
|
+
attr_reader :git, :currentLesson, :netrc, :status
|
10
|
+
attr_accessor :remote_name
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
REPO_BELONGS_TO_US = [
|
13
|
+
'commit-live-students'
|
14
|
+
]
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
def initialize()
|
17
|
+
@git = setGit
|
18
|
+
@netrc = CommitLive::NetrcInteractor.new()
|
19
|
+
@currentLesson = CommitLive::Current.new
|
20
|
+
@status = CommitLive::Status.new
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def commitAndPush
|
24
|
+
checkRemote
|
25
|
+
addChanges
|
26
|
+
commitChanges
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
push
|
29
|
+
createPullRequest
|
30
|
+
update_lesson_status
|
31
|
+
end
|
30
32
|
|
31
|
-
|
33
|
+
private
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
def setGit
|
36
|
+
begin
|
37
|
+
Git.open(FileUtils.pwd)
|
38
|
+
rescue ArgumentError => e
|
39
|
+
if e.message.match(/path does not exist/)
|
40
|
+
puts "It doesn't look like you're in a lesson directory."
|
41
|
+
puts 'Please cd into an appropriate directory and try again.'
|
40
42
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
exit 1
|
44
|
+
else
|
45
|
+
puts 'Sorry, something went wrong. Please try again.'
|
46
|
+
exit 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
def checkRemote
|
52
|
+
netrc.read(machine: 'ga-extra')
|
53
|
+
username = netrc.login
|
54
|
+
if git.remote.url.match(/#{username}/i).nil? && git.remote.url.match(/#{REPO_BELONGS_TO_US.join('|').gsub('-','\-')}/i).nil?
|
55
|
+
puts "It doesn't look like you're in a lesson directory."
|
56
|
+
puts 'Please cd into an appropriate directory and try again.'
|
57
|
+
exit 1
|
58
|
+
else
|
59
|
+
self.remote_name = git.remote.name
|
60
|
+
end
|
61
|
+
end
|
55
62
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
63
|
+
def addChanges
|
64
|
+
puts 'Adding changes...'
|
65
|
+
git.add(all: true)
|
66
|
+
end
|
61
67
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
68
|
+
def commitChanges
|
69
|
+
puts 'Committing changes...'
|
70
|
+
begin
|
71
|
+
git.commit('Done')
|
72
|
+
rescue Git::GitExecuteError => e
|
73
|
+
if e.message.match(/nothing to commit/)
|
74
|
+
puts "It looks like you have no changes to commit."
|
75
|
+
exit 1
|
76
|
+
else
|
77
|
+
puts 'Sorry, something went wrong. Please try again.'
|
78
|
+
exit 1
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
66
82
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
83
|
+
def push()
|
84
|
+
puts 'Pushing changes to GitHub...'
|
85
|
+
push_remote = git.remote(self.remote_name)
|
86
|
+
begin
|
87
|
+
Timeout::timeout(15) do
|
88
|
+
git.push(push_remote)
|
89
|
+
end
|
90
|
+
rescue Git::GitExecuteError => e
|
91
|
+
puts 'There was an error while pushing. Please try again later.'
|
92
|
+
puts e.message
|
93
|
+
exit 1
|
94
|
+
rescue Timeout::Error
|
95
|
+
puts "Can't reach GitHub right now. Please try again."
|
96
|
+
exit 1
|
97
|
+
end
|
98
|
+
end
|
81
99
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
100
|
+
def createPullRequest
|
101
|
+
puts 'Creating Pull Request...'
|
102
|
+
currentLesson.getCurrentLesson
|
103
|
+
userGithub = CommitLive::Github.new()
|
104
|
+
netrc.read(machine: 'ga-extra')
|
105
|
+
username = netrc.login
|
106
|
+
begin
|
107
|
+
Timeout::timeout(45) do
|
108
|
+
lessonData = currentLesson.getAttr('data')
|
109
|
+
parentRepo = lessonData['chapters']['lessons']['repo_url']
|
110
|
+
pullRequest = userGithub.client.create_pull_request(
|
111
|
+
parentRepo,
|
112
|
+
'master',
|
113
|
+
"#{username}:master",
|
114
|
+
"PR by #{username}"
|
115
|
+
)
|
116
|
+
puts "Lesson submitted successfully!"
|
117
|
+
end
|
118
|
+
rescue Octokit::Error => err
|
119
|
+
puts "Error while creating PR!"
|
120
|
+
puts err
|
121
|
+
exit 1
|
122
|
+
rescue Timeout::Error
|
123
|
+
puts "Please check your internet connection."
|
124
|
+
exit 1
|
125
|
+
end
|
126
|
+
end
|
98
127
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
parentRepo = currentLesson.getAttr('github_repo')
|
108
|
-
pullRequest = userGithub.client.create_pull_request(parentRepo, 'master', "#{username}:master", "PR by #{username}")
|
109
|
-
puts "Lesson submitted successfully!"
|
110
|
-
end
|
111
|
-
rescue Octokit::Error => err
|
112
|
-
puts "Error while creating PR!"
|
113
|
-
puts err
|
114
|
-
exit
|
115
|
-
rescue Timeout::Error
|
116
|
-
puts "Please check your internet connection."
|
117
|
-
exit
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
128
|
+
def update_lesson_status
|
129
|
+
puts 'Updating lesson status...'
|
130
|
+
lessonData = currentLesson.getAttr('data')
|
131
|
+
lessonName = lessonData['chapters']['lessons']['title']
|
132
|
+
status.update('submitted_pull_request', lessonName)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
122
136
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "commit-live/lesson/current"
|
2
|
+
require "commit-live/lesson/status"
|
2
3
|
require "commit-live/netrc-interactor"
|
3
4
|
require "commit-live/api"
|
4
5
|
require "commit-live/github"
|
@@ -7,22 +8,24 @@ require 'git'
|
|
7
8
|
|
8
9
|
module CommitLive
|
9
10
|
class Open
|
10
|
-
attr_reader :lessonName, :rootDir, :lesson
|
11
|
+
attr_reader :lessonName, :rootDir, :lesson, :forkedRepo, :lesson_status
|
11
12
|
|
12
13
|
HOME_DIR = File.expand_path("~")
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def initialize()
|
16
|
+
if File.exists?("#{HOME_DIR}/.ga-config")
|
17
|
+
@rootDir = YAML.load(File.read("#{HOME_DIR}/.ga-config"))[:workspace]
|
18
|
+
end
|
19
|
+
@lesson = CommitLive::Current.new
|
20
|
+
@lesson_status = CommitLive::Status.new
|
21
|
+
end
|
20
22
|
|
21
23
|
def openALesson(*puzzle_name)
|
22
24
|
# get currently active lesson
|
23
25
|
puts "Getting current lesson..."
|
24
26
|
lesson.getCurrentLesson(puzzle_name)
|
25
|
-
|
27
|
+
lessonData = lesson.getAttr('data')
|
28
|
+
@lessonName = lessonData['chapters']['lessons']['title']
|
26
29
|
if !File.exists?("#{rootDir}/#{lessonName}")
|
27
30
|
# fork lesson repo via github api
|
28
31
|
forkCurrentLesson
|
@@ -30,6 +33,9 @@ module CommitLive
|
|
30
33
|
cloneCurrentLesson
|
31
34
|
# change group owner
|
32
35
|
change_grp_owner
|
36
|
+
# lesson forked API change
|
37
|
+
puts 'Updating lesson status...'
|
38
|
+
lesson_status.update('lesson_forked', lessonName)
|
33
39
|
end
|
34
40
|
# install dependencies
|
35
41
|
# cd into it and invoke bash
|
@@ -41,8 +47,9 @@ module CommitLive
|
|
41
47
|
github = CommitLive::Github.new()
|
42
48
|
begin
|
43
49
|
Timeout::timeout(15) do
|
44
|
-
|
45
|
-
|
50
|
+
lessonData = lesson.getAttr('data')
|
51
|
+
lessonRepo = lessonData['chapters']['lessons']['repo_url']
|
52
|
+
@forkedRepo = github.client.fork(lessonRepo)
|
46
53
|
end
|
47
54
|
rescue Octokit::Error => err
|
48
55
|
puts "Error while forking!"
|
@@ -57,18 +64,17 @@ module CommitLive
|
|
57
64
|
def cloneCurrentLesson
|
58
65
|
puts "Cloning lesson..."
|
59
66
|
begin
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
67
|
+
Timeout::timeout(15) do
|
68
|
+
Git.clone(forkedRepo.ssh_url, lessonName, path: rootDir)
|
69
|
+
end
|
70
|
+
rescue Git::GitExecuteError => err
|
71
|
+
puts "Error while cloning!"
|
72
|
+
puts err
|
73
|
+
exit
|
74
|
+
rescue Timeout::Error
|
75
|
+
puts "Cannot clone this lesson right now. Please try again."
|
76
|
+
exit
|
77
|
+
end
|
72
78
|
end
|
73
79
|
|
74
80
|
def change_grp_owner
|
@@ -76,7 +82,7 @@ module CommitLive
|
|
76
82
|
if results
|
77
83
|
puts "..."
|
78
84
|
else
|
79
|
-
|
85
|
+
puts "Couldn't change group ownership"
|
80
86
|
end
|
81
87
|
end
|
82
88
|
|
@@ -1,25 +1,25 @@
|
|
1
1
|
module CommitLive
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
module Puzzle
|
3
|
+
class Parser
|
4
|
+
attr_reader :name
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(name)
|
7
|
+
@name = name
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
def parse!
|
11
|
+
if name.chars.include?(' ')
|
12
|
+
slugify_name!
|
13
|
+
else
|
14
|
+
name.downcase.strip
|
15
|
+
end
|
16
|
+
end
|
17
17
|
|
18
|
-
|
18
|
+
private
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
def slugify_name!
|
21
|
+
name.downcase.gsub(' ', '-').strip
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
25
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "commit-live/api"
|
2
|
+
require "commit-live/netrc-interactor"
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module CommitLive
|
6
|
+
class Status
|
7
|
+
attr_reader :api, :netrc
|
8
|
+
|
9
|
+
def initialize()
|
10
|
+
@api = CommitLive::API.new
|
11
|
+
@netrc = CommitLive::NetrcInteractor.new()
|
12
|
+
end
|
13
|
+
|
14
|
+
def update(type, lessonName)
|
15
|
+
begin
|
16
|
+
Timeout::timeout(15) do
|
17
|
+
netrc.read
|
18
|
+
token = netrc.password
|
19
|
+
enc_url = URI.escape("/v1/user/lesson/#{lessonName}")
|
20
|
+
response = api.post(
|
21
|
+
enc_url,
|
22
|
+
headers: { 'access-token' => "#{token}" },
|
23
|
+
params: {
|
24
|
+
'method' => 'assignment_status',
|
25
|
+
'action' => type
|
26
|
+
}
|
27
|
+
)
|
28
|
+
if response.status == 202
|
29
|
+
puts "Lesson Status updated!"
|
30
|
+
else
|
31
|
+
puts "Something went wrong. Please try again."
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
rescue Timeout::Error
|
36
|
+
puts "Error while updating lesson status."
|
37
|
+
puts "Please check your internet connection."
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -2,11 +2,11 @@ require 'commit-live/lesson/git-helper'
|
|
2
2
|
require 'octokit'
|
3
3
|
|
4
4
|
module CommitLive
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
class Submit
|
6
|
+
def run
|
7
|
+
CommitLive::Submit::GitHelper.new().commitAndPush
|
8
|
+
# Just to give GitHub a second to register the repo changes
|
9
|
+
sleep(1)
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
@@ -1,34 +1,34 @@
|
|
1
1
|
require 'netrc'
|
2
2
|
|
3
3
|
module CommitLive
|
4
|
-
|
5
|
-
|
4
|
+
class NetrcInteractor
|
5
|
+
attr_reader :login, :password, :netrc
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def initialize
|
8
|
+
ensure_proper_permissions!
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def read(machine: 'ga-config')
|
12
|
+
@netrc = Netrc.read
|
13
|
+
@login, @password = netrc[machine]
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def write(machine: 'ga-config', new_login:, new_password:)
|
17
|
+
netrc[machine] = new_login, new_password
|
18
|
+
netrc.save
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
def delete!(machine:)
|
22
|
+
@netrc = Netrc.read
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
netrc.delete(machine)
|
25
|
+
netrc.save
|
26
|
+
end
|
27
27
|
|
28
|
-
|
28
|
+
private
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
def ensure_proper_permissions!
|
31
|
+
system('chmod 0600 ~/.netrc &>/dev/null')
|
32
|
+
end
|
33
|
+
end
|
34
34
|
end
|
@@ -1,44 +1,44 @@
|
|
1
1
|
module CommitLive
|
2
|
-
|
3
|
-
|
2
|
+
class OptionsSanitizer
|
3
|
+
attr_reader :args
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
KNOWN_COMMANDS = [
|
6
|
+
'test',
|
7
|
+
'hello',
|
8
|
+
'help',
|
9
|
+
'version',
|
10
|
+
'-v',
|
11
|
+
'--version',
|
12
|
+
'submit',
|
13
|
+
'open',
|
14
|
+
'reset',
|
15
|
+
'setup'
|
16
|
+
]
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def initialize(args)
|
19
|
+
@args = args
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def sanitize!
|
23
|
+
sanitizeTestArgs!
|
24
|
+
end
|
25
25
|
|
26
|
-
|
26
|
+
private
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
def sanitizeTestArgs!
|
29
|
+
if missingOrUnknownArgs?
|
30
|
+
exitWithCannotUnderstand
|
31
|
+
end
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
# Arg check methods
|
35
|
+
def missingOrUnknownArgs?
|
36
|
+
args.empty? || !KNOWN_COMMANDS.include?(args[0])
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
def exitWithCannotUnderstand
|
40
|
+
puts "Sorry, I can't understand what you're trying to do. Type `clive help` for help."
|
41
|
+
exit
|
42
|
+
end
|
42
43
|
end
|
43
|
-
end
|
44
44
|
end
|
@@ -1,34 +1,73 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require "commit-live/lesson/status"
|
3
|
+
require "commit-live/netrc-interactor"
|
2
4
|
require 'commit-live/tests/strategies/python-test'
|
3
5
|
|
4
6
|
module CommitLive
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
7
|
+
class Test
|
8
|
+
REPO_BELONGS_TO_US = [
|
9
|
+
'commit-live-students'
|
10
|
+
]
|
11
|
+
|
12
|
+
def initialize()
|
13
|
+
check_lesson_dir
|
14
|
+
die if !strategy
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_git
|
18
|
+
begin
|
19
|
+
Git.open(FileUtils.pwd)
|
20
|
+
rescue => e
|
21
|
+
put_error_msg
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def check_lesson_dir
|
26
|
+
git = set_git
|
27
|
+
netrc = CommitLive::NetrcInteractor.new()
|
28
|
+
netrc.read(machine: 'ga-extra')
|
29
|
+
username = netrc.login
|
30
|
+
if git.remote.url.match(/#{username}/i).nil? && git.remote.url.match(/#{REPO_BELONGS_TO_US.join('|').gsub('-','\-')}/i).nil?
|
31
|
+
put_error_msg
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def put_error_msg
|
36
|
+
puts "It doesn't look like you're in a lesson directory."
|
37
|
+
puts 'Please cd into an appropriate directory and try again.'
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
|
41
|
+
def run
|
42
|
+
strategy.check_dependencies
|
43
|
+
strategy.configure
|
44
|
+
results = strategy.run
|
45
|
+
puts 'Updating lesson status...'
|
46
|
+
lessonName = File.basename(Dir.getwd)
|
47
|
+
if results
|
48
|
+
# test case passed
|
49
|
+
CommitLive::Status.new().update('test_case_pass', lessonName)
|
50
|
+
else
|
51
|
+
# test case failed
|
52
|
+
CommitLive::Status.new().update('test_case_fail', lessonName)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def strategy
|
57
|
+
@strategy ||= strategies.map{ |s| s.new() }.detect(&:detect)
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def strategies
|
63
|
+
[
|
64
|
+
CommitLive::Strategies::PythonUnittest
|
65
|
+
]
|
66
|
+
end
|
67
|
+
|
68
|
+
def die
|
69
|
+
puts "This directory doesn't appear to have any specs in it."
|
70
|
+
exit
|
71
|
+
end
|
72
|
+
end
|
34
73
|
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
require 'commit-live/tests/strategy'
|
2
2
|
|
3
3
|
module CommitLive
|
4
|
-
|
5
|
-
|
4
|
+
module Strategies
|
5
|
+
class PythonUnittest < CommitLive::Strategy
|
6
|
+
def detect
|
7
|
+
files.any? {|f| f.match(/.*.py$/) }
|
8
|
+
end
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
def files
|
11
|
+
@files ||= Dir.entries('.')
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
system("nosetests")
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
14
|
+
def run
|
15
|
+
system("nosetests --verbose")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
21
19
|
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
module CommitLive
|
2
|
-
|
2
|
+
class Strategy
|
3
|
+
def check_dependencies
|
4
|
+
end
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
+
def configure
|
7
|
+
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
raise NotImplementedError, 'you must implement how this strategy runs its tests'
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
9
|
+
def run
|
10
|
+
raise NotImplementedError, 'you must implement how this strategy runs its tests'
|
11
|
+
end
|
12
|
+
end
|
15
13
|
end
|
data/lib/commit-live/user.rb
CHANGED
@@ -17,7 +17,10 @@ module CommitLive
|
|
17
17
|
puts "Authenticating..."
|
18
18
|
begin
|
19
19
|
Timeout::timeout(15) do
|
20
|
-
response = CommitLive::API.new().get(
|
20
|
+
response = CommitLive::API.new().get(
|
21
|
+
"/v1/users/#{token}",
|
22
|
+
headers: { 'access-token' => "#{token}" }
|
23
|
+
)
|
21
24
|
if response.status == 200
|
22
25
|
# Save valid user details in netrc
|
23
26
|
user = JSON.parse(response.body)
|
@@ -25,17 +28,17 @@ module CommitLive
|
|
25
28
|
if login.nil? || password.nil?
|
26
29
|
save(user, token)
|
27
30
|
else
|
28
|
-
username = user.fetch('username'
|
31
|
+
username = user.fetch('data')['username']
|
29
32
|
welcome(username)
|
30
33
|
end
|
31
34
|
else
|
32
35
|
case response.status
|
33
36
|
when 401
|
34
|
-
|
35
|
-
|
37
|
+
puts "It seems your OAuth token is incorrect. Please retry with correct token."
|
38
|
+
exit 1
|
36
39
|
else
|
37
|
-
|
38
|
-
|
40
|
+
puts "Something went wrong. Please try again."
|
41
|
+
exit 1
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
@@ -46,8 +49,9 @@ module CommitLive
|
|
46
49
|
end
|
47
50
|
|
48
51
|
def save(userDetails, token)
|
49
|
-
|
50
|
-
|
52
|
+
user_data = userDetails.fetch('data')
|
53
|
+
username = user_data['username']
|
54
|
+
github_uid = user_data['id']
|
51
55
|
netrc.write(new_login: 'greyatom', new_password: token)
|
52
56
|
netrc.write(machine: 'ga-extra', new_login: username, new_password: github_uid)
|
53
57
|
welcome(username)
|
data/lib/commit-live/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commit-live-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- greyatom
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -178,6 +178,7 @@ files:
|
|
178
178
|
- lib/commit-live/lesson/git-helper.rb
|
179
179
|
- lib/commit-live/lesson/open.rb
|
180
180
|
- lib/commit-live/lesson/parser.rb
|
181
|
+
- lib/commit-live/lesson/status.rb
|
181
182
|
- lib/commit-live/lesson/submit.rb
|
182
183
|
- lib/commit-live/netrc-interactor.rb
|
183
184
|
- lib/commit-live/options-sanitizer.rb
|