greyatom-cli 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 +7 -0
- data/README.md +41 -0
- data/bin/greyatom +25 -0
- data/lib/greyatom.rb +7 -0
- data/lib/greyatom/api.rb +66 -0
- data/lib/greyatom/cli.rb +60 -0
- data/lib/greyatom/github.rb +16 -0
- data/lib/greyatom/lesson/current.rb +35 -0
- data/lib/greyatom/lesson/git-helper.rb +122 -0
- data/lib/greyatom/lesson/open.rb +79 -0
- data/lib/greyatom/lesson/submit.rb +13 -0
- data/lib/greyatom/netrc-interactor.rb +34 -0
- data/lib/greyatom/options-sanitizer.rb +44 -0
- data/lib/greyatom/tests/runner.rb +34 -0
- data/lib/greyatom/tests/strategies/python-test.rb +21 -0
- data/lib/greyatom/tests/strategy.rb +15 -0
- data/lib/greyatom/user.rb +93 -0
- data/lib/greyatom/version.rb +5 -0
- metadata +189 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 443376289e85b20108e0a8232d10343ee52a532a
|
4
|
+
data.tar.gz: a9e4b902bc50e6219fa2b4e517fd4e315029bd88
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3ce12f995c9c07a3a81e2cf17cf217d66a13738443359227701d86c38efd1345b477d91d62f33cfbb8369b28a91bfc7adfcb9013144eb6b1d34530fab9496e2
|
7
|
+
data.tar.gz: ba1a38c9aaffe034d5d0e7472db937d1e4db0a6a0f5694e0d5d44a16aa479d8682d9287894afc78be97df8a70bfa47c3b6fe3e409357b56e0ed79a4304009750
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Greyatom::Cli
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/greyatom/cli`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'greyatom-cli'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install greyatom-cli
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/greyatom-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.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/bin/greyatom
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'greyatom'
|
4
|
+
|
5
|
+
if ['-v', '--version'].include?(ARGV.first)
|
6
|
+
puts Greyatom::VERSION
|
7
|
+
exit
|
8
|
+
end
|
9
|
+
|
10
|
+
Greyatom::OptionsSanitizer.new( ARGV ).sanitize!
|
11
|
+
|
12
|
+
COMMANDS_THAT_REQUIRE_OAUTH = [
|
13
|
+
'submit',
|
14
|
+
'open'
|
15
|
+
]
|
16
|
+
|
17
|
+
netrc = Greyatom::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 `learn setup` get started.'
|
22
|
+
exit
|
23
|
+
end
|
24
|
+
|
25
|
+
Greyatom::CLI.start( ARGV )
|
data/lib/greyatom.rb
ADDED
data/lib/greyatom/api.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
module Greyatom
|
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
|
data/lib/greyatom/cli.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'greyatom/user'
|
2
|
+
require 'greyatom/netrc-interactor'
|
3
|
+
require 'greyatom/tests/runner'
|
4
|
+
require 'greyatom/lesson/submit'
|
5
|
+
require 'greyatom/lesson/open'
|
6
|
+
require 'thor'
|
7
|
+
|
8
|
+
module Greyatom
|
9
|
+
class CLI < Thor
|
10
|
+
desc "hello", "This will greet you"
|
11
|
+
def hello()
|
12
|
+
puts "Hello World!"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "setup", "This will ask for token"
|
16
|
+
def setup(retries: 5)
|
17
|
+
# Check if token already present
|
18
|
+
login, password = Greyatom::NetrcInteractor.new().read
|
19
|
+
if login.nil? || password.nil?
|
20
|
+
print 'Enter your github token here and press [ENTER]: '
|
21
|
+
password = STDIN.gets.chomp
|
22
|
+
if password.empty?
|
23
|
+
puts "No token provided."
|
24
|
+
exit
|
25
|
+
end
|
26
|
+
end
|
27
|
+
# Check if token is valid
|
28
|
+
user = Greyatom::User.new()
|
29
|
+
user.validate(password)
|
30
|
+
user.setDefaultWorkspace
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "reset", "This will forget you"
|
34
|
+
def reset()
|
35
|
+
Greyatom::User.new().confirmAndReset
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "open", "This will fork new work"
|
39
|
+
def open()
|
40
|
+
# Fork and Clone User's current lesson
|
41
|
+
Greyatom::Open.new().openALesson
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "submit", "This will submit your work"
|
45
|
+
def submit()
|
46
|
+
Greyatom::Submit.new().run
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "test", "This will test you"
|
50
|
+
def test()
|
51
|
+
puts 'Testing...'
|
52
|
+
Greyatom::Test.new().run
|
53
|
+
end
|
54
|
+
|
55
|
+
desc 'version, -v, --version', 'Display the current version of the Learn gem'
|
56
|
+
def version
|
57
|
+
puts Greyatom::VERSION
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "greyatom/netrc-interactor"
|
2
|
+
require 'octokit'
|
3
|
+
|
4
|
+
module Greyatom
|
5
|
+
class Github
|
6
|
+
attr_accessor :client
|
7
|
+
def initialize()
|
8
|
+
netrc = Greyatom::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 "greyatom/api"
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Greyatom
|
5
|
+
class Current
|
6
|
+
attr_accessor :lesson
|
7
|
+
|
8
|
+
def getCurrentLesson
|
9
|
+
begin
|
10
|
+
Timeout::timeout(15) do
|
11
|
+
response = Greyatom::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 "greyatom/lesson/current"
|
2
|
+
require "greyatom/netrc-interactor"
|
3
|
+
require "greyatom/github"
|
4
|
+
|
5
|
+
module Greyatom
|
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 = Greyatom::NetrcInteractor.new()
|
19
|
+
@currentLesson = Greyatom::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 = Greyatom::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,79 @@
|
|
1
|
+
require "greyatom/lesson/current"
|
2
|
+
require "greyatom/netrc-interactor"
|
3
|
+
require "greyatom/api"
|
4
|
+
require "greyatom/github"
|
5
|
+
require 'octokit'
|
6
|
+
require 'git'
|
7
|
+
|
8
|
+
module Greyatom
|
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 = Greyatom::Current.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def openALesson
|
22
|
+
# get currently active lesson
|
23
|
+
puts "Getting current lesson..."
|
24
|
+
lesson.getCurrentLesson
|
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
|
+
end
|
32
|
+
# install dependencies
|
33
|
+
# cd into it and invoke bash
|
34
|
+
cdToLesson
|
35
|
+
end
|
36
|
+
|
37
|
+
def forkCurrentLesson
|
38
|
+
puts "Forking lesson..."
|
39
|
+
github = Greyatom::Github.new()
|
40
|
+
begin
|
41
|
+
Timeout::timeout(15) do
|
42
|
+
lessonRepo = lesson.getAttr('github_repo')
|
43
|
+
forkedRepo = github.client.fork(lessonRepo)
|
44
|
+
end
|
45
|
+
rescue Octokit::Error => err
|
46
|
+
puts "Error while forking!"
|
47
|
+
puts err
|
48
|
+
exit
|
49
|
+
rescue Timeout::Error
|
50
|
+
puts "Please check your internet connection."
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def cloneCurrentLesson
|
56
|
+
puts "Cloning lesson..."
|
57
|
+
begin
|
58
|
+
Timeout::timeout(15) do
|
59
|
+
cloneUrl = lesson.getAttr('forked_repo')
|
60
|
+
Git.clone("git@github.com:#{cloneUrl}.git", lessonName, path: rootDir)
|
61
|
+
end
|
62
|
+
rescue Git::GitExecuteError => err
|
63
|
+
puts "Error while cloning!"
|
64
|
+
puts err
|
65
|
+
exit
|
66
|
+
rescue Timeout::Error
|
67
|
+
puts "Cannot clone this lesson right now. Please try again."
|
68
|
+
exit
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def cdToLesson
|
73
|
+
puts "Opening lesson..."
|
74
|
+
Dir.chdir("#{rootDir}/#{lessonName}")
|
75
|
+
puts "Done."
|
76
|
+
exec("#{ENV['SHELL']} -l")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'greyatom/lesson/git-helper'
|
2
|
+
require 'octokit'
|
3
|
+
|
4
|
+
module Greyatom
|
5
|
+
class Submit
|
6
|
+
def run
|
7
|
+
puts 'submit run'
|
8
|
+
Greyatom::Submit::GitHelper.new().commitAndPush
|
9
|
+
# Just to give GitHub a second to register the repo changes
|
10
|
+
sleep(1)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'netrc'
|
2
|
+
|
3
|
+
module Greyatom
|
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 Greyatom
|
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 `learn help` for help."
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'greyatom/tests/strategies/python-test'
|
3
|
+
|
4
|
+
module Greyatom
|
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
|
+
Greyatom::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 'greyatom/tests/strategy'
|
2
|
+
|
3
|
+
module Greyatom
|
4
|
+
module Strategies
|
5
|
+
class PythonUnittest < Greyatom::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 "greyatom/api"
|
2
|
+
require "greyatom/netrc-interactor"
|
3
|
+
require 'json'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
module Greyatom
|
7
|
+
class User
|
8
|
+
attr_reader :netrc
|
9
|
+
|
10
|
+
DEFAULT_EDITOR = 'atom'
|
11
|
+
|
12
|
+
def initialize()
|
13
|
+
@netrc = Greyatom::NetrcInteractor.new()
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate(token)
|
17
|
+
puts "Authenticating..."
|
18
|
+
begin
|
19
|
+
Timeout::timeout(15) do
|
20
|
+
response = Greyatom::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,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: greyatom-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- greyatom-edu-tech
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-19 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'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: netrc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: octokit
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: json
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: git
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: faraday
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.9'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.9'
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- greyatomedutech@gmail.com
|
142
|
+
executables:
|
143
|
+
- greyatom
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- README.md
|
148
|
+
- bin/greyatom
|
149
|
+
- lib/greyatom.rb
|
150
|
+
- lib/greyatom/api.rb
|
151
|
+
- lib/greyatom/cli.rb
|
152
|
+
- lib/greyatom/github.rb
|
153
|
+
- lib/greyatom/lesson/current.rb
|
154
|
+
- lib/greyatom/lesson/git-helper.rb
|
155
|
+
- lib/greyatom/lesson/open.rb
|
156
|
+
- lib/greyatom/lesson/submit.rb
|
157
|
+
- lib/greyatom/netrc-interactor.rb
|
158
|
+
- lib/greyatom/options-sanitizer.rb
|
159
|
+
- lib/greyatom/tests/runner.rb
|
160
|
+
- lib/greyatom/tests/strategies/python-test.rb
|
161
|
+
- lib/greyatom/tests/strategy.rb
|
162
|
+
- lib/greyatom/user.rb
|
163
|
+
- lib/greyatom/version.rb
|
164
|
+
homepage: https://github.com/greyatom-edu-tech/greyatom-cli
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
metadata: {}
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
require_paths:
|
171
|
+
- lib
|
172
|
+
- bin
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
requirements: []
|
184
|
+
rubyforge_project:
|
185
|
+
rubygems_version: 2.4.8
|
186
|
+
signing_key:
|
187
|
+
specification_version: 4
|
188
|
+
summary: Greyatom's command line interface.
|
189
|
+
test_files: []
|