hubmaster 0.0.02 → 0.0.03

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,14 +18,45 @@ To use as a command line tool, run:
18
18
 
19
19
  ## Usage
20
20
 
21
- To use this gem, you execute:
21
+ The general form for executing commands is `hub repos --modifier [params]`. All parameters that include spaces must be encased in quotes.
22
22
 
23
- hub repos -modifier params
23
+ **BEWARE:** For the purposes of this document, when words are surrounded by brackets, the indicated value should be placed there **without brackets**.
24
24
 
25
- To list all repositories under your account, the modifier is "list" and no parameters are necessary.
25
+ ***
26
26
 
27
- To list all repositories under someone elses account, the modifier is "list" and the users name is the parameter.
27
+ To list all repositories under your account:
28
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.
29
+ hub repos --list
30
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.
31
+ ***
32
+
33
+ To list all repositories under someone elses account:
34
+
35
+ hub repos --list [username]
36
+
37
+ ***
38
+
39
+ To create a new repository:
40
+
41
+ hub repos --create [name] "[description]"
42
+ *Additionaly this command can be run with no parameters and you will be prompted for them later.*
43
+
44
+ ***
45
+
46
+ To delete an existing repository:
47
+
48
+ hub repos --delete [name]
49
+ *Andy you will be asked to confirm by typing the name of the repository specified.*
50
+
51
+ ***
52
+
53
+ To edit an existing repository:
54
+
55
+ hub repos --edit [name] -option [option dependent variable]
56
+
57
+ *The edit command takes several parameters and can be kind of confusing. First you specify
58
+ the name of the repository you would like to edit, followed by the part you would like to edit.
59
+ Currently all that can be edited is the the description, so the '-option' would look like '-description'.
60
+ Finally, you can either specify the change now or be prompted for it later.*
61
+
62
+ **REMEMBER: IF ANY PARAMETERS INCLUDE SPACES, THEY MUST BE ENCASED IN QUOTES**
data/bin/hub CHANGED
@@ -18,6 +18,14 @@ if ARGV.length > 0
18
18
  when "--get"
19
19
  Github.connect
20
20
  Github::Repos.get(ARGV[2], ARGV[3])
21
+ when "--edit"
22
+ Github.connect
23
+ case ARGV[3]
24
+ when "-description"
25
+ Github::Repos.edit(:description, ARGV[2], ARGV[4])
26
+ else
27
+ puts "Unknown modifier for edit '#{ARGV[2]}'. Tyle hub help for assistance."
28
+ end
21
29
  else
22
30
  puts "Unknown Command: Type hub help for usage instructions."
23
31
  end
@@ -60,6 +60,16 @@ module Github
60
60
  return response.body
61
61
  end
62
62
 
63
+ def self.makeEditRequest(path, body, username = @user, password = @pass, server = "api.github.com")
64
+ http = Net::HTTP.new(server,443)
65
+ req = Net::HTTP::Post.new(path)
66
+ http.use_ssl = true
67
+ req.basic_auth username, password
68
+ req.body = body
69
+ response = http.request(req)
70
+ return response.body
71
+ end
72
+
63
73
  def self.help
64
74
  puts "Hubmaster Help: "
65
75
  end
@@ -6,9 +6,11 @@ module Github
6
6
  else
7
7
  request = Github.makeGetRequest("/users/#{user}/repos?sort=pushed")
8
8
  end
9
-
10
- if !request.nil?
11
- JSON.parse(request).each do |repo|
9
+
10
+ response = JSON.parse(request)
11
+
12
+ if response.kind_of?(Array)
13
+ response.each do |repo|
12
14
  puts "#{repo['name']} (#{repo['url']})"
13
15
  puts " - Description: #{repo['description']}"
14
16
  puts " - Owner: #{repo['owner']['login']}"
@@ -23,9 +25,10 @@ module Github
23
25
  puts " - Last Updated: #{updated_at[1]} on #{updated_at_date}"
24
26
  puts ""
25
27
  end
26
- else
27
- puts "No repositories found."
28
- puts ""
28
+ elsif !response["errors"].nil?
29
+ puts "ERROR: #{response['errors'][0]['message']}"
30
+ elsif !response["message"].nil?
31
+ puts "ERROR: #{response["message"]}"
29
32
  end
30
33
  end
31
34
 
@@ -44,10 +47,41 @@ module Github
44
47
  request = Github.makePostRequest("/user/repos", jsonHash)
45
48
  response = JSON.parse(request)
46
49
 
47
- if response["errors"].nil?
50
+ if response["errors"].nil? && response["message"].nil?
48
51
  puts "Repository \"#{name}\" succesfully created! Hosted at: #{JSON.parse(request)["url"]}"
