Class: Github::Repos
- Inherits:
-
Object
- Object
- Github::Repos
- Defined in:
- lib/hubmaster/repo.rb
Class Method Summary collapse
- .create(name, description) ⇒ Object
- .delete(name) ⇒ Object
- .edit(operation, name, op) ⇒ Object
- .get(owner, name) ⇒ Object
- .list(user = nil) ⇒ Object
Class Method Details
.create(name, description) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/hubmaster/repo.rb', line 35 def self.create(name, description) if name.nil? print "Name of repository: " name = STDIN.gets.chomp end if description.nil? print "Description of repository: " description = STDIN.gets.chomp end jsonHash = {"name" => name, "description" => description}.to_json request = Github.makePostRequest("/user/repos", jsonHash) response = JSON.parse(request) if response["errors"].nil? && response["message"].nil? puts "Repository \"#{name}\" succesfully created! Hosted at: #{JSON.parse(request)["ssh_url"]}" elsif !response["errors"].nil? puts "ERROR: #{response['errors'][0]['message']}" elsif !response["message"].nil? puts "ERROR: #{response["message"]}" end puts "" end |
.delete(name) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/hubmaster/repo.rb', line 89 def self.delete(name) if name.nil? print "Name of repository: " name = STDIN.gets.chomp end puts "This well permenantly delete the repository '#{name}' from your github account. Are you sure you want to do this?" print "If so, type the name of the repository (enter to cancle): " confirm = STDIN.gets.chomp if confirm == name request = Github.makeDeleteRequest("/repos/#{Github.user}/#{name}") if request.nil? response = nil else response = JSON.parse(request) end if response.nil? puts "Repository '#{name}' has been deleted!" elsif !response["errors"].nil? puts "ERROR: #{response['errors'][0]['message']}" elsif !response["message"].nil? puts "ERROR: #{response["message"]}" end else puts "Name entered was incorrect and request has been cancled." end puts "" end |
.edit(operation, name, op) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/hubmaster/repo.rb', line 60 def self.edit(operation, name, op) if name.nil? print "Name of repository you wish to edit: " name = STDIN.gets.chomp end case operation when :description if op.nil? print "Intended description of repository: " op = STDIN.gets.chomp end jsonHash = {"name" => name, "description" => op}.to_json request = Github.makeEditRequest("/repos/#{Github.user}/#{name}", jsonHash) end response = JSON.parse(request) if response["errors"].nil? && response["message"].nil? puts "Repository \"#{name}\" succesfully edited! See updates at: #{JSON.parse(request)["html_url"]}" elsif !response["errors"].nil? puts "ERROR: #{response['errors'][0]['message']}" elsif !response["message"].nil? puts "ERROR: #{response["message"]}" end puts "" end |
.get(owner, name) ⇒ Object
120 121 122 123 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 |
# File 'lib/hubmaster/repo.rb', line 120 def self.get(owner, name) if !name.nil? if owner == "self" request = Github.makeGetRequest("/repos/#{Github.user}/#{name}") else request = Github.makeGetRequest("/repos/#{owner}/#{name}") end 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 "" else puts "A repository name must be specified." puts "" end end |
.list(user = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hubmaster/repo.rb', line 3 def self.list(user = nil) if user.nil? request = Github.makeGetRequest("/user/repos?sort=pushed") else request = Github.makeGetRequest("/users/#{user}/repos?sort=pushed") end response = JSON.parse(request) if response.kind_of?(Array) response.each do |repo| puts "#{repo['name']} (#{repo['ssh_url']})" puts " - Description: #{repo['description']}" puts " - Owner: #{repo['owner']['login']}" puts " - Language: #{repo['language']}" created_at = repo['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 = repo['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}" puts "" end elsif !response["errors"].nil? puts "ERROR: #{response['errors'][0]['message']}" elsif !response["message"].nil? puts "ERROR: #{response["message"]}" end end |