octokit 1.14.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # CHANGELOG
2
2
 
3
+ * [1.17.0 - October 8, 2012](https://github.com/pengwynn/octokit/compare/v1.16.0...v1.17.0)
4
+ * [1.16.0 - September 25,2012](https://github.com/pengwynn/octokit/compare/v1.15.1...v1.16.0)
5
+ * [1.15.1 - September 24,2012](https://github.com/pengwynn/octokit/compare/v1.15.0...v1.15.1)
6
+ * [1.15.0 - September 24,2012](https://github.com/pengwynn/octokit/compare/v1.14.0...v1.15.0)
3
7
  * [1.14.0 - September 22,2012](https://github.com/pengwynn/octokit/compare/v1.13.0...v1.14.0)
4
- * [1.13.0 - September 5,2012](https://github.com/pengwynn/octokit/compare/v1.12.0...v1.13.0)
5
- * [1.12.0 - September 4,2012](https://github.com/pengwynn/octokit/compare/v1.11.0...v1.12.0)
8
+ * [1.13.0 - September 5, 2012](https://github.com/pengwynn/octokit/compare/v1.12.0...v1.13.0)
9
+ * [1.12.0 - September 4, 2012](https://github.com/pengwynn/octokit/compare/v1.11.0...v1.12.0)
6
10
  * [1.11.0 - August 29, 2012](https://github.com/pengwynn/octokit/compare/v1.10.0...v1.11.0)
7
11
  * [1.10.0 - August 8, 2012](https://github.com/pengwynn/octokit/compare/v1.9.4...v1.10.0)
8
12
  * [1.9.4 - August 6, 2012](https://github.com/pengwynn/octokit/compare/v1.9.3...v1.9.4)
@@ -81,6 +81,62 @@ module Octokit
81
81
  get("repos/#{Repository.new(repo)}/comments/#{id}", options, 3)
82
82
  end
83
83
 
84
+ # Create a commit comment
85
+ #
86
+ # @param repo [String, Hash, Repository] A GitHub repository
87
+ # @param sha [String] Sha of the commit to comment on
88
+ # @param body [String] Message
89
+ # @param path [String] Relative path of file to comment on
90
+ # @param line [Integer] Line number in the file to comment on
91
+ # @param position [Integer] Line index in the diff to comment on
92
+ # @return [Hashie::Mash] A hash representing the new commit comment
93
+ # @see http://developer.github.com/v3/repos/comments/
94
+ # @example Create a commit comment
95
+ # commit = Octokit.create_commit_comment("octocat/Hello-World", "827efc6d56897b048c772eb4087f854f46256132", "My comment message", "README.md", 10, 1)
96
+ # commit.commit_id # => "827efc6d56897b048c772eb4087f854f46256132"
97
+ # commit.body # => "My comment message"
98
+ # commit.path # => "README.md"
99
+ # commit.line # => 10
100
+ # commit.position # => 1
101
+ def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, options={})
102
+ params = {
103
+ :body => body,
104
+ :commit_id => sha,
105
+ :path => path,
106
+ :line => line,
107
+ :position => position
108
+ }
109
+ post("repos/#{Repository.new(repo)}/commits/#{sha}/comments", options.merge(params), 3)
110
+ end
111
+
112
+ # Update a commit comment
113
+ #
114
+ # @param repo [String, Hash, Repository] A GitHub repository
115
+ # @param id [String] The ID of the comment to update
116
+ # @param body [String] Message
117
+ # @return [Hashie::Mash] A hash representing the updated commit comment
118
+ # @see http://developer.github.com/v3/repos/comments/
119
+ # @example Update a commit comment
120
+ # commit = Octokit.update_commit_comment("octocat/Hello-World", "860296", "Updated commit comment")
121
+ # commit.id # => 860296
122
+ # commit.body # => "Updated commit comment"
123
+ def update_commit_comment(repo, id, body, options={})
124
+ params = {
125
+ :body => body
126
+ }
127
+ patch("repos/#{Repository.new(repo)}/comments/#{id}", options.merge(params), 3)
128
+ end
129
+
130
+ # Delete a commit comment
131
+ #
132
+ # @param repo [String, Hash, Repository] A GitHub repository
133
+ # @param id [String] The ID of the comment to delete
134
+ # @return [nil] nil
135
+ # @see http://developer.github.com/v3/repos/comments/
136
+ def delete_commit_comment(repo, id, options={})
137
+ delete("repos/#{Repository.new(repo)}/comments/#{id}", options, 3)
138
+ end
139
+
84
140
  # Compare two commits
85
141
  #
86
142
  # @param repo [String, Hash, Repository] A GitHub repository
@@ -2,32 +2,108 @@ module Octokit
2
2
  class Client
3
3
  module Gists
4
4
 
5
- def create_gist(options={})
6
- post 'gists', options, 3
5
+ # List gists for a user or all public gists
6
+ #
7
+ # @param username [String] An optional user to filter listing
8
+ # @return [Array<Hashie::Mash>] A list of gists
9
+ # @example Fetch all gists for defunkt
10
+ # Octokit.gists('defunkt')
11
+ # @example Fetch all public gists
12
+ # Octokit.gists
13
+ # @see http://developer.github.com/v3/gists/#list-gists
14
+ def gists(username=nil, options={})
15
+ if username.nil?
16
+ get 'gists', options, 3
17
+ else
18
+ get "users/#{username}/gists", options, 3
19
+ end
7
20
  end
21
+ alias :list_gists :gists
8
22
 
9
- def delete_gist(gist, options={})
10
- response = delete("gists/#{Gist.new gist}", options, 3, true, true)
11
- response.status == 204
23
+ # List public gists
24
+ #
25
+ # @return [Array<Hashie::Mash>] A list of gists
26
+ # @example Fetch all public gists
27
+ # Octokit.public_gists
28
+ # @see http://developer.github.com/v3/gists/#list-gists
29
+ def public_gists(options={})
30
+ get 'gists/public', options, 3
12
31
  end
13
32
 
14
- def edit_gist(gist, options={})
15
- patch "gists/#{Gist.new gist}", options, 3
33
+ # List the authenticated user’s starred gists
34
+ #
35
+ # @return [Array<Hashie::Mash>] A list of gists
36
+ def starred_gists(options={})
37
+ get 'gists/starred', options, 3
16
38
  end
17
39
 
40
+ # Get a single gist
41
+ #
42
+ # @param gist [String] ID of gist to fetch
43
+ # @return [Hash::Mash] Gist information
44
+ # @see http://developer.github.com/v3/gists/#get-a-single-gist
18
45
  def gist(gist, options={})
19
46
  get "gists/#{Gist.new gist}", options, 3
20
47
  end
21
48
 
22
- def gists(username=nil, options={})
23
- if username.nil?
24
- get 'gists', options, 3
25
- else
26
- get "users/#{username}/gists", options, 3
27
- end
49
+ # Create a gist
50
+ #
51
+ # @param options [Hash] Gist information.
52
+ # @option options [String] :description
53
+ # @option options [Boolean] :public Sets gist visibility
54
+ # @option options [Array<Hash>] :files Files that make up this gist. Keys
55
+ # should be the filename, the value a Hash with a :content key with text
56
+ # conent of the Gist.
57
+ # @return [Hashie::Mash] Newly created gist info
58
+ # @see http://developer.github.com/v3/gists/#create-a-gist
59
+ def create_gist(options={})
60
+ post 'gists', options, 3
28
61
  end
29
62
 
30
- # Returns +true+ if +gist+ is starred, +false+ otherwise.
63
+ # Edit a gist
64
+ #
65
+ # @param options [Hash] Gist information.
66
+ # @option options [String] :description
67
+ # @option options [Boolean] :public Sets gist visibility
68
+ # @option options [Array<Hash>] :files Files that make up this gist. Keys
69
+ # should be the filename, the value a Hash with a :content key with text
70
+ # conent of the Gist.
71
+ #
72
+ # NOTE: All files from the previous version of the
73
+ # gist are carried over by default if not included in the hash. Deletes
74
+ # can be performed by including the filename with a null hash.
75
+ # @return
76
+ # [Hashie::Mash] Newly created gist info
77
+ # @see http://developer.github.com/v3/gists/#edit-a-gist
78
+ def edit_gist(gist, options={})
79
+ patch "gists/#{Gist.new gist}", options, 3
80
+ end
81
+ #
82
+ # Star a gist
83
+ #
84
+ # @param gist [String] Gist ID
85
+ # @return [Boolean] Indicates if gist is starred successfully
86
+ # @see http://developer.github.com/v3/gists/#star-a-gist
87
+ def star_gist(gist, options={})
88
+ response = put("gists/#{Gist.new gist}/star", options, 3, true, true)
89
+ response.status == 204
90
+ end
91
+
92
+ # Unstar a gist
93
+ #
94
+ # @param gist [String] Gist ID
95
+ # @return [Boolean] Indicates if gist is unstarred successfully
96
+ # @see http://developer.github.com/v3/gists/#unstar-a-gist
97
+ def unstar_gist(gist, options={})
98
+ response = delete("gists/#{Gist.new gist}/star", options, 3, true, true)
99
+ response.status == 204
100
+ end
101
+
102
+ # Check if a gist is starred
103
+ #
104
+ # @param gist [String] Gist ID
105
+ # @return [Boolean] Indicates if gist is starred
106
+ # @see http://developer.github.com/v3/gists/#check-if-a-gist-is-starred
31
107
  def gist_starred?(gist, options={})
32
108
  begin
33
109
  get("gists/#{Gist.new gist}/star", options, 3, true, true)
@@ -37,27 +113,22 @@ module Octokit
37
113
  end
38
114
  end
39
115
 
116
+ # Fork a gist
117
+ #
118
+ # @param gist [String] Gist ID
119
+ # @return [Hashie::Mash] Data for the new gist
120
+ # @see http://developer.github.com/v3/gists/#fork-a-gist
40
121
  def fork_gist(gist, options={})
41
122
  post "gists/#{Gist.new gist}/fork", options, 3
42
123
  end
43
124
 
44
- def public_gists(options={})
45
- get 'gists', options, 3
46
- end
47
-
48
- def starred_gists(options={})
49
- get 'gists/starred', options, 3
50
- end
51
-
52
- # Returns +true+ or +false+ based on success.
53
- def star_gist(gist, options={})
54
- response = put("gists/#{Gist.new gist}/star", options, 3, true, true)
55
- response.status == 204
56
- end
57
-
58
- # Returns +true+ or +false+ based on success.
59
- def unstar_gist(gist, options={})
60
- response = delete("gists/#{Gist.new gist}/star", options, 3, true, true)
125
+ # Delete a gist
126
+ #
127
+ # @param gist [String] Gist ID
128
+ # @return [Boolean] Indicating success of deletion
129
+ # @see http://developer.github.com/v3/gists/#delete-a-gist
130
+ def delete_gist(gist, options={})
131
+ response = delete("gists/#{Gist.new gist}", options, 3, true, true)
61
132
  response.status == 204
62
133
  end
63
134
 
@@ -15,13 +15,14 @@ module Octokit
15
15
  get("legacy/issues/search/#{Repository.new(repo)}/#{state}/#{search_term}", options, 3)['issues']
16
16
  end
17
17
 
18
- # List issues for a repository
18
+ # List issues for a the authenticated user or repository
19
19
  #
20
20
  # @param repository [String, Repository, Hash] A GitHub repository.
21
21
  # @param options [Hash] A customizable set of options.
22
22
  # @option options [Integer] :milestone Milestone number.
23
23
  # @option options [String] :state (open) State: <tt>open</tt> or <tt>closed</tt>.
24
24
  # @option options [String] :assignee User login.
25
+ # @option options [String] :creator User login.
25
26
  # @option options [String] :mentioned User login.
26
27
  # @option options [String] :labels List of comma separated Label names. Example: <tt>bug,ui,@high</tt>.
27
28
  # @option options [String] :sort (created) Sort: <tt>created</tt>, <tt>updated</tt>, or <tt>comments</tt>.
@@ -31,8 +32,14 @@ module Octokit
31
32
  # @see http://developer.github.com/v3/issues/#list-issues-for-this-repository
32
33
  # @example List issues for a repository
33
34
  # Octokit.list_issues("sferik/rails_admin")
34
- def list_issues(repository, options={})
35
- get("repos/#{Repository.new(repository)}/issues", options, 3)
35
+ # @example List issues for the authenticted user across repositories
36
+ # @client = Octokit::Client.new(:login => 'foo', :password => 'bar')
37
+ # @client.list_issues
38
+ def list_issues(repository = nil, options={})
39
+ path = ''
40
+ path = "repos/#{Repository.new(repository)}" if repository
41
+ path += "/issues"
42
+ get(path, options, 3)
36
43
  end
37
44
  alias :issues :list_issues
38
45
 
@@ -22,7 +22,12 @@ module Octokit
22
22
  alias :list_orgs :organizations
23
23
  alias :orgs :organizations
24
24
 
25
- def organization_repositories(org=nil, options={})
25
+ # List organization repositories
26
+ #
27
+ # @see http://developer.github.com/v3/repos/#list-organization-repositories
28
+ # @param org [String] Organization handle for which to list repos
29
+ # @return [Array<Hashie::Mash>] List of repositories
30
+ def organization_repositories(org, options={})
26
31
  get("orgs/#{org}/repos", options, 3)
27
32
  end
28
33
  alias :org_repositories :organization_repositories
@@ -1,6 +1,43 @@
1
1
  module Octokit
2
2
  class Client
3
3
  module Pulls
4
+ # List pull requests for a repository
5
+ #
6
+ # @see http://developer.github.com/v3/pulls/#list-pull-requests
7
+ # @param repo [String, Hash, Repository] A GitHub repository
8
+ # @param options [Hash] Method options
9
+ # @option options [String] :state `open` or `closed`. Default is `open`.
10
+ # @return [Array<Hashie::Mash>] Array of pulls
11
+ # @example
12
+ # Octokit.pull_requests('rails/rails')
13
+ def pull_requests(repo, state='open', options={})
14
+ get("repos/#{Repository.new(repo)}/pulls", options.merge({:state => state}), 3)
15
+ end
16
+ alias :pulls :pull_requests
17
+
18
+ # Get a pull request
19
+ #
20
+ # @see http://developer.github.com/v3/pulls/#get-a-single-pull-request
21
+ # @param repo [String, Hash, Repository] A GitHub repository
22
+ # @param number [Integer] Number of the pull request to fetch
23
+ # @return [Hashie::Mash] Pull request info
24
+ def pull_request(repo, number, options={})
25
+ get("repos/#{Repository.new(repo)}/pulls/#{number}", options)
26
+ end
27
+ alias :pull :pull_request
28
+
29
+ # Create a pull request
30
+ #
31
+ # @see http://developer.github.com/v3/pulls/#create-a-pull-request
32
+ # @param repo [String, Hash, Repository] A GitHub repository
33
+ # @param base [String] The branch (or git ref) you want your changes
34
+ # pulled into. This should be an existing branch on the current
35
+ # repository. You cannot submit a pull request to one repo that requests
36
+ # a merge to a base of another repo.
37
+ # @param head [String] The branch (or git ref) where your changes are implemented.
38
+ # @param title [String] Title for the pull request
39
+ # @param body [String] The body for the pull request. Supports GFM.
40
+ # @return [Hashie::Mash] The newly created pull request
4
41
  def create_pull_request(repo, base, head, title, body, options={})
5
42
  pull = {
6
43
  :base => base,
@@ -11,6 +48,17 @@ module Octokit
11
48
  post("repos/#{Repository.new(repo)}/pulls", options.merge(pull))
12
49
  end
13
50
 
51
+ # Create a pull request from existing issue
52
+ #
53
+ # @see http://developer.github.com/v3/pulls/#alternative-input
54
+ # @param repo [String, Hash, Repository] A GitHub repository
55
+ # @param base [String] The branch (or git ref) you want your changes
56
+ # pulled into. This should be an existing branch on the current
57
+ # repository. You cannot submit a pull request to one repo that requests
58
+ # a merge to a base of another repo.
59
+ # @param head [String] The branch (or git ref) where your changes are implemented.
60
+ # @param issue [Integer] Number of Issue on which to base this pull request
61
+ # @return [Hashie::Mash] The newly created pull request
14
62
  def create_pull_request_for_issue(repo, base, head, issue, options={})
15
63
  pull = {
16
64
  :base => base,
@@ -20,24 +68,69 @@ module Octokit
20
68
  post("repos/#{Repository.new(repo)}/pulls", options.merge(pull))
21
69
  end
22
70
 
23
- def pull_requests(repo, state='open', options={})
24
- get("repos/#{Repository.new(repo)}/pulls", options.merge({:state => state}), 3)
25
- end
26
- alias :pulls :pull_requests
27
-
28
- def pull_request(repo, number, options={})
29
- get("repos/#{Repository.new(repo)}/pulls/#{number}", options)
30
- end
31
- alias :pull :pull_request
32
71
 
72
+ # List commits on a pull request
73
+ #
74
+ # @see http://developer.github.com/v3/pulls/#list-commits-on-a-pull-request
75
+ # @param repo [String, Hash, Repository] A GitHub repository
76
+ # @param number [Integer] Number of pull request
77
+ # @return [Array<Hashie::Mash>] List of commits
33
78
  def pull_request_commits(repo, number, options={})
34
79
  get("repos/#{Repository.new(repo)}/pulls/#{number}/commits", options)
35
80
  end
36
81
  alias :pull_commits :pull_request_commits
37
82
 
83
+ # List comments on a pull request
84
+ #
85
+ # @see http://developer.github.com/v3/pulls/#list-comments-on-a-pull-request
86
+ # @param repo [String, Hash, Repository] A GitHub repository
87
+ # @param number [Integer] Number of pull request
88
+ # @return [Array<Hashie::Mash>] List of comments
89
+ def pull_request_comments(repo, number, options={})
90
+ # return the comments for a pull request
91
+ get("repos/#{Repository.new(repo)}/pulls/#{number}/comments", options)
92
+ end
93
+ alias :pull_comments :pull_request_comments
94
+ alias :review_comments :pull_request_comments
95
+
96
+ # List files on a pull request
97
+ #
98
+ # @see http://developer.github.com/v3/pulls/#list-files-on-a-pull-request
99
+ # @param repo [String, Hash, Repository] A GitHub repository
100
+ # @param number [Integer] Number of pull request
101
+ # @return [Array<Hashie::Mash>] List of files
102
+ def pull_request_files(repo, number, options={})
103
+ get("repos/#{Repository.new(repo)}/pulls/#{number}/files", options)
104
+ end
105
+ alias :pull_files :pull_request_files
106
+
107
+ # Merge a pull request
108
+ #
109
+ # @see http://developer.github.com/v3/pulls/#merge-a-pull-request-merge-buttontrade
110
+ # @param repo [String, Hash, Repository] A GitHub repository
111
+ # @param number [Integer] Number of pull request
112
+ # @param commit_message [String] Optional commit message for the merge commit
113
+ # @return [Array<Hashie::Mash>] Merge commit info if successful
38
114
  def merge_pull_request(repo, number, commit_message='', options={})
39
115
  put("repos/#{Repository.new(repo)}/pulls/#{number}/merge", options.merge({:commit_message => commit_message}))
40
116
  end
117
+
118
+ # Check pull request merge status
119
+ #
120
+ # @see http://developer.github.com/v3/pulls/#get-if-a-pull-request-has-been-merged
121
+ # @param repo [String, Hash, Repository] A GitHub repository
122
+ # @param number [Integer] Number of pull request
123
+ # @return [Boolean] True if the pull request has been merged
124
+ def pull_merged?(repo, number, options={})
125
+ begin
126
+ get("repos/#{Repository.new(repo)}/pulls/#{number}/merged", options)
127
+ return true
128
+ rescue Octokit::NotFound
129
+ return false
130
+ end
131
+ end
132
+ alias :pull_request_merged? :pull_merged?
133
+
41
134
  end
42
135
  end
43
136
  end
@@ -1,16 +1,40 @@
1
1
  module Octokit
2
2
  class Client
3
3
  module Repositories
4
+
5
+ # Legacy repository search
6
+ #
7
+ # @see http://developer.github.com/v3/search/#search-repositories
8
+ # @param q [String] Search keyword
9
+ # @return [Array<Hashie::Mash>] List of repositories found
4
10
  def search_repositories(q, options={})
5
11
  get("legacy/repos/search/#{q}", options, 3)['repositories']
6
12
  end
7
13
  alias :search_repos :search_repositories
8
14
 
15
+ # Get a single repository
16
+ #
17
+ # @see http://developer.github.com/v3/repos/#get
18
+ # @param repo [String, Hash, Repository] A GitHub repository
19
+ # @return [Hashie::Mash] Repository information
9
20
  def repository(repo, options={})
10
21
  get "repos/#{Repository.new repo}", options, 3
11
22
  end
12
23
  alias :repo :repository
13
24
 
25
+ # Edit a repository
26
+ #
27
+ # @see http://developer.github.com/v3/repos/#edit
28
+ # @param repo [String, Hash, Repository] A GitHub repository
29
+ # @param options [Hash] Repository information to update
30
+ # @option options [String] :name Name of the repo
31
+ # @option options [String] :description Description of the repo
32
+ # @option options [String] :homepage Home page of the repo
33
+ # @option options [String] :private `true` makes the repository private, and `false` makes it public.
34
+ # @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
35
+ # @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
36
+ # @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
37
+ # @return [Hashie::Mash] Repository information
14
38
  def edit_repository(repo, options={})
15
39
  patch "repos/#{Repository.new repo}", options, 3
16
40
  end
@@ -18,6 +42,14 @@ module Octokit
18
42
  alias :update_repository :edit_repository
19
43
  alias :update :edit_repository
20
44
 
45
+ # List repositories
46
+ #
47
+ # If username is not supplied, repositories for the current
48
+ # authenticated user are returned
49
+ #
50
+ # @see http://developer.github.com/v3/repos/#list-your-repositories
51
+ # @param username [String] Optional username for which to list repos
52
+ # @return [Array<Hashie::Mash>] List of repositories
21
53
  def repositories(username=nil, options={})
22
54
  if username.nil?
23
55
  get 'user/repos', options, 3
@@ -29,18 +61,83 @@ module Octokit
29
61
  alias :list_repos :repositories
30
62
  alias :repos :repositories
31
63
 
64
+ # Star a repository
65
+ #
66
+ # @param repo [String, Hash, Repository] A GitHub repository
67
+ # @return [Boolean] `true` if successfully starred
68
+ def star(repo, options={})
69
+ begin
70
+ put "user/starred/#{Repository.new repo}", options, 3
71
+ return true
72
+ rescue Octokit::NotFound
73
+ return false
74
+ end
75
+ end
76
+
77
+ # Unstar a repository
78
+ #
79
+ # @param repo [String, Hash, Repository] A GitHub repository
80
+ # @return [Boolean] `true` if successfully unstarred
81
+ def unstar(repo, options={})
82
+ begin
83
+ delete "user/starred/#{Repository.new repo}", options, 3
84
+ return true
85
+ rescue Octokit::NotFound
86
+ return false
87
+ end
88
+ end
89
+
90
+ # Watch a repository
91
+ #
92
+ # @param repo [String, Hash, Repository] A GitHub repository
93
+ # @return [Boolean] `true` if successfully watched
94
+ # @deprecated Use #star instead
32
95
  def watch(repo, options={})
33
- put "user/watched/#{Repository.new repo}", options, 3
96
+ begin
97
+ put "user/watched/#{Repository.new repo}", options, 3
98
+ return true
99
+ rescue Octokit::NotFound
100
+ return false
101
+ end
34
102
  end
35
103
 
104
+ # Unwatch a repository
105
+ #
106
+ # @param repo [String, Hash, Repository] A GitHub repository
107
+ # @return [Boolean] `true` if successfully unwatched
108
+ # @deprecated Use #unstar instead
36
109
  def unwatch(repo, options={})
37
- delete "user/watched/#{Repository.new repo}", options, 3
110
+ begin
111
+ delete "user/watched/#{Repository.new repo}", options, 3
112
+ return true
113
+ rescue Octokit::NotFound
114
+ return false
115
+ end
38
116
  end
39
117
 
118
+ # Fork a repository
119
+ #
120
+ # @param repo [String, Hash, Repository] A GitHub repository
121
+ # @return [Hashie::Mash] Repository info for the new fork
40
122
  def fork(repo, options={})
41
123
  post "repos/#{Repository.new repo}/forks", options, 3
42
124
  end
43
125
 
126
+ # Create a repository for a user or organization
127
+ #
128
+ # @param name [String] Name of the new repo
129
+ # @option options [String] :description Description of the repo
130
+ # @option options [String] :homepage Home page of the repo
131
+ # @option options [String] :private `true` makes the repository private, and `false` makes it public.
132
+ # @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
133
+ # @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
134
+ # @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
135
+ # @option options [String] :organization Short name for the org under which to create the repo.
136
+ # @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.
137
+ # @option options [Boolean] :auto_init `true` to create an initial commit with empty README. Default is `false`.
138
+ # @option options [String] :gitignore_template Desired language or platform .gitignore template to apply. Ignored if auto_init parameter is not provided.
139
+ # @return [Hashie::Mash] Repository info for the new repository
140
+ # @see http://developer.github.com/v3/repos/#create
44
141
  def create_repository(name, options={})
45
142
  organization = options.delete :organization
46
143
  options.merge! :name => name
@@ -54,16 +151,36 @@ module Octokit
54
151
  alias :create_repo :create_repository
55
152
  alias :create :create_repository
56
153
 
154
+ # Delete repository
155
+ #
156
+ # Note: If OAuth is used, 'delete_repo' scope is required
157
+ #
158
+ # @see http://developer.github.com/v3/repos/#delete-a-repository
159
+ # @param repo [String, Hash, Repository] A GitHub repository
160
+ # @return [Boolean] `true` if repository was deleted
57
161
  def delete_repository(repo, options={})
58
- delete "repos/#{Repository.new repo}", options, 3
162
+ begin
163
+ delete "repos/#{Repository.new repo}", options, 3
164
+ return true
165
+ rescue Octokit::NotFound
166
+ return false
167
+ end
59
168
  end
60
169
  alias :delete_repo :delete_repository
61
170
 
171
+ # Hide a public repository
172
+ #
173
+ # @param repo [String, Hash, Repository] A GitHub repository
174
+ # @return [Hashie::Mash] Updated repository info
62
175
  def set_private(repo, options={})
63
176
  # GitHub Api for setting private updated to use private attr, rather than public
64
177
  update_repository repo, options.merge({ :private => true })
65
178
  end
66
179
 
180
+ # Unhide a private repository
181
+ #
182
+ # @param repo [String, Hash, Repository] A GitHub repository
183
+ # @return [Hashie::Mash] Updated repository info
67
184
  def set_public(repo, options={})
68
185
  # GitHub Api for setting private updated to use private attr, rather than public
69
186
  update_repository repo, options.merge({ :private => false })
@@ -108,6 +225,10 @@ module Octokit
108
225
  end
109
226
  alias :contribs :contributors
110
227
 
228
+ def stargazers(repo, options={})
229
+ get "repos/#{Repository.new repo}/stargazers", options, 3
230
+ end
231
+
111
232
  def watchers(repo, options={})
112
233
  get "repos/#{Repository.new repo}/watchers", options, 3
113
234
  end
@@ -63,6 +63,16 @@ module Octokit
63
63
  delete("user/following/#{user}", options, 3, true, raw=true).status == 204
64
64
  end
65
65
 
66
+ def starred(user=login, options={})
67
+ get("users/#{user}/starred", options, 3)
68
+ end
69
+
70
+ def starred?(user, repo, options={})
71
+ get("user/starred/#{user}/#{repo}", options, 3, true, raw=true).status == 204
72
+ rescue Octokit::NotFound
73
+ false
74
+ end
75
+
66
76
  def watched(user=login, options={})
67
77
  get("users/#{user}/watched", options, 3)
68
78
  end
@@ -5,6 +5,7 @@ module Octokit
5
5
  module Configuration
6
6
  VALID_OPTIONS_KEYS = [
7
7
  :adapter,
8
+ :faraday_config_block,
8
9
  :api_version,
9
10
  :api_endpoint,
10
11
  :web_endpoint,
@@ -15,6 +16,7 @@ module Octokit
15
16
  :client_id,
16
17
  :client_secret,
17
18
  :user_agent,
19
+ :request_host,
18
20
  :auto_traversal,
19
21
  :per_page].freeze
20
22
 
@@ -47,6 +49,10 @@ module Octokit
47
49
  @web_endpoint = File.join(value, "")
48
50
  end
49
51
 
52
+ def faraday_config(&block)
53
+ @faraday_config_block = block
54
+ end
55
+
50
56
  def reset
51
57
  self.adapter = DEFAULT_ADAPTER
52
58
  self.api_version = DEFAULT_API_VERSION
@@ -58,6 +64,7 @@ module Octokit
58
64
  self.oauth_token = nil
59
65
  self.client_id = nil
60
66
  self.client_secret = nil
67
+ self.request_host = nil
61
68
  self.user_agent = DEFAULT_USER_AGENT
62
69
  self.auto_traversal = DEFAULT_AUTO_TRAVERSAL
63
70
  end