commit-live-cli 0.0.23 → 0.1.0

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: 6d45ad410bfe948285bf25b5652e497b54043593
4
- data.tar.gz: '00318d6b80ee020a995562d10b209f02b74b6679'
3
+ metadata.gz: b709e76c453c1368baffb3c69ee21b4271b7beaa
4
+ data.tar.gz: cbb74a0bdcd090e0fbe4b8b88d0f7b30c95bce03
5
5
  SHA512:
6
- metadata.gz: 0d05711060ff9dac8b57c7eeeecf821a16d1058f0b736f39d1d23a1376706a3812e1a9ffcd00145ecc1628b5de47b1df4069b70cf16befab9180fcc8e2e0ae41
7
- data.tar.gz: 4ed5f0d36065629528141bb97e3d8e9a4907f61112d798be9520a9c430ba94b0c871f40716730f5d73b979d55360e37bc73592f31da99c7cab6a5c5f8085a2fd
6
+ metadata.gz: 8327dbdb9b8b634018aef8903d3a429d5fab4069e39990e735d7d59b42af72f4bd983c079d2a60c2b7aaf42fc3f4d7e823a13aae0cbfdd63dec9065fe664608f
7
+ data.tar.gz: eb5f274543d192232d48f9d3b83dc1516a3045515f59cf5107e77899645efdc6d2e1f9a80d790e3e29b82bef001cc2fefe8cdfa583a6f32e3a870788f2d131c3
@@ -13,12 +13,18 @@ module CommitLive
13
13
  puts "Hello World!"
14
14
  end
15
15
 
16
- desc "setup", "This will ask for token"
16
+ desc "setup", "This will ask for your User-ID & Access Token"
17
17
  def setup(retries: 5)
18
18
  # Check if token already present
19
19
  login, password = CommitLive::NetrcInteractor.new().read
20
20
  if login.nil? || password.nil?
21
- print 'Enter your github token here and press [ENTER]: '
21
+ print 'Enter User-ID here and press [ENTER]: '
22
+ login = STDIN.gets.chomp
23
+ if login.empty?
24
+ puts "No User-ID provided."
25
+ exit
26
+ end
27
+ print 'Enter Access token here and press [ENTER]: '
22
28
  password = STDIN.gets.chomp
23
29
  if password.empty?
24
30
  puts "No token provided."
@@ -27,7 +33,7 @@ module CommitLive
27
33
  end
28
34
  # Check if token is valid
29
35
  user = CommitLive::User.new()
30
- user.validate(password)
36
+ user.validate(login, password)
31
37
  user.setDefaultWorkspace
32
38
  end
33
39
 
@@ -36,21 +42,19 @@ module CommitLive
36
42
  CommitLive::User.new().confirmAndReset
37
43
  end
38
44
 
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)
45
+ desc "open <track-slug>", "This will fork given assignment. (for eg. clive open <track-slug>)"
46
+ def open(track_slug)
47
+ CommitLive::Open.new().openALesson(track_slug)
44
48
  end
45
49
 
46
- desc "submit", "This will submit your work"
47
- def submit()
48
- CommitLive::Submit.new().run
50
+ desc "submitn <track-slug>", "This will submit your work"
51
+ def submit(track_slug)
52
+ CommitLive::Submit.new().run(track_slug)
49
53
  end
50
54
 
51
- desc "test", "This will test you"
52
- def test()
53
- CommitLive::Test.new().run
55
+ desc "test <track-slug>", "This will test your assignment. (for eg. clive test <track-slug>)"
56
+ def test(track_slug)
57
+ CommitLive::Test.new(track_slug).run
54
58
  end
55
59
 
56
60
  desc 'version, -v, --version', 'Display the current version of the CommitLive gem'
@@ -1,7 +1,7 @@
1
1
  module CommitLive
2
2
  class Endpoint
