git-ready 0.8.11 → 0.8.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/git-ready.gemspec +4 -2
- data/lib/git-ready/interactive_setup.rb +8 -85
- data/lib/git-ready/interactive_setup/github_access_token.rb +82 -0
- data/lib/git-ready/interactive_setup/workspace.rb +19 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20909dc24b57e356ffe93f86051050354ef4470d
|
4
|
+
data.tar.gz: 0acbc7fe13e51057b80cc322d4e280f1c9ad45e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a46de39cc98533e059c8b54486599392ca06a14e06ffa36a5c992e80adc1273b2cbbb77a080225f513f1f664211396c155963490e7f11ef220709c416a4bc6a5
|
7
|
+
data.tar.gz: 2176c3cd298677411f3c79e21a199f711513e708e79dadd26809a0b8e1b62b8921aaa7583ab15e36b96602a66810cd2673a74c1e5003c9111d8b8989c5f7a5e3
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.12
|
data/git-ready.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: git-ready 0.8.
|
5
|
+
# stub: git-ready 0.8.12 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "git-ready"
|
9
|
-
s.version = "0.8.
|
9
|
+
s.version = "0.8.12"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
@@ -34,6 +34,8 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/git-ready.rb",
|
35
35
|
"lib/git-ready/github.rb",
|
36
36
|
"lib/git-ready/interactive_setup.rb",
|
37
|
+
"lib/git-ready/interactive_setup/github_access_token.rb",
|
38
|
+
"lib/git-ready/interactive_setup/workspace.rb",
|
37
39
|
"lib/git-ready/settings.rb",
|
38
40
|
"lib/git-ready/workspace.rb",
|
39
41
|
"spec/git-ready_spec.rb",
|
@@ -1,23 +1,25 @@
|
|
1
1
|
require 'contracts'
|
2
|
-
require 'highline/import'
|
3
|
-
require 'octokit'
|
4
2
|
require 'terminal-announce'
|
5
3
|
require 'yaml'
|
6
4
|
|
5
|
+
require_relative 'interactive_setup/workspace'
|
6
|
+
require_relative 'interactive_setup/github_access_token'
|
7
|
+
|
7
8
|
module InteractiveSetup
|
8
9
|
include Contracts
|
9
10
|
|
10
|
-
Contract
|
11
|
+
Contract None => Any
|
11
12
|
def self.start
|
12
13
|
Announce.info 'Entering Interactive Setup (^c to exit)'
|
13
14
|
settings = {}
|
14
15
|
settings['workspace'] = Workspace.setup
|
15
16
|
settings['github_access_token'] = GitHubAccessToken.setup
|
16
|
-
save settings if
|
17
|
+
save settings if valid? settings
|
17
18
|
exit
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
+
Contract Hash => Bool
|
22
|
+
def self.valid?(settings)
|
21
23
|
if settings.value? nil
|
22
24
|
Announce.failure 'Settings are not valid.'
|
23
25
|
Announce.info "Settings were #{settings}"
|
@@ -27,90 +29,11 @@ module InteractiveSetup
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
32
|
+
Contract Hash => Any
|
30
33
|
def self.save(settings)
|
31
34
|
config_path = File.expand_path '~/.config'
|
32
35
|
Dir.mkdir config_path unless Dir.exist? config_path
|
33
36
|
File.write "#{config_path}/git-ready.yaml", YAML.dump(settings)
|
34
37
|
Announce.success "Configuration saved to #{config_path}"
|
35
38
|
end
|
36
|
-
|
37
|
-
module Workspace
|
38
|
-
def self.setup
|
39
|
-
path = ask 'Enter the path to your workspace.'
|
40
|
-
actual_path = File.expand_path path
|
41
|
-
Announce.warning "No path given, assuming #{actual_path}" if path.empty?
|
42
|
-
if Dir.exist? actual_path
|
43
|
-
actual_path
|
44
|
-
else
|
45
|
-
Announce.failure 'Directory does not exist.'
|
46
|
-
setup
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
module GitHubAccessToken
|
52
|
-
def self.setup
|
53
|
-
Announce.info 'If you leave this blank, git-ready will do most of the work for you. As a fallback, you can generate your own at https://github.com/settings/tokens/new'
|
54
|
-
token = ask 'Enter your GitHub Personal Access Token:', String
|
55
|
-
generated = guided_generation if token.empty?
|
56
|
-
token = generated[:token] if generated
|
57
|
-
token_works?(token) ? token : setup
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.guided_generation
|
61
|
-
login = ask_login
|
62
|
-
password = ask_password
|
63
|
-
generate login, password
|
64
|
-
rescue Octokit::OneTimePasswordRequired
|
65
|
-
Announce.info 'Your account has 2-Factor Authentication enabled. Awesome!'
|
66
|
-
headers = { 'X-GitHub-OTP' => ask('Enter a valid 2-Factor Auth Token') }
|
67
|
-
generate login, password, headers
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.ask_login
|
71
|
-
login = ask('Enter your GitHub login:')
|
72
|
-
login.empty? ? ask_login : login
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.ask_password
|
76
|
-
password = ask('Enter your GitHub password:') { |c| c.echo = '*' }
|
77
|
-
password.empty? ? ask_password : password
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.generate(login, password, headers = {}, first_attempt = true)
|
81
|
-
github = Octokit::Client.new login: login, password: password
|
82
|
-
github.create_authorization(note: 'git-ready',
|
83
|
-
scopes: ['repo'],
|
84
|
-
headers: headers)
|
85
|
-
rescue Octokit::Unauthorized
|
86
|
-
Announce.failure 'Invalid Credentials'
|
87
|
-
rescue Octokit::UnprocessableEntity
|
88
|
-
if first_attempt
|
89
|
-
Announce.warning 'Found an old token. Replacing it.'
|
90
|
-
delete_existing_authorization github, headers
|
91
|
-
generate login, password, headers, false
|
92
|
-
else
|
93
|
-
Announce.failure "It looked like you had already issued a token, but deleting it didn't help. You're on your own at this point. You should should use the link at the start to generate a token manually."
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def self.delete_existing_authorization(session, headers)
|
98
|
-
existing = old_auth_tokens('git-ready', session, headers).first[:id]
|
99
|
-
session.delete_authorization existing, headers: headers
|
100
|
-
end
|
101
|
-
|
102
|
-
def self.old_auth_tokens(note, session, headers)
|
103
|
-
session.authorizations(headers: headers).select do |auth|
|
104
|
-
auth[:note] == note
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def self.token_works?(token)
|
109
|
-
github = Octokit::Client.new access_token: token
|
110
|
-
true if github.repos
|
111
|
-
rescue Octokit::Unauthorized
|
112
|
-
Announce.failure 'Invalid Credentials'
|
113
|
-
false
|
114
|
-
end
|
115
|
-
end
|
116
39
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require 'highline/import'
|
3
|
+
require 'octokit'
|
4
|
+
require 'terminal-announce'
|
5
|
+
|
6
|
+
module InteractiveSetup
|
7
|
+
module GitHubAccessToken
|
8
|
+
include Contracts
|
9
|
+
|
10
|
+
Contract None => String
|
11
|
+
def self.setup
|
12
|
+
Announce.info 'If you leave this blank, git-ready will do most of the work for you. As a fallback, you can generate your own at https://github.com/settings/tokens/new'
|
13
|
+
token = ask 'Enter your GitHub Personal Access Token:', String
|
14
|
+
generated = guided_generation if token.empty?
|
15
|
+
token = generated[:token] if generated
|
16
|
+
token_works?(token) ? token : setup
|
17
|
+
end
|
18
|
+
|
19
|
+
Contract None => Hash
|
20
|
+
def self.guided_generation
|
21
|
+
login = ask_login
|
22
|
+
password = ask_password
|
23
|
+
generate login, password
|
24
|
+
rescue Octokit::OneTimePasswordRequired
|
25
|
+
Announce.info 'Your account has 2-Factor Authentication enabled. Awesome!'
|
26
|
+
headers = { 'X-GitHub-OTP' => ask('Enter a valid 2-Factor Auth Token') }
|
27
|
+
generate login, password, headers
|
28
|
+
end
|
29
|
+
|
30
|
+
Contract None => String
|
31
|
+
def self.ask_login
|
32
|
+
login = ask('Enter your GitHub login:')
|
33
|
+
login.empty? ? ask_login : login
|
34
|
+
end
|
35
|
+
|
36
|
+
Contract None => String
|
37
|
+
def self.ask_password
|
38
|
+
password = ask('Enter your GitHub password:') { |c| c.echo = '*' }
|
39
|
+
password.empty? ? ask_password : password
|
40
|
+
end
|
41
|
+
|
42
|
+
Contract String, String, Hash, Bool => Hash
|
43
|
+
def self.generate(login, password, headers = {}, first_attempt = true)
|
44
|
+
github = Octokit::Client.new login: login, password: password
|
45
|
+
github.create_authorization(note: 'git-ready',
|
46
|
+
scopes: ['repo'],
|
47
|
+
headers: headers)
|
48
|
+
rescue Octokit::Unauthorized
|
49
|
+
Announce.failure 'Invalid Credentials'
|
50
|
+
rescue Octokit::UnprocessableEntity
|
51
|
+
if first_attempt
|
52
|
+
Announce.warning 'Found an old token. Replacing it.'
|
53
|
+
delete_existing_authorization github, headers
|
54
|
+
generate login, password, headers, false
|
55
|
+
else
|
56
|
+
Announce.failure "It looked like you had already issued a token, but deleting it didn't help. You're on your own at this point. You should should use the link at the start to generate a token manually."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
Contract Octokit::Client, Hash => Any
|
61
|
+
def self.delete_existing_authorization(session, headers)
|
62
|
+
existing = old_auth_tokens('git-ready', session, headers).first[:id]
|
63
|
+
session.delete_authorization existing, headers: headers
|
64
|
+
end
|
65
|
+
|
66
|
+
Contract String Octokit::Client, Hash => Any
|
67
|
+
def self.old_auth_tokens(note, session, headers)
|
68
|
+
session.authorizations(headers: headers).select do |auth|
|
69
|
+
auth[:note] == note
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
Contract String => Bool
|
74
|
+
def self.token_works?(token)
|
75
|
+
github = Octokit::Client.new access_token: token
|
76
|
+
true if github.repos
|
77
|
+
rescue Octokit::Unauthorized
|
78
|
+
Announce.failure 'Invalid Credentials'
|
79
|
+
false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'contracts'
|
2
|
+
require 'highline/import'
|
3
|
+
require 'terminal-announce'
|
4
|
+
|
5
|
+
module InteractiveSetup
|
6
|
+
module Workspace
|
7
|
+
def self.setup
|
8
|
+
path = ask 'Enter the path to your workspace.'
|
9
|
+
actual_path = File.expand_path path
|
10
|
+
Announce.warning "No path given, assuming #{actual_path}" if path.empty?
|
11
|
+
if Dir.exist? actual_path
|
12
|
+
actual_path
|
13
|
+
else
|
14
|
+
Announce.failure 'Directory does not exist.'
|
15
|
+
setup
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-ready
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Olstrom
|
@@ -244,6 +244,8 @@ files:
|
|
244
244
|
- lib/git-ready.rb
|
245
245
|
- lib/git-ready/github.rb
|
246
246
|
- lib/git-ready/interactive_setup.rb
|
247
|
+
- lib/git-ready/interactive_setup/github_access_token.rb
|
248
|
+
- lib/git-ready/interactive_setup/workspace.rb
|
247
249
|
- lib/git-ready/settings.rb
|
248
250
|
- lib/git-ready/workspace.rb
|
249
251
|
- spec/git-ready_spec.rb
|