49
- else
52
+ elsif !response["errors"].nil?
53
+ puts "ERROR: #{response['errors'][0]['message']}"
54
+ elsif !response["message"].nil?
55
+ puts "ERROR: #{response["message"]}"
56
+ end
57
+ puts ""
58
+ end
59
+
60
+ def self.edit(operation, name, op)
61
+ if name.nil?
62
+ print "Name of repository you wish to edit: "
63
+ name = STDIN.gets.chomp
64
+ end
65
+
66
+ case operation
67
+ when :description
68
+ if op.nil?
69
+ print "Intended description of repository: "
70
+ op = STDIN.gets.chomp
71
+ end
72
+
73
+ jsonHash = {"name" => name, "description" => op}.to_json
74
+ request = Github.makeEditRequest("/repos/#{Github.user}/#{name}", jsonHash)
75
+ end
76
+
77
+ response = JSON.parse(request)
78
+
79
+ if response["errors"].nil? && response["message"].nil?
80
+ puts "Repository \"#{name}\" succesfully edited! See updates at: #{JSON.parse(request)["url"]}"
81
+ elsif !response["errors"].nil?
50
82
  puts "ERROR: #{response['errors'][0]['message']}"
83
+ elsif !response["message"].nil?
84
+ puts "ERROR: #{response["message"]}"
51
85
  end
52
86
  puts ""
53
87
  end
@@ -58,17 +92,28 @@ module Github
58
92
  name = STDIN.gets.chomp
59
93
  end
60
94
 
61
- request = Github.makeGetRequest("/user/repos")
95
+ puts "This well permenantly delete the repository '#{name}' from your github account. Are you sure you want to do this?"
96
+ print "If so, type the name of the repository (enter to cancle): "
97
+ confirm = STDIN.gets.chomp
62
98
 
63
- JSON.parse(request).each do |repo|
64
- if repo["name"] == name
65
- @owner = repo["owner"]["login"]
99
+ if confirm == name
100
+ request = Github.makeDeleteRequest("/repos/#{Github.user}/#{name}")
101
+ if request.nil?
102
+ response = nil
103
+ else
104
+ response = JSON.parse(request)
66
105
  end
67
- end
68
106
 
69
- request = Github.makeDeleteRequest("/repos/#{@owner}/#{name}")
70
-
71
- puts "Delete command sent for repository #{name}!"
107
+ if response.nil?
108
+ puts "Repository '#{name}' has been deleted!"
109
+ elsif !response["errors"].nil?
110
+ puts "ERROR: #{response['errors'][0]['message']}"
111
+ elsif !response["message"].nil?
112
+ puts "ERROR: #{response["message"]}"
113
+ end
114
+ else
115
+ puts "Name entered was incorrect and request has been cancled."
116
+ end
72
117
  puts ""
73
118
  end
74
119
 
@@ -79,26 +124,34 @@ module Github
79
124
  else
80
125
  request = Github.makeGetRequest("/repos/#{owner}/#{name}")
81
126
  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 ""
127
+
128
+ response = JSON.parse(request)
129
+
130
+ if response["errors"].nil? && response["message"].nil?
131
+ puts "#{response['name']} (#{response['url']})"
132
+ puts " - Owner: #{response['owner']['login']}"
133
+ puts " - Description: #{response['description']}"
134
+ puts " - Private: #{response['private']}"
135
+ puts " - Fork: #{response['fork']}"
136
+ puts " - Language: #{response['language']}"
137
+ puts " - Forks: #{response['forks']}"
138
+ puts " - Watchers: #{response['watchers']}"
139
+ puts " - Master Branch: #{response['master_branch']}"
140
+ puts " - Open Issues: #{response['open_issues']}"
141
+ created_at = response['created_at'].split("T")
142
+ created_at_date = created_at[0].split("-")
143
+ created_at_date = "#{created_at_date[1]}/#{created_at_date[2]}/#{created_at_date[0]}"
144
+ puts " - Created At: #{created_at[1]} on #{created_at_date}"
145
+ updated_at = response['updated_at'].split("T")
146
+ updated_at_date = updated_at[0].split("-")
147
+ updated_at_date = "#{updated_at_date[1]}/#{updated_at_date[2]}/#{updated_at_date[0]}"
148
+ puts " - Last Updated: #{updated_at[1]} on #{updated_at_date}"
149
+ elsif !response["errors"].nil?
150
+ puts "ERROR: #{response['errors'][0]['message']}"
151
+ elsif !response["message"].nil?
152
+ puts "ERROR: #{response["message"]}"
101
153
  end
154
+ puts ""
102
155
  else
103
156
  puts "A repository name must be specified."
104
157
  puts ""
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Github
2
- VERSION = "0.0.02"
2
+ VERSION = "0.0.03"
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.02
4
+ version: 0.0.03
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-06 00:00:00.000000000 Z
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: highline
@@ -54,7 +54,6 @@ extra_rdoc_files: []
54
54
  files:
55
55
  - README.md
56
56
  - bin/hub
57
- - hubmaster-0.0.01.gem
58
57
  - hubmaster.gemspec
59
58
  - lib/hubmaster.rb
60
59
  - lib/hubmaster/base.rb
data/hubmaster-0.0.01.gem DELETED
Binary file