3
3
  END_POINTS = {
4
- "PROD" => 'https://api.commit.live',
4
+ "PROD" => 'https://api2.commit.live',
5
5
  "DEV" => 'http://api.greyatom.com',
6
6
  "LOCAL" => 'http://api.greyatom.com'
7
7
  }
@@ -13,11 +13,7 @@ module CommitLive
13
13
  end
14
14
 
15
15
  def getCurrentLesson(puzzle_name)
16
- url = '/v1/current_track'
17
- if !puzzle_name.empty?
18
- url = "/v1/user/track/#{puzzle_name}"
19
- end
20
- getLesson(url)
16
+ getLesson(puzzle_name)
21
17
  end
22
18
 
23
19
  def token
@@ -25,12 +21,12 @@ module CommitLive
25
21
  netrc.password
26
22
  end
27
23
 
28
- def getLesson(url)
24
+ def getLesson(track_slug)
29
25
  begin
30
26
  Timeout::timeout(15) do
31
27
  response = CommitLive::API.new().get(
32
- url,
33
- headers: { 'access-token' => "#{token}" }
28
+ "/v2/user/track/#{track_slug}",
29
+ headers: { 'Authorization' => "#{token}" }
34
30
  )
35
31
  if response.status == 200
36
32
  @lesson = JSON.parse(response.body)
@@ -40,7 +36,7 @@ module CommitLive
40
36
  else
