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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c19318f01d88e5c412eca18e85e93996fe4e3eea
4
- data.tar.gz: a7b81393f01458087f467a7db12ce7e41217fe31
3
+ metadata.gz: b5b31aee6b82c9e1f200ed56ddeeb4a1872a9643
4
+ data.tar.gz: a30692eb817f2cfa092a814d74ecb6af3bdeb709
5
5
  SHA512:
6
- metadata.gz: 8e14e1aec39dfb6d56165e038e39688be0d9ff8cfde446ca09a20ca7515bbe19433a02fee2ab4c2fe6f84e853a534a0ea6a4c1d4d9e5f0dded774ef5b5eb1b9e
7
- data.tar.gz: fe7a3cf6de78503bdcd0f7e4ffe9b6f00a73aee0c1ab439319b2f21c13bed4cf7b50a98b457dba1e2a651e76f54eb046ce69730fd37f20888436fbd6ab76380f
6
+ metadata.gz: e8c435641b96def863e44a03c32ed8b87748ea43792e351826e300cb61258bcd20e859082bcb63c2a9d986618d34cee765ab483671608c81fcda7ddeef87b91a
7
+ data.tar.gz: 8711f052b2f9c80c979616fedac3c70dc534f35ef9e472de464515493a9145e12a8436c57274aba0e79ddbffd0f24b282f7bc9fb3bc4105e6c0d5936db9d7399
data/bin/clive CHANGED
@@ -3,8 +3,8 @@
3
3
  require 'commit-live'
4
4
 
5
5
  if ['-v', '--version'].include?(ARGV.first)
6
- puts CommitLive::Cli::VERSION
7
- exit
6
+ puts CommitLive::Cli::VERSION
7
+ exit
8
8
  end
9
9
 
10
10
  CommitLive::OptionsSanitizer.new( ARGV ).sanitize!
@@ -1,66 +1,66 @@
1
1
  require "faraday"
2
2
 
3
3
  module CommitLive
4
- class API
5
- attr_reader :conn
4
+ class API
5
+ attr_reader :conn
6
6
 
7
- URL = 'https://api.myjson.com'
8
- API_ROOT = '/api/v1'
7
+ URL = 'http://api.greyatom.com'
8
+ API_ROOT = '/api/v1'
9
9
 
10
- def initialize()
11
- @conn = Faraday.new(url: URL) do |faraday|
12
- faraday.adapter Faraday.default_adapter
13
- end
14
- end
10
+ def initialize()
11
+ @conn = Faraday.new(url: URL) do |faraday|
12
+ faraday.adapter Faraday.default_adapter
13
+ end
14
+ end
15
15
 
16
- def get(url, options = {})
17
- request :get, url, options
18
- end
16
+ def get(url, options = {})
17
+ request :get, url, options
18
+ end
19
19
 
20
- def post(url, options = {})
21
- request :post, url, options
22
- end
23
-
24
- private
20
+ def post(url, options = {})
21
+ request :post, url, options
22
+ end
23
+
24
+ private
25
25
 
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
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
- def buildRequest(request, options)
39
- buildHeaders(request, options[:headers])
40
- buildParams(request, options[:params])
41
- buildBody(request, options[:body])
42
- end
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
- def buildHeaders(request, headers)
45
- if headers
46
- headers.each do |header, value|
47
- request.headers[header] = value
48
- end
49
- end
50
- end
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
- def buildParams(request, params)
53
- if params
54
- params.each do |param, value|
55
- request.params[param] = value
56
- end
57
- end
58
- end
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
- def buildBody(request, body)
61
- if body
62
- request.body = Oj.dump(body, mode: :compat)
63
- end
64
- end
65
- end
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
@@ -7,56 +7,56 @@ require 'commit-live/lesson/parser'
7
7
  require 'thor'
8
8
 
9
9
  module CommitLive
10
- class CLI < Thor
11
- desc "hello", "This will greet you"
12
- def hello()
13
- puts "Hello World!"
14
- end
10
+ class CLI < Thor
11
+ desc "hello", "This will greet you"
12
+ def hello()
13
+ puts "Hello World!"
14
+ end
15
15
 
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
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
- desc 'version, -v, --version', 'Display the current version of the CommitLive gem'
58
- def version
59
- puts CommitLive::Cli::VERSION
60
- end
61
- end
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
- response = CommitLive::API.new().get('/bins/k8lsj')
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
- puts "Something went wrong. Please try again."
18
- exit 1
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
- class Submit
7
- class GitHelper
8
- attr_reader :git, :dummyUsername, :currentLesson, :netrc
9
- attr_accessor :remote_name
7
+ class Submit
8
+ class GitHelper
9
+ attr_reader :git, :currentLesson, :netrc, :status
10
+ attr_accessor :remote_name
10
11
 
11
- REPO_BELONGS_TO_US = [
12
- 'Rubygemtrial'
13
- ]
12
+ REPO_BELONGS_TO_US = [
13
+ 'commit-live-students'
14
+ ]
14
15
 
