Permalink
Browse files

More yardoc

  • Loading branch information...
pengwynn committed Oct 8, 2012
1 parent fbe7e44 commit 103333e8d19c94b2e9c15c00efde22ac02982c13
Showing with 125 additions and 11 deletions.
  1. +6 −1 lib/octokit/client/organizations.rb
  2. +114 −5 lib/octokit/client/repositories.rb
  3. +5 −5 spec/octokit/client/repositories_spec.rb
@@ -22,7 +22,12 @@ def organizations(user=nil, options={})
alias :list_orgs :organizations
alias :orgs :organizations
def organization_repositories(org=nil, options={})
# List organization repositories
#
# @see http://developer.github.com/v3/repos/#list-organization-repositories
# @param org [String] Organization handle for which to list repos
# @return [Array<Hashie::Mash>] List of repositories
def organization_repositories(org, options={})
get("orgs/#{org}/repos", options, 3)
end
alias :org_repositories :organization_repositories
@@ -1,23 +1,55 @@
module Octokit
class Client
module Repositories
# Legacy repository search
#
# @see http://developer.github.com/v3/search/#search-repositories
# @param q [String] Search keyword
# @return [Array<Hashie::Mash>] List of repositories found
def search_repositories(q, options={})
get("legacy/repos/search/#{q}", options, 3)['repositories']
end
alias :search_repos :search_repositories
# Get a single repository
#
# @see http://developer.github.com/v3/repos/#get
# @param repo [String, Hash, Repository] A GitHub repository
# @return [Hashie::Mash] Repository information
def repository(repo, options={})
get "repos/#{Repository.new repo}", options, 3
end
alias :repo :repository
# Edit a repository
#
# @see http://developer.github.com/v3/repos/#edit
# @param repo [String, Hash, Repository] A GitHub repository
# @param options [Hash] Repository information to update
# @option options [String] :name Name of the repo
# @option options [String] :description Description of the repo
# @option options [String] :homepage Home page of the repo
# @option options [String] :private `true` makes the repository private, and `false` makes it public.
# @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
# @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
# @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
# @return [Hashie::Mash] Repository information
def edit_repository(repo, options={})
patch "repos/#{Repository.new repo}", options, 3
end
alias :edit :edit_repository
alias :update_repository :edit_repository
alias :update :edit_repository
# List repositories
#
# If username is not supplied, repositories for the current
# authenticated user are returned
#
# @see http://developer.github.com/v3/repos/#list-your-repositories
# @param username [String] Optional username for which to list repos
# @return [Array<Hashie::Mash>] List of repositories
def repositories(username=nil, options={})
if username.nil?
get 'user/repos', options, 3
@@ -29,26 +61,83 @@ def repositories(username=nil, options={})
alias :list_repos :repositories
alias :repos :repositories
# Star a repository
#
# @param repo [String, Hash, Repository] A GitHub repository
# @return [Boolean] `true` if successfully starred
def star(repo, options={})
put "user/starred/#{Repository.new repo}", options, 3
begin
put "user/starred/#{Repository.new repo}", options, 3
return true
rescue Octokit::NotFound
return false
end
end
# Unstar a repository
#
# @param repo [String, Hash, Repository] A GitHub repository
# @return [Boolean] `true` if successfully unstarred
def unstar(repo, options={})
delete "user/starred/#{Repository.new repo}", options, 3
begin
delete "user/starred/#{Repository.new repo}", options, 3
return true
rescue Octokit::NotFound
return false
end
end
# Watch a repository
#
# @param repo [String, Hash, Repository] A GitHub repository
# @return [Boolean] `true` if successfully watched
# @deprecated Use #star instead
def watch(repo, options={})
put "user/watched/#{Repository.new repo}", options, 3
begin
put "user/watched/#{Repository.new repo}", options, 3
return true
rescue Octokit::NotFound
return false
end
end
# Unwatch a repository
#
# @param repo [String, Hash, Repository] A GitHub repository
# @return [Boolean] `true` if successfully unwatched
# @deprecated Use #unstar instead
def unwatch(repo, options={})
delete "user/watched/#{Repository.new repo}", options, 3
begin
delete "user/watched/#{Repository.new repo}", options, 3
return true
rescue Octokit::NotFound
return false
end
end
# Fork a repository
#
# @param repo [String, Hash, Repository] A GitHub repository
# @return [Hashie::Mash] Repository info for the new fork
def fork(repo, options={})
post "repos/#{Repository.new repo}/forks", options, 3
end
# Create a repository for a user or organization
#
# @param name [String] Name of the new repo
# @option options [String] :description Description of the repo
# @option options [String] :homepage Home page of the repo
# @option options [String] :private `true` makes the repository private, and `false` makes it public.
# @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
# @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
# @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
# @option options [String] :organization Short name for the org under which to create the repo.
# @option options [Integer] :team_id The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization.
# @option options [Boolean] :auto_init `true` to create an initial commit with empty README. Default is `false`.
# @option options [String] :gitignore_template Desired language or platform .gitignore template to apply. Ignored if auto_init parameter is not provided.
# @return [Hashie::Mash] Repository info for the new repository
# @see http://developer.github.com/v3/repos/#create
def create_repository(name, options={})
organization = options.delete :organization
options.merge! :name => name
@@ -62,16 +151,36 @@ def create_repository(name, options={})
alias :create_repo :create_repository
alias :create :create_repository
# Delete repository
#
# Note: If OAuth is used, 'delete_repo' scope is required
#
# @see http://developer.github.com/v3/repos/#delete-a-repository
# @param repo [String, Hash, Repository] A GitHub repository
# @return [Boolean] `true` if repository was deleted
def delete_repository(repo, options={})
delete "repos/#{Repository.new repo}", options, 3
begin
delete "repos/#{Repository.new repo}", options, 3
return true
rescue Octokit::NotFound
return false
end
end
alias :delete_repo :delete_repository
# Hide a public repository
#
# @param repo [String, Hash, Repository] A GitHub repository
# @return [Hashie::Mash] Updated repository info
def set_private(repo, options={})
# GitHub Api for setting private updated to use private attr, rather than public
update_repository repo, options.merge({ :private => true })
end
# Unhide a private repository
#
# @param repo [String, Hash, Repository] A GitHub repository
# @return [Hashie::Mash] Updated repository info
def set_public(repo, options={})
# GitHub Api for setting private updated to use private attr, rather than public
update_repository repo, options.merge({ :private => false })
@@ -73,7 +73,7 @@
it "should star a repository" do
stub_put("/user/starred/sferik/rails_admin").
to_return(:status => 204)
@client.star("sferik/rails_admin").should be_nil
@client.star("sferik/rails_admin").should be_true
end
end
@@ -83,7 +83,7 @@
it "should unstar a repository" do
stub_delete("/user/starred/sferik/rails_admin").
to_return(:status => 204)
@client.unstar("sferik/rails_admin").should be_nil
@client.unstar("sferik/rails_admin").should be_true
end
end
@@ -93,7 +93,7 @@
it "should watch a repository" do
stub_put("/user/watched/sferik/rails_admin").
to_return(:status => 204)
@client.watch("sferik/rails_admin").should be_nil
@client.watch("sferik/rails_admin").should be_true
end
end
@@ -103,7 +103,7 @@
it "should unwatch a repository" do
stub_delete("/user/watched/sferik/rails_admin").
to_return(:status => 204)
@client.unwatch("sferik/rails_admin").should be_nil
@client.unwatch("sferik/rails_admin").should be_true
end
end
@@ -146,7 +146,7 @@
stub_delete("/repos/sferik/rails_admin").
to_return(:status => 204, :body => "")
result = @client.delete_repository("sferik/rails_admin")
result.should be_nil
result.should be_true
end
end

0 comments on commit 103333e

Please sign in to comment.