hubmaster 0.0.01
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +31 -0
- data/bin/hub +39 -0
- data/hubmaster-0.0.1.gem +0 -0
- data/hubmaster.gemspec +16 -0
- data/lib/hubmaster/base.rb +67 -0
- data/lib/hubmaster/cipher.rb +22 -0
- data/lib/hubmaster/repo.rb +108 -0
- data/lib/hubmaster.rb +11 -0
- data/lib/version.rb +3 -0
- metadata +56 -0
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Hubmaster
|
2
|
+
|
3
|
+
Hubmaster is a rubygem that allows GitHub API interaction in Terminal. The current version only permit repository interactions (list, create, delete), but feel free to fork and contribute!
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
To use as a library, add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'hubmaster'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
bundle install
|
14
|
+
|
15
|
+
To use as a command line tool, run:
|
16
|
+
|
17
|
+
sudo gem install hubmaster
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To use this gem, you execute:
|
22
|
+
|
23
|
+
hub repos -modifier params
|
24
|
+
|
25
|
+
To list all repositories under your account, the modifier is "list" and no parameters are necessary.
|
26
|
+
|
27
|
+
To list all repositories under someone elses account, the modifier is "list" and the users name is the parameter.
|
28
|
+
|
29
|
+
To create a new repository, the modifier is "create" and there are two parameters. The first is the name of the repository (place in quotes if multiword) and the next is the description (place in quotes if multiword). Additionally this command can be run with no parameters and you will be prompted for them later.
|
30
|
+
|
31
|
+
To delete an existing repository, the modifier is "delete" and only one parameter is required. The parameter is the name of the repository you wish to delete. You can also omit the the parameter and you will be prompted for it later.
|
data/bin/hub
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'hubmaster.rb'))
|
4
|
+
|
5
|
+
if ARGV.length > 0
|
6
|
+
result = case ARGV[0]
|
7
|
+
when "repos"
|
8
|
+
case ARGV[1]
|
9
|
+
when "--list"
|
10
|
+
Github.connect
|
11
|
+
Github::Repos.list(ARGV[2])
|
12
|
+
when "--create"
|
13
|
+
Github.connect
|
14
|
+
Github::Repos.create(ARGV[2], ARGV[3])
|
15
|
+
when "--delete"
|
16
|
+
Github.connect
|
17
|
+
Github::Repos.delete(ARGV[2])
|
18
|
+
when "--get"
|
19
|
+
Github.connect
|
20
|
+
Github::Repos.get(ARGV[2], ARGV[3])
|
21
|
+
else
|
22
|
+
puts "Unknown Command: Type hub help for usage instructions."
|
23
|
+
end
|
24
|
+
when "help"
|
25
|
+
Github.help
|
26
|
+
when "login"
|
27
|
+
case ARGV[1]
|
28
|
+
when "--reset"
|
29
|
+
Github.resetLogin
|
30
|
+
else
|
31
|
+
end
|
32
|
+
else
|
33
|
+
puts "Unknown Command: Type hub help for usage instructions."
|
34
|
+
end
|
35
|
+
exit
|
36
|
+
else
|
37
|
+
puts "Unknown Command: Type hub help for usage instructions."
|
38
|
+
end
|
39
|
+
|
data/hubmaster-0.0.1.gem
ADDED
Binary file
|
data/hubmaster.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Tommy Schaefer"]
|
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.}
|
9
|
+
gem.homepage = "https://github.com/tommyschaefer/hubmaster"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "hubmaster"
|
15
|
+
gem.version = Github::VERSION
|
16
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Github
|
2
|
+
def self.connect
|
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
|
10
|
+
|
11
|
+
@user = content[0]
|
12
|
+
@pass = Github::Cipher.new.decrypt(content[1])
|
13
|
+
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
|
22
|
+
|
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)}")}
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.user
|
32
|
+
return @user
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.makeGetRequest(path, username = @user, password = @pass, server = "api.github.com")
|
36
|
+
http = Net::HTTP.new(server,443)
|
37
|
+
req = Net::HTTP::Get.new(path)
|
38
|
+
http.use_ssl = true
|
39
|
+
req.basic_auth username, password
|
40
|
+
response = http.request(req)
|
41
|
+
return response.body
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.makePostRequest(path, body, username = @user, password = @pass, server = "api.github.com")
|
45
|
+
http = Net::HTTP.new(server,443)
|
46
|
+
req = Net::HTTP::Post.new(path)
|
47
|
+
http.use_ssl = true
|
48
|
+
req.basic_auth username, password
|
49
|
+
req.body = body
|
50
|
+
response = http.request(req)
|
51
|
+
return response.body
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.makeDeleteRequest(path, username = @user, password = @pass, server = "api.github.com")
|
55
|
+
http = Net::HTTP.new(server,443)
|
56
|
+
req = Net::HTTP::Delete.new(path)
|
57
|
+
http.use_ssl = true
|
58
|
+
req.basic_auth username, password
|
59
|
+
response = http.request(req)
|
60
|
+
return response.body
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.help
|
64
|
+
puts "Hubmaster Help: "
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Github
|
2
|
+
class Cipher
|
3
|
+
def initialize
|
4
|
+
normal = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + [' ']
|
5
|
+
shuffled = ["K", "D", "w", "X", "H", "3", "e", "1", "S", "B", "g", "a", "y", "v", "I", "6", "u", "W", "C", "0", "9", "b", "z", "T", "A", "q", "U", "4", "O", "o", "E", "N", "r", "n", "m", "d", "k", "x", "P", "t", "R", "s", "J", "L", "f", "h", "Z", "j", "Y", "5", "7", "l", "p", "c", "2", "8", "M", "V", "G", "i", " ", "Q", "F"]
|
6
|
+
|
7
|
+
@map = normal.zip(shuffled).inject(:encrypt => {} , :decrypt => {}) do |hash,(a,b)|
|
8
|
+
hash[:encrypt][a] = b
|
9
|
+
hash[:decrypt][b] = a
|
10
|
+
hash
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def encrypt(data)
|
15
|
+
data.split(//).map { |char| @map[:encrypt][char] }.join
|
16
|
+
end
|
17
|
+
|
18
|
+
def decrypt(eData)
|
19
|
+
eData.split(//).map { |char| @map[:decrypt][char] }.join
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module Github
|
2
|
+
class Repos
|
3
|
+
def self.list(user = nil)
|
4
|
+
if user.nil?
|
5
|
+
request = Github.makeGetRequest("/user/repos?sort=pushed")
|
6
|
+
else
|
7
|
+
request = Github.makeGetRequest("/users/#{user}/repos?sort=pushed")
|
8
|
+
end
|
9
|
+
|
10
|
+
if !request.nil?
|
11
|
+
JSON.parse(request).each do |repo|
|
12
|
+
puts "#{repo['name']} (#{repo['url']})"
|
13
|
+
puts " - Description: #{repo['description']}"
|
14
|
+
puts " - Owner: #{repo['owner']['login']}"
|
15
|
+
puts " - Language: #{repo['language']}"
|
16
|
+
created_at = repo['created_at'].split("T")
|
17
|
+
created_at_date = created_at[0].split("-")
|
18
|
+
created_at_date = "#{created_at_date[1]}/#{created_at_date[2]}/#{created_at_date[0]}"
|
19
|
+
puts " - Created At: #{created_at[1]} on #{created_at_date}"
|
20
|
+
updated_at = repo['updated_at'].split("T")
|
21
|
+
updated_at_date = updated_at[0].split("-")
|
22
|
+
updated_at_date = "#{updated_at_date[1]}/#{updated_at_date[2]}/#{updated_at_date[0]}"
|
23
|
+
puts " - Last Updated: #{updated_at[1]} on #{updated_at_date}"
|
24
|
+
puts ""
|
25
|
+
end
|
26
|
+
else
|
27
|
+
puts "No repositories found."
|
28
|
+
puts ""
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.create(name, description)
|
33
|
+
if name.nil?
|
34
|
+
print "Name of repository: "
|
35
|
+
name = STDIN.gets.chomp
|
36
|
+
end
|
37
|
+
|
38
|
+
if description.nil?
|
39
|
+
print "Description of repository: "
|
40
|
+
description = STDIN.gets.chomp
|
41
|
+
end
|
42
|
+
|
43
|
+
jsonHash = {"name" => name, "description" => description}.to_json
|
44
|
+
request = Github.makePostRequest("/user/repos", jsonHash)
|
45
|
+
response = JSON.parse(request)
|
46
|
+
|
47
|
+
if response["errors"].nil?
|
48
|
+
puts "Repository \"#{name}\" succesfully created! Hosted at: #{JSON.parse(request)["url"]}"
|
49
|
+
else
|
50
|
+
puts "ERROR: #{response['errors'][0]['message']}"
|
51
|
+
end
|
52
|
+
puts ""
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.delete(name)
|
56
|
+
if name.nil?
|
57
|
+
print "Name of repository: "
|
58
|
+
name = STDIN.gets.chomp
|
59
|
+
end
|
60
|
+
|
61
|
+
request = Github.makeGetRequest("/user/repos")
|
62
|
+
|
63
|
+
JSON.parse(request).each do |repo|
|
64
|
+
if repo["name"] == name
|
65
|
+
@owner = repo["owner"]["login"]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
request = Github.makeDeleteRequest("/repos/#{@owner}/#{name}")
|
70
|
+
|
71
|
+
puts "Delete command sent for repository #{name}!"
|
72
|
+
puts ""
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.get(owner, name)
|
76
|
+
if !name.nil?
|
77
|
+
if owner == "self"
|
78
|
+
request = Github.makeGetRequest("/repos/#{Github.user}/#{name}")
|
79
|
+
else
|
80
|
+
request = Github.makeGetRequest("/repos/#{owner}/#{name}")
|
81
|
+
end
|
82
|
+
|
83
|
+
if !request.nil?
|
84
|
+
repo = JSON.parse(request)
|
85
|
+
puts "#{repo['name']} (#{repo['url']})"
|
86
|
+
puts " - Description: #{repo['description']}"
|
87
|
+
puts " - Owner: #{repo['owner']['login']}"
|
88
|
+
puts " - Language: #{repo['language']}"
|
89
|
+
created_at = repo['created_at'].split("T")
|
90
|
+
created_at_date = created_at[0].split("-")
|
91
|
+
created_at_date = "#{created_at_date[1]}/#{created_at_date[2]}/#{created_at_date[0]}"
|
92
|
+
puts " - Created At: #{created_at[1]} on #{created_at_date}"
|
93
|
+
updated_at = repo['updated_at'].split("T")
|
94
|
+
updated_at_date = updated_at[0].split("-")
|
95
|
+
updated_at_date = "#{updated_at_date[1]}/#{updated_at_date[2]}/#{updated_at_date[0]}"
|
96
|
+
puts " - Last Updated: #{updated_at[1]} on #{updated_at_date}"
|
97
|
+
puts ""
|
98
|
+
else
|
99
|
+
puts "No repositories found."
|
100
|
+
puts ""
|
101
|
+
end
|
102
|
+
else
|
103
|
+
puts "A repository name must be specified."
|
104
|
+
puts ""
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/hubmaster.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'highline/import'
|
3
|
+
require 'json'
|
4
|
+
require 'net/http'
|
5
|
+
require 'net/https'
|
6
|
+
require 'stringio'
|
7
|
+
require 'uri'
|
8
|
+
|
9
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "hubmaster", "base.rb"))
|
10
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "hubmaster", "repo.rb"))
|
11
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "hubmaster", "cipher.rb"))
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hubmaster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.01
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tommy Schaefer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Hubmaster is a tool built in ruby that allows github interactions to
|
15
|
+
be made outside the browser.
|
16
|
+
email:
|
17
|
+
- me@tommyschaefer.net
|
18
|
+
executables:
|
19
|
+
- hub
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- README.md
|
24
|
+
- bin/hub
|
25
|
+
- hubmaster-0.0.1.gem
|
26
|
+
- hubmaster.gemspec
|
27
|
+
- lib/hubmaster.rb
|
28
|
+
- lib/hubmaster/base.rb
|
29
|
+
- lib/hubmaster/cipher.rb
|
30
|
+
- lib/hubmaster/repo.rb
|
31
|
+
- lib/version.rb
|
32
|
+
homepage: https://github.com/tommyschaefer/hubmaster
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.24
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Hubmaster is simple and easy to use. Visit the github page for more details.
|
56
|
+
test_files: []
|