41
37
  sentry.log_message("Get Lesson Failed",
42
38
  {
43
- 'url' => url,
39
+ 'url' => "/v2/user/track/#{track_slug}",
44
40
  'response-body' => response.body,
45
41
  'response-status' => response.status
46
42
  }
@@ -62,11 +58,7 @@ module CommitLive
62
58
 
63
59
  def getValue(key)
64
60
  lessonData = getAttr('data')
65
- if !lessonData['current_track'].nil?
66
- lessonData['current_track'][key]
67
- else
68
- lessonData[key]
69
- end
61
+ lessonData[key]
70
62
  end
71
63
 
72
64
  end
@@ -7,14 +7,15 @@ require "commit-live/sentry"
7
7
  module CommitLive
8
8
  class Submit
9
9
  class GitHelper
10
- attr_reader :git, :currentLesson, :netrc, :status, :lessonName, :sentry
10
+ attr_reader :git, :currentLesson, :netrc, :status, :lessonName, :sentry, :track_slug
11
11
  attr_accessor :remote_name
12
12
 
13
13
  REPO_BELONGS_TO_US = [
14
14
  'commit-live-students'
15
15
  ]
16
16
 
17
- def initialize()
17
+ def initialize(trackSlug)
18
+ @track_slug = trackSlug
18
19
  @git = setGit
19
20
  @netrc = CommitLive::NetrcInteractor.new()
20
21
  @currentLesson = CommitLive::Current.new
@@ -25,19 +26,15 @@ module CommitLive
25
26
 
26
27
  def commitAndPush
27
28
  checkRemote
28
-
29
29
  check_if_practice_lesson
30
-
31
- testCasePassed = currentLesson.getValue('test_case_pass')
32
30
  # Check if User passed test cases
33
- if testCasePassed
31
+ if is_test_case_passed
34
32
  # Push to User's Github
35
33
  addChanges
36
34
  commitChanges
37
35
  push
38
36
 
39
- pullRequestSubmitted = currentLesson.getValue('submitted_pull_request')
40
- if !pullRequestSubmitted
37
+ if !is_submitted_pr
41
38
  # Create Pull Request
42
39
  createPullRequest
43
40
  update_lesson_status
@@ -53,11 +50,35 @@ module CommitLive
53
50
 
54
51
  private
55
52
 
56
- def check_if_practice_lesson
57
- currentLesson.getCurrentLesson(lessonName)
53
+ def is_test_case_passed
54
+ isTestCasesPassed = currentLesson.getValue('testCasesPassed')
55
+ !isTestCasesPassed.nil? && isTestCasesPassed == 1
56
+ end
57
+
58
+ def is_submitted_pr
59
+ isSubmittedPr = currentLesson.getValue('submittedPr')
60
+ !isSubmittedPr.nil? && isSubmittedPr == 1
61
+ end
62
+
63
+ def is_project
64
+ isProject = currentLesson.getValue('isProject')
65
+ !isProject.nil? && isProject == 1
66
+ end
67
+
68
+ def is_practice
58
69
  lessonType = currentLesson.getValue('type')
59
- if lessonType == "PRACTICE"
60
- puts "This is a practice lesson. No need to submit anything."
70
+ !lessonType.nil? && lessonType == "PRACTICE"
71
+ end
72
+
73
+ def repo_url
74
+ currentLesson.getValue('repoUrl')
75
+ end
76
+
77
+ def check_if_practice_lesson
78
+ currentLesson.getCurrentLesson(track_slug)
79
+ if is_project || is_practice
80
+ puts 'This is a Project. Go to individual assignments and follow intructions given on how to submit them.' if is_project
81
+ puts 'This is a Practice Lesson. No need to submit your code.' if is_practice
61
82
  exit 1
62
83
  end
63
84
  end
@@ -159,12 +180,11 @@ module CommitLive
159
180
  username = netrc.login
160
181
  begin
161
182
  Timeout::timeout(45) do
162
- parentRepo = currentLesson.getValue('repo_url')
163
183
  pullRequest = userGithub.client.create_pull_request(
164
- parentRepo,
184
+ repo_url,
165
185
  'master',
166
186
  "#{username}:master",
167
- "PR by #{username}"
187
+ "#{track_slug} - PR by #{username}"
168
188
  )
169
189
  end
170
190
  rescue Octokit::Error => err
@@ -188,7 +208,7 @@ module CommitLive
188
208
  end
189
209
 
190
210
  def update_lesson_status
191
- status.update('submitted_pull_request', lessonName)
211
+ status.update('submittedPr', track_slug)
192
212
  end
193
213
  end
194
214
  end
@@ -12,7 +12,7 @@ module CommitLive
12
12
  attr_reader :rootDir, :lesson, :forkedRepo, :lesson_status, :sentry
13
13
 
14
14
  HOME_DIR = File.expand_path("~")
15
- ALLOWED_TYPES = ["LAB", "PRACTICE"]
15
+ ALLOWED_TYPES = ["CODE", "PRACTICE"]
16
16
 
17
17
  def initialize()
18
18
  if File.exists?("#{HOME_DIR}/.ga-config")
@@ -32,19 +32,34 @@ module CommitLive
32
32
  end
33
33
 
34
34
  def lesson_name
35
- lesson.getValue('track_slug')
35
+ lesson.getValue('titleSlug')
36
+ end
37
+
38
+ def track_slug
39
+ lesson.getValue('titleSlugTestCase')
36
40
  end
37
41
 
38
42
  def lesson_type
39
43
  lesson.getValue('type')
40
44
  end
41
45
 
46
+ def is_project_assignment
47
+ isProjectAssignment = lesson.getValue('isProjectAssignment')
48
+ !isProjectAssignment.nil? && isProjectAssignment == 1
49
+ end
50
+
42
51
  def lesson_forked
43
- lesson.getValue('forked')
52
+ forked = lesson.getValue('forked')
53
+ !forked.nil? && forked == 1
54
+ end
55
+
56
+ def is_project
57
+ isProject = lesson.getValue('isProject')
58
+ !isProject.nil? && isProject == 1
44
59
  end
45
60
 
46
61
  def lesson_repo
47
- lesson.getValue('repo_url')
62
+ lesson.getValue('repoUrl')
48
63
  end
49
64
 
50
65
  def openALesson(puzzle_name)
@@ -59,7 +74,7 @@ module CommitLive
59
74
 
60
75
  if !File.exists?("#{rootDir}/#{lesson_name}")
61
76
  # fork lesson repo via github api
62
- if lesson_type == "LAB"
77
+ if lesson_type == "CODE"
63
78
  forkCurrentLesson
64
79
  end
65
80
  # clone forked lesson into machine
@@ -67,10 +82,10 @@ module CommitLive
67
82
  # change group owner
68
83
  change_grp_owner
69
84
  # lesson forked API change
70
- if lesson_type == "LAB" && !lesson_forked
71
- lesson_status.update('forked', lesson_name)
85
+ if !is_project && lesson_type == "CODE" && !lesson_forked
86
+ lesson_status.update('forked', track_slug)
72
87
  end
73
- if lesson_type == "PRACTICE"
88
+ if lesson_type == "PRACTICE" || is_project
74
89
  open_lesson
75
90
  end
76
91
  else
@@ -148,7 +163,12 @@ module CommitLive
148
163
  url = URI.escape("/send/#{username}")
149
164
  message = {
150
165
  'type': 'open-lesson',
151
- 'title': lesson_name
166
+ 'title': is_project_assignment ? track_slug : lesson_name,
167
+ 'message': {
168
+ 'fileName': 'readme.md',
169
+ 'type': 'forked',
170
+ 'value': true
171
+ }
152
172
  }
153
173
  response = api.post(
154
174
  url,
@@ -19,18 +19,20 @@ module CommitLive
19
19
  end
20
20
 
21
21
  def update(type, trackName)
22
- enc_url = URI.escape("/v1/user/track/#{trackName}")
22
+ enc_url = URI.escape("/v2/user/track/#{trackName}")
23
23
  begin
24
24
  Timeout::timeout(60) do
25
25
  response = api.post(
26
26
  enc_url,
27
- headers: { 'access-token' => "#{token}" },
28
- params: {
29
- 'method' => 'assignment_status',
27
+ headers: {
28
+ 'Authorization' => "#{token}",
29
+ 'Content-Type' => 'application/json'
30
+ },
31
+ body: {
30
32
  'action' => type
31
33
  }
32
34
  )
33
- if response.status != 202
35
+ if response.status != 201
34
36
  sentry.log_message("Update Lesson Status Failed",
35
37
  {
36
38
  'url' => enc_url,
@@ -3,10 +3,10 @@ require "octokit"
3
3
 
4
4
  module CommitLive
5
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)
6
+ def run(track_slug)
7
+ CommitLive::Submit::GitHelper.new(track_slug).commitAndPush
8
+ # Just to give GitHub a second to register the repo changes
9
+ sleep(1)
10
10
  end
11
11
  end
12
12
  end
@@ -9,17 +9,22 @@ require "commit-live/tests/strategies/python-test"
9
9
 
10
10
  module CommitLive
11
11
  class Test
12
- attr_reader :git, :sentry
12
+ attr_reader :git, :sentry, :track_slug, :lesson, :rootDir
13
13
 
14
+ HOME_DIR = File.expand_path("~")
14
15
  REPO_BELONGS_TO_US = [
15
16
  'commit-live-students'
16
17
  ]
17
18
 
18
- def initialize()
19
+ def initialize(trackSlug)
20
+ @track_slug = trackSlug
19
21
  check_lesson_dir
20
22
  check_if_practice_lesson
21
23
  die if !strategy
22
24
  @sentry = CommitLive::Sentry.new()
25
+ if File.exists?("#{HOME_DIR}/.ga-config")
26
+ @rootDir = YAML.load(File.read("#{HOME_DIR}/.ga-config"))[:workspace]
27
+ end
23
28
  end
24
29
 
25
30
  def set_git
@@ -60,21 +65,24 @@ module CommitLive
60
65
  puts 'Testing lesson...'
61
66
  strategy.check_dependencies
62
67
  strategy.configure
63
- results = strategy.run
68
+ results = strategy.run(test_case_dir_path)
69
+ if strategy.results
70
+ strategy.print_results
71
+ end
64
72
  if updateStatus
65
73
  if results
66
74
  # test case passed
67
75
  puts 'Great! You have passed all the test cases.'
68
76
  puts 'Use `clive submit` to push your changes.'
69
- CommitLive::Status.new().update('test_case_pass', lesson_name)
77
+ CommitLive::Status.new().update('testCasesPassed', track_slug)
70
78
  else
71
79
  # test case failed
72
80
  puts 'Oops! You still have to pass all the test cases.'
73
- CommitLive::Status.new().update('test_case_fail', lesson_name)
81
+ CommitLive::Status.new().update('testCasesFailed', track_slug)
74
82
  end
75
83
  end
76
84
  if strategy.results
77
- dump_results
85
+ # dump_results
78
86
  end
79
87
  strategy.cleanup
80
88
  return results
@@ -85,17 +93,43 @@ module CommitLive
85
93
  end
86
94
 
87
95
  def clear_changes_in_tests
88
- system("git checkout HEAD -- tests/")
96
+ system("git checkout HEAD -- #{test_case_dir_path}")
97
+ end
98
+
99
+ def test_case_dir_path
100
+ filePath = ""
101
+ filePath += "#{test_slug}/" if is_project_assignment
102
+ filePath += "tests/"
103
+ return filePath
104
+ end
105
+
106
+ def test_slug
107
+ lesson.getValue('testCase')
108
+ end
109
+
110
+ def is_project_assignment
111
+ isProjectAssignment = lesson.getValue('isProjectAssignment')
112
+ !isProjectAssignment.nil? && isProjectAssignment == 1
113
+ end
114
+
115
+ def is_project
116
+ isProject = lesson.getValue('isProject')
117
+ !isProject.nil? && isProject == 1
118
+ end
119
+
120
+ def is_practice
121
+ lessonType = lesson.getValue('type')
122
+ !lessonType.nil? && lessonType == "PRACTICE"
89
123
  end
90
124
 
91
125
  private
92
126
 
93
127
  def check_if_practice_lesson
94
- lesson = CommitLive::Current.new
95
- lesson.getCurrentLesson(lesson_name)
96
- lessonType = lesson.getValue('type')
97
- if lessonType == "PRACTICE"
98
- puts "This is a practice lesson. No need to run test on it."
128
+ @lesson = CommitLive::Current.new
129
+ lesson.getCurrentLesson(track_slug)
130
+ if is_project || is_practice
131
+ puts 'This is a Project. Go to individual assignments and follow intructions given on how to pass test cases for them.' if is_project
132
+ puts 'This is a Practice Lesson. No need to run tests on it.' if is_practice
99
133
  exit 1
100
134
  end
101
135
  end
@@ -107,23 +141,23 @@ module CommitLive
107
141
  netrc = CommitLive::NetrcInteractor.new()
108
142
  netrc.read
109
143
  token = netrc.password
110
- url = URI.escape("/v1/dumps")
144
+ url = URI.escape("/v2/dumps")
111
145
  response = api.post(
112
146
  url,
113
147
  headers: {
114
- 'access-token' => "#{token}",
115
- 'content-type' => 'application/json',
148
+ 'Authorization' => "#{token}",
149
+ 'Content-Type' => 'application/json',
116
150
  },
117
151
  body: {
118
152
  'data' => Oj.dump(strategy.results, mode: :compat),
119
- 'track_slug' => lesson_name
153
+ 'titleSlugTestCase' => track_slug
120
154
  }
121
155
  )
122
156
  if response.status != 201
123
157
  sentry.log_message("Test Results Dump Failed",
124
158
  {
125
159
  'url' => url,
126
- 'track_slug' => lesson_name,
160
+ 'track-slug' => track_slug,
127
161
  'results' => strategy.results,
128
162
  'response-body' => response.body,
129
163
  'response-status' => response.status
@@ -1,3 +1,4 @@
1
+ require "terminal-table"
1
2
  require "commit-live/tests/strategy"
2
3
 
3
4
  module CommitLive
@@ -11,8 +12,37 @@ module CommitLive
11
12
  @files ||= Dir.entries('.')
12
13
  end
13
14
 
14
- def run
15
- system("nosetests --verbose --with-json --json-file=\"./.results.json\"")
15
+ def run(dir)
16
+ system("nosetests #{dir} --verbose --with-json --json-file=\"./.results.json\" > /dev/null 2>&1")
17
+ end
18
+
19
+ def print_results
20
+ if File.exists?('.results.json')
21
+ rows = []
22
+ totalPassed = 0
23
+ totalFailed = 0
24
+ test_results = results
25
+ columns = ['Test Case', 'Status']
26
+ test_results["results"].each do |value|
27
+ newRow = [value["name"], value["type"]]
28
+ isErrorOrFail = value['type'] == 'failure' || value['type'] == 'error'
29
+ totalFailed += 1 if isErrorOrFail
30
+ newRow << value['message'] if isErrorOrFail
31
+ totalPassed += 1 if value['type'] == 'success'
32
+ rows << newRow
33
+ end
34
+ if totalFailed > 0
35
+ columns << 'Message'
36
+ end
37
+ table = Terminal::Table.new do |t|
38
+ t.headings = columns
39
+ t.rows = rows
40
+ t.style = { :all_separators => true }
41
+ end
42
+ puts table
43
+ puts "Total Passed: #{totalPassed}"
44
+ puts "Total Failed: #{totalFailed}"
45
+ end
16
46
  end
17
47
 
18
48
  def results
@@ -13,13 +13,13 @@ module CommitLive
13
13
  @netrc = CommitLive::NetrcInteractor.new()
14
14
  end
15
15
 
16
- def validate(token)
16
+ def validate(userID, token)
17
17
  puts "Authenticating..."
18
18
  begin
19
19
  Timeout::timeout(15) do
20
20
  response = CommitLive::API.new().get(
21
- "/v1/users/#{token}",
22
- headers: { 'access-token' => "#{token}" }
21
+ "/v2/users/#{userID}",
22
+ headers: { 'Authorization' => "#{token}" }
23
23
  )
24
24
  if response.status == 200
25
25
  # Save valid user details in netrc
@@ -28,7 +28,7 @@ module CommitLive
28
28
  if login.nil? || password.nil?
29
29
  save(user, token)
30
30
  else
31
- username = user.fetch('data')['username']
31
+ username = user.fetch('data')['userName']
32
32
  welcome(username)
33
33
  end
34
34
  else
@@ -50,10 +50,10 @@ module CommitLive
50
50
 
51
51
  def save(userDetails, token)
52
52
  user_data = userDetails.fetch('data')
53
- username = user_data['username']
54
- github_uid = user_data['id']
55
- netrc.write(new_login: 'greyatom', new_password: token)
56
- netrc.write(machine: 'ga-extra', new_login: username, new_password: github_uid)
53
+ username = user_data['userName']
54
+ userID = user_data['id']
55
+ netrc.write(new_login: userID, new_password: token)
56
+ netrc.write(machine: 'ga-extra', new_login: username, new_password: userID)
57
57
  welcome(username)
58
58
  end
59
59
 
@@ -1,5 +1,5 @@
1
1
  module CommitLive
2
2
  module Cli
3
- VERSION = "0.0.23"
3
+ VERSION = "0.1.0"
4
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.23
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - greyatom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-22 00:00:00.000000000 Z
11
+ date: 2017-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -188,6 +188,20 @@ dependencies:
188
188
  - - "~>"
189
189
  - !ruby/object:Gem::Version
190
190
  version: '2.5'
191
+ - !ruby/object:Gem::Dependency
192
+ name: terminal-table
193
+ requirement: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - "~>"
196
+ - !ruby/object:Gem::Version
197
+ version: '1.8'
198
+ type: :runtime
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - "~>"
203
+ - !ruby/object:Gem::Version
204
+ version: '1.8'
191
205
  description:
192
206
  email:
193
207
  - greyatomedutech@gmail.com