124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
# File 'lib/hubmaster/repo.rb', line 124
def self.get(owner, name, operator, branch = nil)
owner = Github.user if owner == "self"
toput = []
if owner.nil?
print "Name of owner: "
owner = STDIN.gets.chomp
end
if name.nil?
print "Name of repository: "
name = STDIN.gets.chomp
end
case operator
when :contributors
request = Github.makeGetRequest("/repos/#{owner}/#{name}/contributors")
response = JSON.parse(request)
if response.kind_of?(Array)
response.each do |contributer|
toput << "User #{contributer["login"]}"
toput << " - URL: #{contributer["url"]}"
toput << " - Contributions #{contributer["contributions"]}"
toput << ""
end
elsif !response["errors"].nil?
puts "ERROR: #{response['errors'][0]['message']}"
puts ""
elsif !response["message"].nil?
puts "ERROR: #{response["message"]}"
puts ""
end
when :languages
request = Github.makeGetRequest("/repos/#{owner}/#{name}/languages")
response = JSON.parse(request)
if response["errors"].nil? && response["message"].nil?
response.each do |language, bytes|
toput << "#{bytes} bytes written in #{language}."
toput << ""
end
elsif !response["errors"].nil?
puts "ERROR: #{response['errors'][0]['message']}"
puts ""
elsif !response["message"].nil?
puts "ERROR: #{response["message"]}"
puts ""
end
when :teams
request = Github.makeGetRequest("/repos/#{owner}/#{name}/teams")
response = JSON.parse(request)
if response.kind_of?(Array)
response.each do |team|
toput << "Team: #{team["name"]}"
toput << " - URL: #{team["url"]}"
puts ""
end
elsif !response["errors"].nil?
puts "ERROR: #{response['errors'][0]['message']}"
puts ""
elsif !response["message"].nil?
puts "ERROR: #{response["message"]}"
puts ""
end
when :tags
request = Github.makeGetRequest("/repos/#{owner}/#{name}/tags")
response = JSON.parse(request)
if response.kind_of?(Array)
response.each do |tag|
toput << "Tag Name: #{tag["name"]}"
toput << " - Commit URL: #{tag["commit"]["url"]}"
toput << " - Commit SHA: #{tag["commit"]["sha"]}"
toput << ""
end
elsif !response["errors"].nil?
puts "ERROR: #{response['errors'][0]['message']}"
puts ""
elsif !response["message"].nil?
puts "ERROR: #{response["message"]}"
puts ""
end
when :branches
request = Github.makeGetRequest("/repos/#{owner}/#{name}/branches")
response = JSON.parse(request)
if response.kind_of?(Array)
response.each do |branch|
toput << "Branch Name: #{branch["name"]}"
toput << " - Commit URL: #{branch["commit"]["url"]}"
toput << " - Commit SHA: #{branch["commit"]["sha"]}"
puts ""
end
elsif !response["errors"].nil?
puts "ERROR: #{response['errors'][0]['message']}"
puts ""
elsif !response["message"].nil?
puts "ERROR: #{response["message"]}"
puts ""
end
when :branch
if branch.nil?
print "Branch to view: "
branch = STDIN.gets.chomp
end
request = Github.makeGetRequest("/repos/#{owner}/#{name}/branches/#{branch}")
response = JSON.parse(request)
if response["errors"].nil? && response["message"].nil?
puts "Branch Name: #{response['name']}"
puts " - Commit SHA: #{response["commit"]["sha"]}"
puts " - Message: #{response["commit"]["commit"]["message"]}"
puts " - Author: #{response["commit"]["author"]["login"]}"
puts " - Author Name: #{response["commit"]["commit"]["author"]["name"]}"
puts " - Author Email: #{response["commit"]["commit"]["author"]["email"]}"
if response["commit"]["committer"]["login"] != response["commit"]["author"]["login"]
puts " - Commiter: #{response["commit"]["committer"]["login"]}"
puts " - Commiter Name: #{response["commit"]["commit"]["committer"]["name"]}"
puts " - Commiter Email: #{response["commit"]["commit"]["committer"]["email"]}"
end
puts " - Parents:"
response["commit"]["parents"].each do |parent|
puts " - Parent SHA: #{parent["sha"]}"
end
elsif !response["errors"].nil?
puts "ERROR: #{response['errors'][0]['message']}"
elsif !response["message"].nil?
puts "ERROR: #{response["message"]}"
end
puts ""
when :repository
request = Github.makeGetRequest("/repos/#{owner}/#{name}")
response = JSON.parse(request)
if response["errors"].nil? && response["message"].nil?
puts "#{response['name']} (#{response['ssh_url']})"
puts " - Owner: #{response['owner']['login']}"
puts " - Description: #{response['description']}"
puts " - Private: #{response['private']}"
puts " - Fork: #{response['fork']}"
puts " - Language: #{response['language']}"
puts " - Forks: #{response['forks']}"
puts " - Watchers: #{response['watchers']}"
puts " - Master Branch: #{response['master_branch']}"
puts " - Open Issues: #{response['open_issues']}"
created_at = response['created_at'].split("T")
created_at_date = created_at[0].split("-")
created_at_date = "#{created_at_date[1]}/#{created_at_date[2]}/#{created_at_date[0]}"
puts " - Created At: #{created_at[1]} on #{created_at_date}"
updated_at = response['updated_at'].split("T")
updated_at_date = updated_at[0].split("-")
updated_at_date = "#{updated_at_date[1]}/#{updated_at_date[2]}/#{updated_at_date[0]}"
puts " - Last Updated: #{updated_at[1]} on #{updated_at_date}"
elsif !response["errors"].nil?
puts "ERROR: #{response['errors'][0]['message']}"
elsif !response["message"].nil?
puts "ERROR: #{response["message"]}"
end
puts ""
end
putLess toput unless toput == []
end
|