commit-live-cli 0.0.1
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 +7 -0
- data/README.md +37 -0
- data/bin/clive +25 -0
- data/lib/commit-live.rb +7 -0
- data/lib/commit-live/api.rb +66 -0
- data/lib/commit-live/cli.rb +62 -0
- data/lib/commit-live/github.rb +16 -0
- data/lib/commit-live/lesson/current.rb +35 -0
- data/lib/commit-live/lesson/git-helper.rb +122 -0
- data/lib/commit-live/lesson/open.rb +90 -0
- data/lib/commit-live/lesson/parser.rb +25 -0
- data/lib/commit-live/lesson/submit.rb +12 -0
- data/lib/commit-live/netrc-interactor.rb +34 -0
- data/lib/commit-live/options-sanitizer.rb +44 -0
- data/lib/commit-live/tests/runner.rb +34 -0
- data/lib/commit-live/tests/strategies/python-test.rb +21 -0
- data/lib/commit-live/tests/strategy.rb +15 -0
- data/lib/commit-live/user.rb +93 -0
- data/lib/commit-live/version.rb +5 -0
- metadata +214 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c19318f01d88e5c412eca18e85e93996fe4e3eea
|
4
|
+
data.tar.gz: a7b81393f01458087f467a7db12ce7e41217fe31
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e14e1aec39dfb6d56165e038e39688be0d9ff8cfde446ca09a20ca7515bbe19433a02fee2ab4c2fe6f84e853a534a0ea6a4c1d4d9e5f0dded774ef5b5eb1b9e
|
7
|
+
data.tar.gz: fe7a3cf6de78503bdcd0f7e4ffe9b6f00a73aee0c1ab439319b2f21c13bed4cf7b50a98b457dba1e2a651e76f54eb046ce69730fd37f20888436fbd6ab76380f
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Commit Live Cli
|
2
|
+
|
3
|
+
The command line interface for learners at greyatom.com
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'commit-live-cli'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install commit-live-cli
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
$ clive help
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/commit-live-cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
32
|
+
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
37
|
+
|
data/bin/clive
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'commit-live'
|
4
|
+
|
5
|
+
if ['-v', '--version'].include?(ARGV.first)
|
6
|
+
puts CommitLive::Cli::VERSION
|
7
|
+
exit
|
8
|
+
end
|
9
|
+
|
10
|
+
CommitLive::OptionsSanitizer.new( ARGV ).sanitize!
|
11
|
+
|
12
|
+
COMMANDS_THAT_REQUIRE_OAUTH = [
|
13
|
+
'submit',
|
14
|
+
'open'
|
15
|
+
]
|
16
|
+
|
17
|
+
netrc = CommitLive::NetrcInteractor.new()
|
18
|
+
netrc.read
|
19
|
+
token = netrc.password
|
20
|
+
if token.nil? && COMMANDS_THAT_REQUIRE_OAUTH.include?(ARGV[0])
|
21
|
+
puts 'You are not authorized to use this command. Run `clive setup` get started.'
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
25
|
+
CommitLive::CLI.start( ARGV )
|
data/lib/commit-live.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
module CommitLive
|
4
|
+
class API
|
5
|
+
attr_reader :conn
|
6
|
+
|
7
|
+
URL = 'https://api.myjson.com'
|
8
|
+
API_ROOT = '/api/v1'
|
9
|
+
|
10
|
+
def initialize()
|
11
|
+
@conn = Faraday.new(url: URL) do |faraday|
|
12
|
+
faraday.adapter Faraday.default_adapter
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(url, options = {})
|
17
|
+
request :get, url, options
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(url, options = {})
|
21
|
+
request :post, url, options
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
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
|
37
|
+
|
38
|
+
def buildRequest(request, options)
|
39
|
+
buildHeaders(request, options[:headers])
|
40
|
+
buildParams(request, options[:params])
|
41
|
+
buildBody(request, options[:body])
|
42
|
+
end
|
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
|
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
|
59
|
+
|
60
|
+
def buildBody(request, body)
|
61
|
+
if body
|
62
|
+
request.body = Oj.dump(body, mode: :compat)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'commit-live/user'
|
2
|
+
require 'commit-live/netrc-interactor'
|
3
|
+
require 'commit-live/tests/runner'
|
4
|
+
require 'commit-live/lesson/submit'
|
5
|
+
require 'commit-live/lesson/open'
|
6
|
+
require 'commit-live/lesson/parser'
|
7
|
+
require 'thor'
|
8
|
+
|
9
|
+
module CommitLive
|
10
|
+
class CLI < Thor
|
11
|
+
desc "hello", "This will greet you"
|
12
|
+
def hello()
|
13
|
+
puts "Hello World!"
|
14
|
+
end
|
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
|
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
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "commit-live/netrc-interactor"
|
2
|
+
require 'octokit'
|
3
|
+
|
4
|
+
module CommitLive
|
5
|
+
class Github
|
6
|
+
attr_accessor :client
|
7
|
+
def initialize()
|
8
|
+
netrc = CommitLive::NetrcInteractor.new()
|
9
|
+
netrc.read
|
10
|
+
token = netrc.password
|
11
|
+
if !token.nil?
|
12
|
+
@client = Octokit::Client.new(:access_token => token)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "commit-live/api"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module CommitLive
|
5
|
+
class Current
|
6
|
+
attr_accessor :lesson
|
7
|
+
|
8
|
+
def getCurrentLesson(*puzzle_name)
|
9
|
+
begin
|
10
|
+
Timeout::timeout(15) do
|
11
|
+
response = CommitLive::API.new().get('/bins/k8lsj')
|
12
|
+
if response.status == 200
|
13
|
+
@lesson = JSON.parse(response.body)
|
14
|
+
# @lessonRepo = lesson.fetch('github_repo')
|
15
|
+
# @lessonName = lesson.fetch('lesson_name')
|
16
|
+
else
|
17
|
+
puts "Something went wrong. Please try again."
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
rescue Timeout::Error
|
22
|
+
puts "Error while getting current lesson."
|
23
|
+
puts "Please check your internet connection."
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def getAttr(attr)
|
29
|
+
if !attr.nil?
|
30
|
+
lesson.fetch(attr)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require "commit-live/lesson/current"
|
2
|
+
require "commit-live/netrc-interactor"
|
3
|
+
require "commit-live/github"
|
4
|
+
|
5
|
+
module CommitLive
|
6
|
+
class Submit
|
7
|
+
class GitHelper
|
8
|
+
attr_reader :git, :dummyUsername, :currentLesson, :netrc
|
9
|
+
attr_accessor :remote_name
|
10
|
+
|
11
|
+
REPO_BELONGS_TO_US = [
|
12
|
+
'Rubygemtrial'
|
13
|
+
]
|
14
|
+
|
15
|
+
def initialize()
|
16
|
+
@git = setGit
|
17
|
+
@dummyUsername = 'gitint'
|
18
|
+
@netrc = CommitLive::NetrcInteractor.new()
|
19
|
+
@currentLesson = CommitLive::Current.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def commitAndPush
|
23
|
+
checkRemote
|
24
|
+
addChanges
|
25
|
+
commitChanges
|
26
|
+
|
27
|
+
push
|
28
|
+
createPullRequest
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
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.'
|
40
|
+
|
41
|
+
exit 1
|
42
|
+
else
|
43
|
+
puts 'Sorry, something went wrong. Please try again.'
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
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.'
|
55
|
+
|
56
|
+
exit 1
|
57
|
+
else
|
58
|
+
self.remote_name = git.remote.name
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def addChanges
|
63
|
+
puts 'Adding changes...'
|
64
|
+
git.add(all: true)
|
65
|
+
end
|
66
|
+
|
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
|
81
|
+
|
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
|
98
|
+
|
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
|
122
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require "commit-live/lesson/current"
|
2
|
+
require "commit-live/netrc-interactor"
|
3
|
+
require "commit-live/api"
|
4
|
+
require "commit-live/github"
|
5
|
+
require 'octokit'
|
6
|
+
require 'git'
|
7
|
+
|
8
|
+
module CommitLive
|
9
|
+
class Open
|
10
|
+
attr_reader :lessonName, :rootDir, :lesson
|
11
|
+
|
12
|
+
HOME_DIR = File.expand_path("~")
|
13
|
+
|
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
|
20
|
+
|
21
|
+
def openALesson(*puzzle_name)
|
22
|
+
# get currently active lesson
|
23
|
+
puts "Getting current lesson..."
|
24
|
+
lesson.getCurrentLesson(puzzle_name)
|
25
|
+
@lessonName = lesson.getAttr('lesson_name')
|
26
|
+
if !File.exists?("#{rootDir}/#{lessonName}")
|
27
|
+
# fork lesson repo via github api
|
28
|
+
forkCurrentLesson
|
29
|
+
# clone forked lesson into machine
|
30
|
+
cloneCurrentLesson
|
31
|
+
# change group owner
|
32
|
+
change_grp_owner
|
33
|
+
end
|
34
|
+
# install dependencies
|
35
|
+
# cd into it and invoke bash
|
36
|
+
cdToLesson
|
37
|
+
end
|
38
|
+
|
39
|
+
def forkCurrentLesson
|
40
|
+
puts "Forking lesson..."
|
41
|
+
github = CommitLive::Github.new()
|
42
|
+
begin
|
43
|
+
Timeout::timeout(15) do
|
44
|
+
lessonRepo = lesson.getAttr('github_repo')
|
45
|
+
forkedRepo = github.client.fork(lessonRepo)
|
46
|
+
end
|
47
|
+
rescue Octokit::Error => err
|
48
|
+
puts "Error while forking!"
|
49
|
+
puts err
|
50
|
+
exit
|
51
|
+
rescue Timeout::Error
|
52
|
+
puts "Please check your internet connection."
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def cloneCurrentLesson
|
58
|
+
puts "Cloning lesson..."
|
59
|
+
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
|
72
|
+
end
|
73
|
+
|
74
|
+
def change_grp_owner
|
75
|
+
results = system("chgrp -R ubuntu #{rootDir}/#{lessonName}")
|
76
|
+
if results
|
77
|
+
puts "..."
|
78
|
+
else
|
79
|
+
puts "Couldn't change group ownership"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def cdToLesson
|
84
|
+
puts "Opening lesson..."
|
85
|
+
Dir.chdir("#{rootDir}/#{lessonName}")
|
86
|
+
puts "Done."
|
87
|
+
exec("#{ENV['SHELL']} -l")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CommitLive
|
2
|
+
module Puzzle
|
3
|
+
class Parser
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(name)
|
7
|
+
@name = name
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse!
|
11
|
+
if name.chars.include?(' ')
|
12
|
+
slugify_name!
|
13
|
+
else
|
14
|
+
name.downcase.strip
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def slugify_name!
|
21
|
+
name.downcase.gsub(' ', '-').strip
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'netrc'
|
2
|
+
|
3
|
+
module CommitLive
|
4
|
+
class NetrcInteractor
|
5
|
+
attr_reader :login, :password, :netrc
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
ensure_proper_permissions!
|
9
|
+
end
|
10
|
+
|
11
|
+
def read(machine: 'ga-config')
|
12
|
+
@netrc = Netrc.read
|
13
|
+
@login, @password = netrc[machine]
|
14
|
+
end
|
15
|
+
|
16
|
+
def write(machine: 'ga-config', new_login:, new_password:)
|
17
|
+
netrc[machine] = new_login, new_password
|
18
|
+
netrc.save
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete!(machine:)
|
22
|
+
@netrc = Netrc.read
|
23
|
+
|
24
|
+
netrc.delete(machine)
|
25
|
+
netrc.save
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def ensure_proper_permissions!
|
31
|
+
system('chmod 0600 ~/.netrc &>/dev/null')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module CommitLive
|
2
|
+
class OptionsSanitizer
|
3
|
+
attr_reader :args
|
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
|
+
]
|
17
|
+
|
18
|
+
def initialize(args)
|
19
|
+
@args = args
|
20
|
+
end
|
21
|
+
|
22
|
+
def sanitize!
|
23
|
+
sanitizeTestArgs!
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def sanitizeTestArgs!
|
29
|
+
if missingOrUnknownArgs?
|
30
|
+
exitWithCannotUnderstand
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Arg check methods
|
35
|
+
def missingOrUnknownArgs?
|
36
|
+
args.empty? || !KNOWN_COMMANDS.include?(args[0])
|
37
|
+
end
|
38
|
+
|
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
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'commit-live/tests/strategies/python-test'
|
3
|
+
|
4
|
+
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
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'commit-live/tests/strategy'
|
2
|
+
|
3
|
+
module CommitLive
|
4
|
+
module Strategies
|
5
|
+
class PythonUnittest < CommitLive::Strategy
|
6
|
+
|
7
|
+
def detect
|
8
|
+
files.any? {|f| f.match(/.*.py$/) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def files
|
12
|
+
@files ||= Dir.entries('.')
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
system("nosetests")
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "commit-live/api"
|
2
|
+
require "commit-live/netrc-interactor"
|
3
|
+
require 'json'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module CommitLive
|
7
|
+
class User
|
8
|
+
attr_reader :netrc
|
9
|
+
|
10
|
+
DEFAULT_EDITOR = 'atom'
|
11
|
+
|
12
|
+
def initialize()
|
13
|
+
@netrc = CommitLive::NetrcInteractor.new()
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate(token)
|
17
|
+
puts "Authenticating..."
|
18
|
+
begin
|
19
|
+
Timeout::timeout(15) do
|
20
|
+
response = CommitLive::API.new().get('/bins/c4vbn')
|
21
|
+
if response.status == 200
|
22
|
+
# Save valid user details in netrc
|
23
|
+
user = JSON.parse(response.body)
|
24
|
+
login, password = netrc.read
|
25
|
+
if login.nil? || password.nil?
|
26
|
+
save(user, token)
|
27
|
+
else
|
28
|
+
username = user.fetch('username')
|
29
|
+
welcome(username)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
case response.status
|
33
|
+
when 401
|
34
|
+
puts "It seems your OAuth token is incorrect. Please retry with correct token."
|
35
|
+
exit 1
|
36
|
+
else
|
37
|
+
puts "Something went wrong. Please try again."
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
rescue Timeout::Error
|
43
|
+
puts "Please check your internet connection."
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def save(userDetails, token)
|
49
|
+
username = userDetails.fetch('username')
|
50
|
+
github_uid = userDetails.fetch('github_uid')
|
51
|
+
netrc.write(new_login: 'greyatom', new_password: token)
|
52
|
+
netrc.write(machine: 'ga-extra', new_login: username, new_password: github_uid)
|
53
|
+
welcome(username)
|
54
|
+
end
|
55
|
+
|
56
|
+
def setDefaultWorkspace
|
57
|
+
workspaceDir = File.expand_path('~/Workspace/code')
|
58
|
+
configPath = File.expand_path('~/.ga-config')
|
59
|
+
|
60
|
+
FileUtils.mkdir_p(workspaceDir)
|
61
|
+
FileUtils.touch(configPath)
|
62
|
+
|
63
|
+
data = YAML.dump({ workspace: workspaceDir, editor: DEFAULT_EDITOR })
|
64
|
+
|
65
|
+
File.write(configPath, data)
|
66
|
+
end
|
67
|
+
|
68
|
+
def confirmAndReset
|
69
|
+
if confirmReset?
|
70
|
+
netrc.delete!(machine: 'ga-config')
|
71
|
+
netrc.delete!(machine: 'ga-extra')
|
72
|
+
puts "Sorry to see you go!"
|
73
|
+
else
|
74
|
+
puts "Thanks for being there with us!"
|
75
|
+
end
|
76
|
+
|
77
|
+
exit
|
78
|
+
end
|
79
|
+
|
80
|
+
def confirmReset?
|
81
|
+
puts "This will remove your existing login configuration and reset.\n"
|
82
|
+
print "Are you sure you want to do this? [yN]: "
|
83
|
+
|
84
|
+
response = STDIN.gets.chomp.downcase
|
85
|
+
|
86
|
+
!!(response == 'yes' || response == 'y')
|
87
|
+
end
|
88
|
+
|
89
|
+
def welcome(username)
|
90
|
+
puts "Welcome, #{username}!"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: commit-live-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- greyatom
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.19'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.19.1
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0.19'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.19.1
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: netrc
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0.11'
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 0.11.0
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0.11'
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 0.11.0
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: octokit
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '4.0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '4.0'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: json
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '2.0'
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 2.0.2
|
119
|
+
type: :runtime
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '2.0'
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: 2.0.2
|
129
|
+
- !ruby/object:Gem::Dependency
|
130
|
+
name: git
|
131
|
+
requirement: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - "~>"
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '1.3'
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.3.0
|
139
|
+
type: :runtime
|
140
|
+
prerelease: false
|
141
|
+
version_requirements: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '1.3'
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: 1.3.0
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: faraday
|
151
|
+
requirement: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - "~>"
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0.9'
|
156
|
+
type: :runtime
|
157
|
+
prerelease: false
|
158
|
+
version_requirements: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - "~>"
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0.9'
|
163
|
+
description:
|
164
|
+
email:
|
165
|
+
- greyatomedutech@gmail.com
|
166
|
+
executables:
|
167
|
+
- clive
|
168
|
+
extensions: []
|
169
|
+
extra_rdoc_files: []
|
170
|
+
files:
|
171
|
+
- README.md
|
172
|
+
- bin/clive
|
173
|
+
- lib/commit-live.rb
|
174
|
+
- lib/commit-live/api.rb
|
175
|
+
- lib/commit-live/cli.rb
|
176
|
+
- lib/commit-live/github.rb
|
177
|
+
- lib/commit-live/lesson/current.rb
|
178
|
+
- lib/commit-live/lesson/git-helper.rb
|
179
|
+
- lib/commit-live/lesson/open.rb
|
180
|
+
- lib/commit-live/lesson/parser.rb
|
181
|
+
- lib/commit-live/lesson/submit.rb
|
182
|
+
- lib/commit-live/netrc-interactor.rb
|
183
|
+
- lib/commit-live/options-sanitizer.rb
|
184
|
+
- lib/commit-live/tests/runner.rb
|
185
|
+
- lib/commit-live/tests/strategies/python-test.rb
|
186
|
+
- lib/commit-live/tests/strategy.rb
|
187
|
+
- lib/commit-live/user.rb
|
188
|
+
- lib/commit-live/version.rb
|
189
|
+
homepage: https://github.com/greyatom-edu-tech/commit-live-cli
|
190
|
+
licenses:
|
191
|
+
- MIT
|
192
|
+
metadata: {}
|
193
|
+
post_install_message:
|
194
|
+
rdoc_options: []
|
195
|
+
require_paths:
|
196
|
+
- lib
|
197
|
+
- bin
|
198
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: 2.1.1
|
203
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
requirements: []
|
209
|
+
rubyforge_project:
|
210
|
+
rubygems_version: 2.6.11
|
211
|
+
signing_key:
|
212
|
+
specification_version: 4
|
213
|
+
summary: Commit Live command line interface.
|
214
|
+
test_files: []
|