15
- def initialize()
16
- @git = setGit
17
- @dummyUsername = 'gitint'
18
- @netrc = CommitLive::NetrcInteractor.new()
19
- @currentLesson = CommitLive::Current.new
20
- end
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
- def commitAndPush
23
- checkRemote
24
- addChanges
25
- commitChanges
23
+ def commitAndPush
24
+ checkRemote
25
+ addChanges
26
+ commitChanges
26
27
 
27
- push
28
- createPullRequest
29
- end
28
+ push
29
+ createPullRequest
30
+ update_lesson_status
31
+ end
30
32
 
31
- private
33
+ private
32
34
 
33
- def setGit
34
- begin
35
- Git.open(FileUtils.pwd)
36
- rescue ArgumentError => e
37
- if e.message.match(/path does not exist/)
38
- puts "It doesn't look like you're in a lesson directory."
39
- puts 'Please cd into an appropriate directory and try again.'
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
- exit 1
42
- else
43
- puts 'Sorry, something went wrong. Please try again.'
44
- exit 1
45
- end
46
- end
47
- end
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
- def checkRemote
50
- netrc.read(machine: 'ga-extra')
51
- username = dummyUsername || netrc.login
52
- if git.remote.url.match(/#{username}/i).nil? && git.remote.url.match(/#{REPO_BELONGS_TO_US.join('|').gsub('-','\-')}/i).nil?
53
- puts "It doesn't look like you're in a lesson directory."
54
- puts 'Please cd into an appropriate directory and try again.'
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
- exit 1
57
- else
58
- self.remote_name = git.remote.name
59
- end
60
- end
63
+ def addChanges
64
+ puts 'Adding changes...'
65
+ git.add(all: true)
66
+ end
61
67
 
62
- def addChanges
63
- puts 'Adding changes...'
64
- git.add(all: true)
65
- end
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
- def commitChanges
68
- puts 'Committing changes...'
69
- begin
70
- git.commit('Done')
71
- rescue Git::GitExecuteError => e
72
- if e.message.match(/nothing to commit/)
73
- puts "It looks like you have no changes to commit."
74
- exit 1
75
- else
76
- puts 'Sorry, something went wrong. Please try again.'
77
- exit 1
78
- end
79
- end
80
- end
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
- def push()
83
- puts 'Pushing changes to GitHub...'
84
- push_remote = git.remote(self.remote_name)
85
- begin
86
- Timeout::timeout(15) do
87
- git.push(push_remote)
88
- end
89
- rescue Git::GitExecuteError => e
90
- puts 'There was an error while pushing. Please try again later.'
91
- puts e.message
92
- exit 1
93
- rescue Timeout::Error
94
- puts "Can't reach GitHub right now. Please try again."
95
- exit 1
96
- end
97
- end
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
- def createPullRequest
100
- puts 'Creating Pull Request...'
101
- currentLesson.getCurrentLesson
102
- userGithub = CommitLive::Github.new()
103
- netrc.read
104
- username = dummyUsername || netrc.login
105
- begin
106
- Timeout::timeout(45) do
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
- def initialize()
15
- if File.exists?("#{HOME_DIR}/.ga-config")
16
- @rootDir = YAML.load(File.read("#{HOME_DIR}/.ga-config"))[:workspace]
17
- end
18
- @lesson = CommitLive::Current.new
19
- end
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
- @lessonName = lesson.getAttr('lesson_name')
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
- lessonRepo = lesson.getAttr('github_repo')
45
- forkedRepo = github.client.fork(lessonRepo)
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
- Timeout::timeout(15) do
61
- cloneUrl = lesson.getAttr('forked_repo')
62
- Git.clone("git@github.com:#{cloneUrl}.git", lessonName, path: rootDir)
63
- end
64
- rescue Git::GitExecuteError => err
65
- puts "Error while cloning!"
66
- puts err
67
- exit
68
- rescue Timeout::Error
69
- puts "Cannot clone this lesson right now. Please try again."
70
- exit
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
- puts "Couldn't change group ownership"
85
+ puts "Couldn't change group ownership"
80
86
  end
81
87
  end
82
88
 
@@ -1,25 +1,25 @@
1
1
  module CommitLive
2
- module Puzzle
3
- class Parser
4
- attr_reader :name
2
+ module Puzzle
3
+ class Parser
4
+ attr_reader :name
5
5
 
6
- def initialize(name)
7
- @name = name
8
- end
6
+ def initialize(name)
7
+ @name = name
8
+ end
9
9
 
10
- def parse!
11
- if name.chars.include?(' ')
12
- slugify_name!
13
- else
14
- name.downcase.strip
15
- end
16
- end
10
+ def parse!
11
+ if name.chars.include?(' ')
12
+ slugify_name!
13
+ else
14
+ name.downcase.strip
15
+ end
16
+ end
17
17
 
18
- private
18
+ private
19
19
 
20
- def slugify_name!
21
- name.downcase.gsub(' ', '-').strip
22
- end
23
- end
24
- end
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
- 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
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
- class NetrcInteractor
5
- attr_reader :login, :password, :netrc
4
+ class NetrcInteractor
5
+ attr_reader :login, :password, :netrc
6
6
 
7
- def initialize
8
- ensure_proper_permissions!
9
- end
7
+ def initialize
8
+ ensure_proper_permissions!
9
+ end
10
10
 
11
- def read(machine: 'ga-config')
12
- @netrc = Netrc.read
13
- @login, @password = netrc[machine]
14
- end
11
+ def read(machine: 'ga-config')
12
+ @netrc = Netrc.read
13
+ @login, @password = netrc[machine]
14
+ end
15
15
 
16
- def write(machine: 'ga-config', new_login:, new_password:)
17
- netrc[machine] = new_login, new_password
18
- netrc.save
19
- end
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
- def delete!(machine:)
22
- @netrc = Netrc.read
21
+ def delete!(machine:)
22
+ @netrc = Netrc.read
23
23
 
24
- netrc.delete(machine)
25
- netrc.save
26
- end
24
+ netrc.delete(machine)
25
+ netrc.save
26
+ end
27
27
 
28
- private
28
+ private
29
29
 
30
- def ensure_proper_permissions!
31
- system('chmod 0600 ~/.netrc &>/dev/null')
32
- end
33
- end
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
- class OptionsSanitizer
3
- attr_reader :args
2
+ class OptionsSanitizer
3
+ attr_reader :args
4
4
 
5
- KNOWN_COMMANDS = [
6
- 'test',
7
- 'hello',
8
- 'help',
9
- 'version',
10
- '-v',
11
- '--version',
12
- 'submit',
13
- 'open',
14
- 'reset',
15
- 'setup'
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
- def initialize(args)
19
- @args = args
20
- end
18
+ def initialize(args)
19
+ @args = args
20
+ end
21
21
 
22
- def sanitize!
23
- sanitizeTestArgs!
24
- end
22
+ def sanitize!
23
+ sanitizeTestArgs!
24
+ end
25
25
 
26
- private
26
+ private
27
27
 
28
- def sanitizeTestArgs!
29
- if missingOrUnknownArgs?
30
- exitWithCannotUnderstand
31
- end
32
- end
28
+ def sanitizeTestArgs!
29
+ if missingOrUnknownArgs?
30
+ exitWithCannotUnderstand
31
+ end
32
+ end
33
33
 
34
- # Arg check methods
35
- def missingOrUnknownArgs?
36
- args.empty? || !KNOWN_COMMANDS.include?(args[0])
37
- end
34
+ # Arg check methods
35
+ def missingOrUnknownArgs?
36
+ args.empty? || !KNOWN_COMMANDS.include?(args[0])
37
+ end
38
38
 
39
- def exitWithCannotUnderstand
40
- puts "Sorry, I can't understand what you're trying to do. Type `clive help` for help."
41
- exit
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
- class Test
6
-
7
- def initialize()
8
- die if !strategy
9
- end
10
-
11
- def run
12
- strategy.check_dependencies
13
- strategy.configure
14
- strategy.run
15
- end
16
-
17
- def strategy
18
- @strategy ||= strategies.map{ |s| s.new() }.detect(&:detect)
19
- end
20
-
21
- private
22
-
23
- def strategies
24
- [
25
- CommitLive::Strategies::PythonUnittest
26
- ]
27
- end
28
-
29
- def die
30
- puts "This directory doesn't appear to have any specs in it."
31
- exit
32
- end
33
- end
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
- module Strategies
5
- class PythonUnittest < CommitLive::Strategy
4
+ module Strategies
5
+ class PythonUnittest < CommitLive::Strategy
6
+ def detect
7
+ files.any? {|f| f.match(/.*.py$/) }
8
+ end
6
9
 
7
- def detect
8
- files.any? {|f| f.match(/.*.py$/) }
9
- end
10
+ def files
11
+ @files ||= Dir.entries('.')
12
+ end
10
13
 
11
- def files
12
- @files ||= Dir.entries('.')
13
- end
14
-
15
- def run
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
- class Strategy
2
+ class Strategy
3
+ def check_dependencies
4
+ end
3
5
 
4
- def check_dependencies
5
- end
6
+ def configure
7
+ end
6
8
 
7
- def configure
8
- end
9
-
10
- def run
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
@@ -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('/bins/c4vbn')
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
- puts "It seems your OAuth token is incorrect. Please retry with correct token."
35
- exit 1
37
+ puts "It seems your OAuth token is incorrect. Please retry with correct token."
38
+ exit 1
36
39
  else
37
- puts "Something went wrong. Please try again."
38
- exit 1
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
- username = userDetails.fetch('username')
50
- github_uid = userDetails.fetch('github_uid')
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)
@@ -1,5 +1,5 @@
1
1
  module CommitLive
2
- module Cli
3
- VERSION = "0.0.1"
4
- end
2
+ module Cli
3
+ VERSION = "0.0.2"
4
+ end
5
5
  end
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.1
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-28 00:00:00.000000000 Z
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