hubmaster 0.0.08 → 0.0.09

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,12 +6,17 @@ Hubmaster is a rubygem that allows GitHub API interaction in Terminal. The curre
6
6
 
7
7
  * [Installation](#install)
8
8
  * [Overview](#overview)
9
+ * [Authentication Documentation](#authdoc)
10
+ * [Basic Authentication](#basicauth)
11
+ * [Stored Basic Authentication](#sbasicauth)
12
+ * [OAuth 2.0](#oauth)
13
+ * [Resetting Login](#reset)
9
14
  * [Repository Documentation](#repos)
10
- * [List](#reposList)
11
- * [Get](#reposGet)
12
- * [Create](#reposCreate)
13
- * [Edit](#reposEdit)
14
- * [Delete](#reposDelete)
15
+ * [List](#reposList)
16
+ * [Get](#reposGet)
17
+ * [Create](#reposCreate)
18
+ * [Edit](#reposEdit)
19
+ * [Delete](#reposDelete)
15
20
 
16
21
  <a name="install"/>
17
22
  ## Installation
@@ -34,9 +39,58 @@ To use as a command line tool, run:
34
39
  Hubmaster is a library written in ruby that makes interfacing with github a snap! In adition to being a library, hubmaster also includes an executable
35
40
  command line tool that allows github web operations to be carried out in terminal. The rest of the document details how hubmaster should be used, but there are a few things to note beforehand.
36
41
 
37
- 1. The general form for executing commands is `hub repos --modifier [params]`. All parameters that include spaces must be encased in quotes.
42
+ 1. The general form for executing commands is `hub [class] --modifier [params]`. All parameters that include spaces must be encased in quotes.
38
43
 
39
- 2. **BEWARE:** For the purposes of this document, when words are surrounded by brackets, the indicated value should be placed there **without brackets**.
44
+ 2. Any parameter that you ommit, you will be prompted for later. This can be helpful when dealing with multi-word parameters or absent-mindedness.
45
+
46
+ **BEWARE:** For the purposes of this document, when words are surrounded by brackets, the indicated value should be placed there **without brackets**.
47
+ <a name="authdoc"/>
48
+ ## Authentication Documentation
49
+
50
+ Hubmaster allows you to connect in several different ways to your Github account. You can use basic auth, stored bashic auth, or OAuth 2.0.
51
+ We do suggest, however, that you use OAuth 2.0 over stored basic authentication because it is more secure.
52
+
53
+ <a name="basicauth"/>
54
+ ### Basic Authentication
55
+ ***
56
+
57
+ If you only want to use basic authentication without storing information for later use, you dont have to do anything. If you just execute
58
+ the desired command, you will be automatically prompted for your login information.
59
+
60
+ <a name="sbasicauth"/>
61
+ ### Stored Basic Authentication
62
+ ***
63
+
64
+ If you want to use basic authentication but store your login information, run the following:
65
+
66
+ hub login --new -basic [optional username]
67
+
68
+ *If you don't include your username as a parameter, you will be prompted for it later*
69
+
70
+ **Note:** this method of storing your information makes you vulnerable should someone gain access to your computer.
71
+ Your username and password will both be saved in a hidden file. Your password will be sent through a cipher first,
72
+ but the cipher is **easily** crackable. The prefered method for saving login data is through OAuth.
73
+
74
+ <a name="oauth"/>
75
+ ### OAuth 2.0
76
+ ***
77
+
78
+ To add a new login using OAuth 2.0, just run:
79
+
80
+ hub login --new -oauth [optional username]
81
+ *If you don't include your username as a parameter, you will be prompted for it later*
82
+
83
+ OAuth is the most secure method of saving your login for later use because it doesnt actually save your credentials.
84
+ Instead, hubmaster generates and saves a OAuth token which is passed to Github and grants authorization to the program.
85
+ The privelages associated with this token can be revoked at any time from github.com (or from hubmaster in the future).
86
+
87
+ <a name="reset">
88
+ ### Resetting Login
89
+ ***
90
+
91
+ If you ever accidentally input your login information incorrectly or change your password (basic auth), you can allways reset your login by running the following:
92
+
93
+ hub login --reset -[basic or oauth] [optional username]
40
94
 
41
95
  <a name="repos"/>
42
96
  ## Repository Documentation
@@ -46,48 +100,138 @@ There are five main functions that will be described in further detail: List, Ge
46
100
 
47
101
  <a name="reposList"/>
48
102
  ### List
103
+ ***
104
+
105
+ The list function provides an easy way to see both your repositories, or the repositories of someone you know.
49
106
 
50
- To list all repositories under your account:
107
+ To list all of the repositories associated with your account, you would execute:
51
108
 
52
109
  hub repos --list
53
110
 
54
111
 
55
- To list all repositories under someone elses account:
112
+ To list all of the repositories linked with someone elses account, you would execute:
56
113
 
57
114
  hub repos --list [username]
58
115
 
116
+ **Remember:** In place of "[username]" you should place the username of the person whos repositories you would like to see.
117
+
59
118
  <a name="reposGet">
60
- ### Get
119
+ ### Get
120
+ ***
121
+
122
+ The "get" function carries out operations that refer to a single repository. There are 7 simple modifiers bundled within this function that do the following:
123
+
124
+ 1. [List the contributors of a repository,](#getC)
125
+ 2. [List the languages used in a repository,](#getL)
126
+ 3. [List the teams associated with a repository,](#getT)
127
+ 4. [List the tags of a repository,](#getTags)
128
+ 5. [List the various branches of a repository,](#getBs)
129
+ 6. [Return information on a specific branch, and](#getB)
130
+ 7. [Return information on a specific repository.](#getR)
131
+
132
+ The general form for making get requests is as follows:
133
+
134
+ hub repos --get -operator [user] [repository name] [sometimes branch]
135
+
136
+ If you wish to get information on one of your own repositories, either use your login or "self" for the [user] parameter
137
+
138
+ <a name="getC"/>
139
+ #### Get Contributors
140
+ ***
61
141
 
142
+ To list all of the contributors for a specific repository, execute the following:
143
+
144
+ hub repos --get -contributors [user] [repository name]
145
+
146
+ <a name="getL"/>
147
+ #### Get Languages
148
+ ***
149
+
150
+ To display all of the languages used and how many bits of each were used, the following can be used:
151
+
152
+ hub repos --get -languages [user] [repository name]
153
+
154
+ <a name="getT"/>
155
+ #### Get Teams
156
+ ***
157
+
158
+ To show all of the teams associated with a specific repository, run:
159
+
160
+ hub repos --get -teams [user] [repository name]
161
+
162
+ <a name="getTags"/>
163
+ #### Get Tags
164
+ ***
165
+
166
+ If you want to find all of the tags for a given repository, type:
167
+
168
+ hub repos --get -tags [user] [repository name]
169
+
170
+ <a name="getBs"/>
171
+ #### Get Branches
172
+ ***
173
+
174
+ To list all of branches under a given repository, run:
175
+
176
+ hub repos --get -branches [user] [repository name]
177
+
178
+ <a name="getB"/>
179
+ #### Get Branch
180
+ ***
181
+
182
+ If you want to get information on a specific branch of a repository, use:
183
+
184
+ hub repos --get -branch [user] [repository name] [branch name]
185
+
186
+ <a name="getR"/>
187
+ #### Get Repository
188
+ ***
189
+
190
+ To get information on a specific repository, all you need to do is execute:
191
+
192
+ hub repos --get -repository [user] [repository name]
62
193
 
63
194
  <a name="reposCreate"/>
64
195
  ### Create
196
+ ***
65
197
 
66
- To create a new repository:
198
+ Creating repositories from terminal is both extreemly easy and usefull.
67
199
 
68
- hub repos --create [name] "[description]"
69
- *Additionaly this command can be run with no parameters and you will be prompted for them later.*
200
+ To create a new repository, all you have to do is run:
201
+
202
+ hub repos --create [name] [description]
203
+
204
+ If the description of your repository contains multiple words (usually they do), you have two options:
205
+
206
+ 1. Encase the description in quotes
207
+ 2. Execute the command with no description parameter and you will be prompted for it later.
70
208
 
71
209
  <a name="reposEdit"/>
72
210
  ### Edit
211
+ ***
73
212
 
74
- To edit an existing repository:
213
+ If you wish to edit an existing repository, the general form is as follows:
75
214
 
76
215
  hub repos --edit [name] -option [option dependent variable]
77
216
 
78
- *The edit command takes several parameters and can be kind of confusing. First you specify
79
- the name of the repository you would like to edit, followed by the part you would like to edit.
80
- Currently all that can be edited is the the description, so the '-option' would look like '-description'.
81
- Finally, you can either specify the change now or be prompted for it later.*
217
+ The edit command takes several parameters and can be kind of canfusing, so let me break it down a bit for you:
218
+
219
+ 1. Identify the name of the repository you wish to edit -> [name].
220
+
221
+ 2. Specify an option, or element, that you wish to edit -> -option.
222
+
223
+ 3. Provide the new value for the element that you specified in step two -> [option dependent variable]
82
224
 
83
- **REMEMBER: IF ANY PARAMETERS INCLUDE SPACES, THEY MUST BE ENCASED IN QUOTES**
225
+ *The edit command only allows you to modify the description of a repository at this time. An description specific example of this would look like:
226
+ `hub repos --edit [name] -description [description]`*
84
227
 
85
228
  <a name="reposDelete"/>
86
229
  ### Delete
230
+ ***
87
231
 
88
- To delete an existing repository:
232
+ If you wish to delete an existing repository, all you have to do is:
89
233
 
90
234
  hub repos --delete [name]
91
- *Andy you will be asked to confirm by typing the name of the repository specified.*
92
235
 
236
+ To confirm that you do in fact wish to delete this repository, you will be prompted to enter the name of the repository again.
93
237
 
data/bin/hub CHANGED
@@ -19,8 +19,8 @@ if ARGV.length > 0
19
19
  Github.connect
20
20
 
21
21
  case ARGV[2]
22
- when "-contributers", "-contribs"
23
- Github::Repos.get(ARGV[3], ARGV[4], :contributers)
22
+ when "-contributors", "-contribs"
23
+ Github::Repos.get(ARGV[3], ARGV[4], :contributors)
24
24
  when "-repo", "-repository"
25
25
  Github::Repos.get(ARGV[3], ARGV[4], :repository)
26
26
  when "-langs", "-languages"
@@ -51,9 +51,28 @@ if ARGV.length > 0
51
51
  Github.help
52
52
  when "login"
53
53
  case ARGV[1]
54
+ when "--new"
55
+ if ARGV[2] == "-basic"
56
+ Github::Login.create(:basic) if ARGV[3].nil?
57
+ Github::Login.create(:basic, ARGV[3]) unless ARGV[3].nil?
58
+ elsif ARGV[2] == "-oauth"
59
+ Github::Login.create(:oauth) if ARGV[3].nil?
60
+ Github::Login.create(:oauth, ARGV[3]) unless ARGV[3].nil?
61
+ else
62
+ puts "Unknown modifier for login '#{ARGV[2]}'. Tyle hub help for assistance."
63
+ end
54
64
  when "--reset"
55
- Github.resetLogin
65
+ if ARGV[2] == "-basic"
66
+ Github::Login.create(:basic) if ARGV[3].nil?
67
+ Github::Login.create(:basic, ARGV[3]) unless ARGV[3].nil?
68
+ elsif ARGV[2] == "-oauth"
69
+ Github::Login.create(:oauth) if ARGV[3].nil?
70
+ Github::Login.create(:oauth, ARGV[3]) unless ARGV[3].nil?
71
+ else
72
+ puts "Unknown modifier for login '#{ARGV[2]}'. Tyle hub help for assistance."
73
+ end
56
74
  else
75
+ puts "Unknown Command: Type hub help for usage instructions."
57
76
  end
58
77
  else
59
78
  puts "Unknown Command: Type hub help for usage instructions."
data/hubmaster.gemspec CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Tommy Schaefer"]
6
6
  gem.email = ["me@tommyschaefer.net"]
7
- gem.description = %q{Hubmaster is a tool built in ruby that allows github interactions to be made outside the browser.}
8
- gem.summary = %q{Hubmaster is simple and easy to use. Visit the github page for more details.}
7
+ gem.description = %q{Hubmaster is a tool built in Ruby that allows Github interactions to be made outside the browser.}
8
+ gem.summary = %q{Hubmaster is simple and easy to use. Visit the Github page for more details.}
9
9
  gem.homepage = "https://github.com/tommyschaefer/hubmaster"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
data/lib/hubmaster.rb CHANGED
@@ -10,6 +10,7 @@ require 'uri'
10
10
  require File.expand_path(File.join(File.dirname(__FILE__), "hubmaster", "base.rb"))
11
11
  require File.expand_path(File.join(File.dirname(__FILE__), "hubmaster", "repo.rb"))
12
12
  require File.expand_path(File.join(File.dirname(__FILE__), "hubmaster", "cipher.rb"))
13
+ require File.expand_path(File.join(File.dirname(__FILE__), "hubmaster", "login.rb"))
13
14
 
14
15
  def putLess(array)
15
16
  string = array.join("\n")
@@ -1,30 +1,25 @@
1
1
  module Github
2
2
  def self.connect
3
3
  if File.exists? "#{Dir.home}/.hubmaster"
4
- content = []
5
- File.open("#{Dir.home}/.hubmaster", "rb") do |fileC|
6
- while (line = fileC.gets)
7
- content << line.gsub("\n", "")
8
- end
9
- end
4
+ line1 = File.open("#{Dir.home}/.hubmaster").first.gsub("\n", "")
10
5
 
11
- @user = content[0]
12
- @pass = Github::Cipher.new.decrypt(content[1])
6
+ if line1 == "basic"
7
+ auth = Github::Login.authenticate(:basic)
8
+ @user = auth[0]
9
+ @pass = auth[1]
10
+ elsif line1 == "oauth"
11
+ auth = Github::Login.authenticate(:oauth)
12
+ @user = auth[0]
13
+ @token = auth[1]
14
+ end
13
15
  else
14
- print "Username: "
15
- @user = STDIN.gets.chomp
16
- @pass = ask("Password: ") {|q| q.echo = "*"}
17
- File.open("#{Dir.home}/.hubmaster", "w") {|f| f.write("#{@user}\n#{@pass = Github::Cipher.new.encrypt(@pass)}")}
18
- end
19
-
20
- return nil
21
- end
16
+ puts "No login file was detected. To add one, use hub login --new. Unstored basic auth will be used at this point."
17
+ puts ""
22
18
 
23
- def self.resetLogin
24
- print "Username: "
25
- @user = STDIN.gets.chomp
26
- @pass = ask("Password: ") {|q| q.echo = "*"}
27
- File.open("#{Dir.home}/.hubmaster", "w") {|f| f.write("#{@user}\n#{@pass = Github::Cipher.new.encrypt(@pass)}")}
19
+ auth = Github::Login.basic
20
+ @user = auth[0]
21
+ @pass = auth[1]
22
+ end
28
23
  return nil
29
24
  end
30
25
 
@@ -32,16 +27,34 @@ module Github
32
27
  return @user
33
28
  end
34
29
 
35
- def self.makeGetRequest(path, username = @user, password = @pass, server = "api.github.com")
30
+ def self.makeGetRequest(path, username = @user, password = @pass, token = @token, server = "api.github.com")
31
+ if password.nil?
32
+ http = Net::HTTP.new(server, 443)
33
+ req = Net::HTTP::Get.new("#{path}?access_token=#{token}") if path.include?("?") == false
34
+ req = Net::HTTP::Get.new("#{path}&&access_token=#{token}") if path.include?("?") == true
35
+ http.use_ssl = true
36
+ response = http.request(req)
37
+ return response.body
38
+ else
36
39
  http = Net::HTTP.new(server,443)
37
40
  req = Net::HTTP::Get.new(path)
38
41
  http.use_ssl = true
39
42
  req.basic_auth username, password
40
43
  response = http.request(req)
41
44
  return response.body
45
+ end
42
46
  end
43
47
 
44
- def self.makePostRequest(path, body, username = @user, password = @pass, server = "api.github.com")
48
+ def self.makePostRequest(path, body, username = @user, password = @pass, token = @token, server = "api.github.com")
49
+ if password.nil?
50
+ http = Net::HTTP.new(server,443)
51
+ req = Net::HTTP::Post.new("#{path}?access_token=#{token}") if path.include?("?") == false
52
+ req = Net::HTTP::Post.new("#{path}&&access_token=#{token}") if path.include?("?") == true
53
+ http.use_ssl = true
54
+ req.body = body
55
+ response = http.request(req)
56
+ return response.body
57
+ else
45
58
  http = Net::HTTP.new(server,443)
46
59
  req = Net::HTTP::Post.new(path)
47
60
  http.use_ssl = true
@@ -49,18 +62,37 @@ module Github
49
62
  req.body = body
50
63
  response = http.request(req)
51
64
  return response.body
65
+ end
52
66
  end
53
67
 
54
- def self.makeDeleteRequest(path, username = @user, password = @pass, server = "api.github.com")
68
+ def self.makeDeleteRequest(path, username = @user, password = @pass, token = @token, server = "api.github.com")
69
+ if password.nil?
70
+ http = Net::HTTP.new(server,443)
71
+ req = Net::HTTP::Delete.new("#{path}?access_token=#{token}") if path.include?("?") == false
72
+ req = Net::HTTP::Delete.new("#{path}&&access_token=#{token}") if path.include?("?") == true
73
+ http.use_ssl = true
74
+ response = http.request(req)
75
+ return response.body
76
+ else
55
77
  http = Net::HTTP.new(server,443)
56
78
  req = Net::HTTP::Delete.new(path)
57
79
  http.use_ssl = true
58
80
  req.basic_auth username, password
59
81
  response = http.request(req)
60
82
  return response.body
83
+ end
61
84
  end
62
85
 
63
- def self.makeEditRequest(path, body, username = @user, password = @pass, server = "api.github.com")
86
+ def self.makeEditRequest(path, body, username = @user, password = @pass, token = @token, server = "api.github.com")
87
+ if password.nil?
88
+ http = Net::HTTP.new(server,443)
89
+ req = Net::HTTP::Post.new("#{path}?access_token=#{token}") if path.include?("?") == false
90
+ req = Net::HTTP::Post.new("#{path}&&access_token=#{token}") if path.include?("?") == true
91
+ http.use_ssl = true
92
+ req.body = body
93
+ response = http.request(req)
94
+ return response.body
95
+ else
64
96
  http = Net::HTTP.new(server,443)
65
97
  req = Net::HTTP::Post.new(path)
66
98
  http.use_ssl = true
@@ -68,8 +100,8 @@ module Github
68
100
  req.body = body
69
101
  response = http.request(req)
70
102
  return response.body
103
+ end
71
104
  end
72
-
73
105
  def self.help
74
106
  puts "Hubmaster Help: "
75
107
  end
@@ -0,0 +1,69 @@
1
+ module Github
2
+ class Login
3
+ def self.create(type, username = nil)
4
+ if username.nil?
5
+ print "Username: "
6
+ @user = STDIN.gets.chomp
7
+ else
8
+ @user = username
9
+ end
10
+
11
+ @pass = ask("Password: ") {|q| q.echo = "*"}
12
+
13
+ if type == :basic
14
+ File.open("#{Dir.home}/.hubmaster", "w") {|f| f.write("basic\n#{@user}\n#{@pass = Github::Cipher.new.encrypt(@pass)}")}
15
+ elsif type == :oauth
16
+ jsonHash = {"note" => "Token for hubmaster", "scopes" => ["user", "public_repo", "repo", "repo:status", "delete_repo", "notifications", "gist"]}.to_json
17
+ request = Github.makePostRequest("/authorizations", jsonHash, @user, @pass)
18
+
19
+ response = JSON.parse(request)
20
+
21
+ @token = response["token"]
22
+
23
+ File.open("#{Dir.home}/.hubmaster", "w") {|f| f.write("oauth\n#{@user}\n#{@token}")}
24
+ end
25
+ end
26
+
27
+ def self.authenticate(type)
28
+ if !File.exists?("#{Dir.home}/.hubmaster")
29
+ puts "A login file was not detected. Please use 'hub login --new' to create a new one"
30
+ puts ""
31
+ else
32
+ if type == :basic
33
+ content = []
34
+
35
+ File.open("#{Dir.home}/.hubmaster", "rb") do |fileC|
36
+ while (line = fileC.gets)
37
+ content << line.gsub("\n", "")
38
+ end
39
+ end
40
+
41
+ @user = content[1]
42
+ @pass = Github::Cipher.new.decrypt(content[2])
43
+
44
+ return [@user, @pass]
45
+ elsif type == :oauth
46
+ content = []
47
+
48
+ File.open("#{Dir.home}/.hubmaster", "rb") do |fileC|
49
+ while (line = fileC.gets)
50
+ content << line.gsub("\n", "")
51
+ end
52
+ end
53
+
54
+ @user = content[1]
55
+ @token = content[2]
56
+
57
+ return [@user, @token]
58
+ end
59
+ end
60
+ end
61
+
62
+ def self.basic
63
+ print "Username: "
64
+ @user = STDIN.gets.chomp
65
+ @pass = ask("Password: ") {|q| q.echo = "*"}
66
+ return [@user, @pass]
67
+ end
68
+ end
69
+ end
@@ -137,7 +137,7 @@ module Github
137
137
  end
138
138
 
139
139
  case operator
140
- when :contributers
140
+ when :contributors
141
141
  request = Github.makeGetRequest("/repos/#{owner}/#{name}/contributors")
142
142
  response = JSON.parse(request)
143
143
 
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Github
2
- VERSION = "0.0.08"
2
+ VERSION = "0.0.09"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubmaster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.08
4
+ version: 0.0.09
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-10 00:00:00.000000000 Z
12
+ date: 2012-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline
@@ -43,7 +43,7 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: Hubmaster is a tool built in ruby that allows github interactions to
46
+ description: Hubmaster is a tool built in Ruby that allows Github interactions to
47
47
  be made outside the browser.
48
48
  email:
49
49
  - me@tommyschaefer.net
@@ -58,6 +58,7 @@ files:
58
58
  - lib/hubmaster.rb
59
59
  - lib/hubmaster/base.rb
60
60
  - lib/hubmaster/cipher.rb
61
+ - lib/hubmaster/login.rb
61
62
  - lib/hubmaster/repo.rb
62
63
  - lib/version.rb
63
64
  homepage: https://github.com/tommyschaefer/hubmaster
@@ -83,5 +84,5 @@ rubyforge_project:
83
84
  rubygems_version: 1.8.24
84
85
  signing_key:
85
86
  specification_version: 3
86
- summary: Hubmaster is simple and easy to use. Visit the github page for more details.
87
+ summary: Hubmaster is simple and easy to use. Visit the Github page for more details.
87
88
  test_files: []