octokit 2.7.2 → 3.0.0.pre

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bb0abde4b6ce638afc6c962f04dbee820d5af42
4
- data.tar.gz: a7bbbfa2fa6f2654736ea7a403af7f348323ea39
3
+ metadata.gz: ba2a0b7ef2fe7ccfc4d47d20101e1bf1df5352b6
4
+ data.tar.gz: 00d6d398a4682911be8b46d7cc0e0a5320afbdd4
5
5
  SHA512:
6
- metadata.gz: 34a5e2a2dc261137f83b151593ab573455e7b60fefeb35c90bb6ab7c971797433f84d897f34e2c0924c8b5ce8d59662c35f584c28f2b3e884133d18b551bb995
7
- data.tar.gz: a00b6f83733e4ac7abe948748f53d370546bcb02bced8b30adc77322418d17cfa3a5d496b1b20f0ba2df22b30f942f6f3038c2b9faef1d7c53df985e5d52f068
6
+ metadata.gz: d754b8c098880c8e738ba09b2c96db93e5ec70961cb8b3a9b20876ebf6f3034f70f662bf63f6268f596d5aaa740c6fb06996db714148319a1e20d95028ba4f9d
7
+ data.tar.gz: 8c164081ca60967730307c8d98dd1822cb0bc3ada9876cd192ca39d9ac790881e7424f53b1762929b64078bd374211d215a5c0ee65708c64c68fbe122ee70dd1
data/CONTRIBUTING.md CHANGED
@@ -9,11 +9,12 @@
9
9
  5. Implement your feature or bug fix.
10
10
  6. Run `script/test`. If your specs fail, return to step 5.
11
11
  7. Run `open coverage/index.html`. If your changes are not completely covered
12
- by your tests, return to step 3.
12
+ by your tests, return to step 4.
13
13
  8. Add documentation for your feature or bug fix.
14
14
  9. Run `bundle exec rake doc:yard`. If your changes are not 100% documented, go
15
15
  back to step 8.
16
- 10. Add, commit, and push your changes.
16
+ 10. Add, commit, and push your changes. For documentation-only fixes, please
17
+ add "[ci skip]" to your commit message to avoid needless CI builds.
17
18
  11. [Submit a pull request.][pr]
18
19
 
19
20
  [fork]: https://help.github.com/articles/fork-a-repo
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2013 Wynn Netherland, Adam Stacoviak, Erik Michaels-Ober
1
+ Copyright (c) 2009-2014 Wynn Netherland, Adam Stacoviak, Erik Michaels-Ober
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -54,7 +54,7 @@ or
54
54
 
55
55
  ```ruby
56
56
  # Provide authentication credentials
57
- client = Octokit::Client.new :login => 'defunkt', :password => 'c0d3b4ssssss!'
57
+ client = Octokit::Client.new(:login => 'defunkt', :password => 'c0d3b4ssssss!')
58
58
  # Fetch the current user
59
59
  client.user
60
60
  ```
@@ -129,7 +129,7 @@ To use an access token with the Octokit client, just pass it in lieu of your
129
129
  username and password:
130
130
 
131
131
  ```ruby
132
- client = Octokit::Client.new :access_token => "<your 40 char token>"
132
+ client = Octokit::Client.new(:access_token => "<your 40 char token>")
133
133
 
134
134
  user = client.user
135
135
  user.login
@@ -141,7 +141,7 @@ that you can use for subsequent calls.
141
141
 
142
142
  ### Two-Factor Authentication
143
143
 
144
- [Two-Factor Authentication](https://help.github.com/articles/about-two-factor-authentication) brings added security to the account by requiring more information to login.
144
+ [Two-Factor Authentication](https://help.github.com/articles/about-two-factor-authentication) brings added security to the account by requiring more information to login.
145
145
 
146
146
  Using two-factor authentication for API calls is as simple as adding the [required header](http://developer.github.com/v3/auth/#working-with-two-factor-authentication) as an option:
147
147
 
@@ -177,7 +177,7 @@ machine api.github.com
177
177
  You can now create a client with those credentials:
178
178
 
179
179
  ```ruby
180
- client = Octokit::Client.new :netrc => true
180
+ client = Octokit::Client.new(:netrc => true)
181
181
  client.login
182
182
  # => "defunkt"
183
183
  ```
@@ -482,6 +482,7 @@ implementations:
482
482
  * Ruby 1.9.2
483
483
  * Ruby 1.9.3
484
484
  * Ruby 2.0.0
485
+ * Ruby 2.1.0
485
486
 
486
487
  If something doesn't work on one of these Ruby versions, it's a bug.
487
488
 
@@ -516,4 +517,24 @@ Constraint][pvc] with two digits of precision. For example:
516
517
 
517
518
  ## License
518
519
 
519
- {include:file:LICENSE.md}
520
+ Copyright (c) 2009-2014 Wynn Netherland, Adam Stacoviak, Erik Michaels-Ober
521
+
522
+ Permission is hereby granted, free of charge, to any person obtaining
523
+ a copy of this software and associated documentation files (the
524
+ "Software"), to deal in the Software without restriction, including
525
+ without limitation the rights to use, copy, modify, merge, publish,
526
+ distribute, sublicense, and/or sell copies of the Software, and to
527
+ permit persons to whom the Software is furnished to do so, subject to
528
+ the following conditions:
529
+
530
+ The above copyright notice and this permission notice shall be
531
+ included in all copies or substantial portions of the Software.
532
+
533
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
534
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
535
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
536
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
537
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
538
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
539
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
540
+
@@ -11,6 +11,7 @@ require 'octokit/client/commits'
11
11
  require 'octokit/client/commit_comments'
12
12
  require 'octokit/client/contents'
13
13
  require 'octokit/client/downloads'
14
+ require 'octokit/client/deployments'
14
15
  require 'octokit/client/emojis'
15
16
  require 'octokit/client/events'
16
17
  require 'octokit/client/feeds'
@@ -26,6 +27,7 @@ require 'octokit/client/milestones'
26
27
  require 'octokit/client/notifications'
27
28
  require 'octokit/client/objects'
28
29
  require 'octokit/client/organizations'
30
+ require 'octokit/client/pages'
29
31
  require 'octokit/client/pub_sub_hubbub'
30
32
  require 'octokit/client/pull_requests'
31
33
  require 'octokit/client/rate_limit'
@@ -52,6 +54,7 @@ module Octokit
52
54
  include Octokit::Client::Commits
53
55
  include Octokit::Client::CommitComments
54
56
  include Octokit::Client::Contents
57
+ include Octokit::Client::Deployments
55
58
  include Octokit::Client::Downloads
56
59
  include Octokit::Client::Emojis
57
60
  include Octokit::Client::Events
@@ -68,6 +71,7 @@ module Octokit
68
71
  include Octokit::Client::Notifications
69
72
  include Octokit::Client::Objects
70
73
  include Octokit::Client::Organizations
74
+ include Octokit::Client::Pages
71
75
  include Octokit::Client::PubSubHubbub
72
76
  include Octokit::Client::PullRequests
73
77
  include Octokit::Client::RateLimit
@@ -82,7 +86,7 @@ module Octokit
82
86
  include Octokit::Client::Users
83
87
 
84
88
  # Header keys that can be passed in options hash to {#get},{#head}
85
- CONVENIENCE_HEADERS = Set.new [:accept, :content_type]
89
+ CONVENIENCE_HEADERS = Set.new([:accept, :content_type])
86
90
 
87
91
  def initialize(options = {})
88
92
  # Use options passed in, but fall back to module defaults
@@ -183,7 +187,7 @@ module Octokit
183
187
  # @param block [Block] Block to perform the data concatination of the
184
188
  # multiple requests. The block is called with two parameters, the first
185
189
  # contains the contents of the requests so far and the second parameter
186
- # contains the latest response.
190
+ # contains the latest response.
187
191
  # @return [Sawyer::Resource]
188
192
  def paginate(url, options = {}, &block)
189
193
  opts = parse_query_and_convenience_headers(options.dup)
@@ -236,7 +240,7 @@ module Octokit
236
240
  #
237
241
  # @return [Sawyer::Response]
238
242
  def last_response
239
- @last_response
243
+ @last_response if defined? @last_response
240
244
  end
241
245
 
242
246
  private
@@ -254,7 +258,7 @@ module Octokit
254
258
  options[:query].merge! application_authentication
255
259
  end
256
260
 
257
- @last_response = response = agent.call(method, URI.encode(path.to_s), data, options)
261
+ @last_response = response = agent.call(method, URI::Parser.new.escape(path.to_s), data, options)
258
262
  response.data
259
263
  end
260
264
 
@@ -3,7 +3,7 @@ module Octokit
3
3
 
4
4
  # Methods for the Authorizations API
5
5
  #
6
- # @see http://developer.github.com/v3/oauth/#oauth-authorizations-api
6
+ # @see http://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api
7
7
  module Authorizations
8
8
 
9
9
  # List the authenticated user's authorizations
@@ -13,7 +13,7 @@ module Octokit
13
13
  # Basic Authentication.
14
14
  #
15
15
  # @return [Array<Sawyer::Resource>] A list of authorizations for the authenticated user
16
- # @see http://developer.github.com/v3/oauth/#list-your-authorizations
16
+ # @see http://developer.github.com/v3/oauth_authorizations/#list-your-authorizations
17
17
  # @example List authorizations for user ctshryock
18
18
  # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
19
19
  # client.authorizations
@@ -27,7 +27,7 @@ module Octokit
27
27
  # Basic Authentication.
28
28
  #
29
29
  # @return [Sawyer::Resource] A single authorization for the authenticated user
30
- # @see http://developer.github.com/v3/oauth/#get-a-single-authorization
30
+ # @see http://developer.github.com/v3/oauth_authorizations/#get-a-single-authorization
31
31
  # @example Show authorization for user ctshryock's Travis auth
32
32
  # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
33
33
  # client.authorization(999999)
@@ -50,7 +50,7 @@ module Octokit
50
50
  #
51
51
  # @return [Sawyer::Resource] A single authorization for the authenticated user
52
52
  # @see http://developer.github.com/v3/oauth/#scopes Available scopes
53
- # @see http://developer.github.com/v3/oauth/#create-a-new-authorization
53
+ # @see http://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization
54
54
  # @example Create a new authorization for user ctshryock's project Zoidberg
55
55
  # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
56
56
  # client.create_authorization({:scopes => ["public_repo","gist"], :note => "Why not Zoidberg?", :note_url=> "https://en.wikipedia.org/wiki/Zoidberg"})
@@ -84,7 +84,7 @@ module Octokit
84
84
  # @option options [String] :note_url A URL to remind you what app the OAuth token is for.
85
85
  #
86
86
  # @return [Sawyer::Resource] A single (updated) authorization for the authenticated user
87
- # @see http://developer.github.com/v3/oauth/#update-a-new-authorization
87
+ # @see http://developer.github.com/v3/oauth_authorizations/#update-an-existing-authorization
88
88
  # @see http://developer.github.com/v3/oauth/#scopes for available scopes
89
89
  # @example Update the authorization for user ctshryock's project Zoidberg
90
90
  # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
@@ -101,7 +101,7 @@ module Octokit
101
101
  # @param number [Number] An existing Authorization ID
102
102
  #
103
103
  # @return [Boolean] Success
104
- # @see http://developer.github.com/v3/oauth/#delete-an-authorization
104
+ # @see http://developer.github.com/v3/oauth_authorizations/#delete-an-authorization
105
105
  # @example Delete an authorization
106
106
  # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
107
107
  # client.delete_authorization(999999)
@@ -138,13 +138,7 @@ module Octokit
138
138
  # @see http://developer.github.com/v3/oauth/#web-application-flow
139
139
  # @example
140
140
  # @client.authorize_url('xxxx')
141
- def authorize_url(*args)
142
- arguments = Arguments.new(args)
143
- options = arguments.options
144
- app_id = arguments.shift || client_id
145
- if app_secret = arguments.shift
146
- warn "client_secret is not required for this method"
147
- end
141
+ def authorize_url(app_id = client_id, options = {})
148
142
  authorize_url = options.delete(:endpoint) || Octokit.web_endpoint
149
143
  authorize_url += "login/oauth/authorize?client_id=" + app_id
150
144
 
@@ -46,16 +46,16 @@ module Octokit
46
46
  # @return [Sawyer::Resource] Commit comment
47
47
  # @see http://developer.github.com/v3/repos/comments/#create-a-commit-comment
48
48
  # @example Create a commit comment
49
- # commit = Octokit.create_commit_comment("octocat/Hello-World", "827efc6d56897b048c772eb4087f854f46256132", "My comment message", "README.md", 10, 1)
50
- # commit.commit_id # => "827efc6d56897b048c772eb4087f854f46256132"
51
- # commit.body # => "My comment message"
52
- # commit.path # => "README.md"
53
- # commit.line # => 10
54
- # commit.position # => 1
49
+ # comment = Octokit.create_commit_comment("octocat/Hello-World", "827efc6d56897b048c772eb4087f854f46256132", "My comment message", "README.md", 10, 1)
50
+ # comment.commit_id # => "827efc6d56897b048c772eb4087f854f46256132"
51
+ # comment.id # => 54321
52
+ # comment.body # => "My comment message"
53
+ # comment.path # => "README.md"
54
+ # comment.line # => 10
55
+ # comment.position # => 1
55
56
  def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, options = {})
56
57
  params = {
57
58
  :body => body,
58
- :commit_id => sha,
59
59
  :path => path,
60
60
  :line => line,
61
61
  :position => position
@@ -71,9 +71,9 @@ module Octokit
71
71
  # @return [Sawyer::Resource] Updated commit comment
72
72
  # @see http://developer.github.com/v3/repos/comments/#update-a-commit-comment
73
73
  # @example Update a commit comment
74
- # commit = Octokit.update_commit_comment("octocat/Hello-World", "860296", "Updated commit comment")
75
- # commit.id # => 860296
76
- # commit.body # => "Updated commit comment"
74
+ # comment = Octokit.update_commit_comment("octocat/Hello-World", "860296", "Updated commit comment")
75
+ # comment.id # => 860296
76
+ # comment.body # => "Updated commit comment"
77
77
  def update_commit_comment(repo, id, body, options = {})
78
78
  params = {
79
79
  :body => body
@@ -50,7 +50,6 @@ module Octokit
50
50
  arguments = Octokit::RepoArguments.new(args)
51
51
  date = parse_date(arguments.shift)
52
52
  params = arguments.options
53
- end_date = date + 1
54
53
  params.merge!(:since => iso8601(date))
55
54
  sha_or_branch = arguments.pop
56
55
  if sha_or_branch
@@ -77,7 +76,6 @@ module Octokit
77
76
  arguments = Octokit::RepoArguments.new(args)
78
77
  date = parse_date(arguments.shift)
79
78
  params = arguments.options
80
- end_date = date + 1
81
79
  params.merge!(:until => iso8601(date))
82
80
  sha_or_branch = arguments.pop
83
81
  if sha_or_branch
@@ -189,91 +187,6 @@ module Octokit
189
187
  post "repos/#{Repository.new(repo)}/git/commits", options.merge(params)
190
188
  end
191
189
 
192
- # List all commit comments
193
- #
194
- # @param repo [String, Hash, Repository] A GitHub repository
195
- # @return [Array] An array of hashes representing comments
196
- # @see http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository
197
- def list_commit_comments(repo, options = {})
198
- get "repos/#{Repository.new(repo)}/comments", options
199
- end
200
-
201
- # List comments for a single commit
202
- #
203
- # @param repo [String, Hash, Repository] A GitHub repository
204
- # @param sha [String] The SHA of the commit whose comments will be fetched
205
- # @return [Array] An array of hashes representing comments
206
- # @see http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit
207
- def commit_comments(repo, sha, options = {})
208
- get "repos/#{Repository.new(repo)}/commits/#{sha}/comments", options
209
- end
210
-
211
- # Get a single commit comment
212
- #
213
- # @param repo [String, Hash, Repository] A GitHub repository
214
- # @param id [String] The ID of the comment to fetch
215
- # @return [Sawyer::Resource] A hash representing the comment
216
- # @see http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment
217
- def commit_comment(repo, id, options = {})
218
- get "repos/#{Repository.new(repo)}/comments/#{id}", options
219
- end
220
-
221
- # Create a commit comment
222
- #
223
- # @param repo [String, Hash, Repository] A GitHub repository
224
- # @param sha [String] Sha of the commit to comment on
225
- # @param body [String] Message
226
- # @param path [String] Relative path of file to comment on
227
- # @param line [Integer] Line number in the file to comment on
228
- # @param position [Integer] Line index in the diff to comment on
229
- # @return [Sawyer::Resource] A hash representing the new commit comment
230
- # @see http://developer.github.com/v3/repos/comments/#create-a-commit-comment
231
- # @example Create a commit comment
232
- # commit = Octokit.create_commit_comment("octocat/Hello-World", "827efc6d56897b048c772eb4087f854f46256132", "My comment message", "README.md", 10, 1)
233
- # commit.commit_id # => "827efc6d56897b048c772eb4087f854f46256132"
234
- # commit.body # => "My comment message"
235
- # commit.path # => "README.md"
236
- # commit.line # => 10
237
- # commit.position # => 1
238
- def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, options = {})
239
- params = {
240
- :body => body,
241
- :commit_id => sha,
242
- :path => path,
243
- :line => line,
244
- :position => position
245
- }
246
- post "repos/#{Repository.new(repo)}/commits/#{sha}/comments", options.merge(params)
247
- end
248
-
249
- # Update a commit comment
250
- #
251
- # @param repo [String, Hash, Repository] A GitHub repository
252
- # @param id [String] The ID of the comment to update
253
- # @param body [String] Message
254
- # @return [Sawyer::Resource] A hash representing the updated commit comment
255
- # @see http://developer.github.com/v3/repos/comments/#update-a-commit-comment
256
- # @example Update a commit comment
257
- # commit = Octokit.update_commit_comment("octocat/Hello-World", "860296", "Updated commit comment")
258
- # commit.id # => 860296
259
- # commit.body # => "Updated commit comment"
260
- def update_commit_comment(repo, id, body, options = {})
261
- params = {
262
- :body => body
263
- }
264
- patch "repos/#{Repository.new(repo)}/comments/#{id}", options.merge(params)
265
- end
266
-
267
- # Delete a commit comment
268
- #
269
- # @param repo [String, Hash, Repository] A GitHub repository
270
- # @param id [String] The ID of the comment to delete
271
- # @return [nil] nil
272
- # @see http://developer.github.com/v3/repos/comments/#delete-a-commit-comment
273
- def delete_commit_comment(repo, id, options = {})
274
- boolean_from_response :delete, "repos/#{Repository.new(repo)}/comments/#{id}", options
275
- end
276
-
277
190
  # Compare two commits
278
191
  #
279
192
  # @param repo [String, Hash, Repository] A GitHub repository
@@ -17,7 +17,7 @@ module Octokit
17
17
  # @example Get the readme file for a repo
18
18
  # Octokit.readme("octokit/octokit.rb")
19
19
  def readme(repo, options={})
20
- get "repos/#{Repository.new repo}/readme", options
20
+ get "repos/#{Repository.new(repo)}/readme", options
21
21
  end
22
22
 
23
23
  # Receive a listing of a repository folder or the contents of a file
@@ -31,7 +31,7 @@ module Octokit
31
31
  # Octokit.contents("octokit/octokit.rb", :path => 'lib/octokit.rb')
32
32
  def contents(repo, options={})
33
33
  repo_path = options.delete :path
34
- url = "repos/#{Repository.new repo}/contents/#{repo_path}"
34
+ url = "repos/#{Repository.new(repo)}/contents/#{repo_path}"
35
35
  get url, options
36
36
  end
37
37
  alias :content :contents
@@ -62,7 +62,7 @@ module Octokit
62
62
  if content.nil? && file = options.delete(:file)
63
63
  case file
64
64
  when String
65
- if File.exists?(file)
65
+ if File.exist?(file)
66
66
  file = File.open(file, "r")
67
67
  content = file.read
68
68
  file.close
@@ -72,12 +72,12 @@ module Octokit
72
72
  file.close
73
73
  end
74
74
  end
75
- raise ArgumentError.new "content or :file option required" if content.nil?
75
+ raise ArgumentError.new("content or :file option required") if content.nil?
76
76
  options[:content] = Base64.respond_to?(:strict_encode64) ?
77
77
  Base64.strict_encode64(content) :
78
78
  Base64.encode64(content).delete("\n") # Ruby 1.9.2
79
79
  options[:message] = message
80
- url = "repos/#{Repository.new repo}/contents/#{path}"
80
+ url = "repos/#{Repository.new(repo)}/contents/#{path}"
81
81
  put url, options
82
82
  end
83
83
  alias :create_content :create_contents
@@ -133,7 +133,7 @@ module Octokit
133
133
  def delete_contents(repo, path, message, sha, options = {})
134
134
  options[:message] = message
135
135
  options[:sha] = sha
136
- url = "repos/#{Repository.new repo}/contents/#{path}"
136
+ url = "repos/#{Repository.new(repo)}/contents/#{path}"
137
137
  delete url, options
138
138
  end
139
139
  alias :delete_content :delete_contents
@@ -152,7 +152,7 @@ module Octokit
152
152
  def archive_link(repo, options={})
153
153
  repo_ref = options.delete :ref
154
154
  format = (options.delete :format) || 'tarball'
155
- url = "repos/#{Repository.new repo}/#{format}/#{repo_ref}"
155
+ url = "repos/#{Repository.new(repo)}/#{format}/#{repo_ref}"
156
156
  request :head, url, options
157
157
 
158
158
  last_response.headers['Location']
@@ -0,0 +1,83 @@
1
+ module Octokit
2
+ class Client
3
+
4
+ # Methods for the Deployments API
5
+ #
6
+ # @see http://developer.github.com/v3/repos/commits/deployments/
7
+ module Deployments
8
+
9
+ DEPLOYMENTS_PREVIEW_MEDIA_TYPE = "application/vnd.github.cannonball-preview+json".freeze
10
+
11
+ # List all deployments for a repository
12
+ #
13
+ # @param repo [String, Repository, Hash] A GitHub repository
14
+ # @return [Array<Sawyer::Resource>] A list of deployments
15
+ # @see http://developer.github.com/v3/repos/deployments/#list-deployments
16
+ def deployments(repo, options = {})
17
+ options = ensure_deployments_api_media_type(options)
18
+ get("repos/#{Repository.new(repo)}/deployments", options)
19
+ end
20
+ alias :list_deployments :deployments
21
+
22
+ # Create a deployment for a ref
23
+ #
24
+ # @param repo [String, Repository, Hash] A GitHub repository
25
+ # @param ref [String] The ref to deploy
26
+ # @option options [String] :payload Meta info about the deployment
27
+ # @option options [String] :force Optional parameter to bypass any ahead/behind checks or commit status checks. Default: false
28
+ # @option options [String] :auto_merge Optional parameter to merge the default branch into the requested deployment branch if necessary. Default: false
29
+ # @option options [String] :description Optional short description.
30
+ # @return [Sawyer::Resource] A deployment
31
+ # @see http://developer.github.com/v3/repos/deployments/#create-a-deployment
32
+ def create_deployment(repo, ref, options = {})
33
+ options = ensure_deployments_api_media_type(options)
34
+ options[:ref] = ref
35
+ post("repos/#{Repository.new(repo)}/deployments", options)
36
+ end
37
+
38
+ # List all statuses for a Deployment
39
+ #
40
+ # @param deployment_url [String] A URL for a deployment resource
41
+ # @return [Array<Sawyer::Resource>] A list of deployment statuses
42
+ # @see http://developer.github.com/v3/repos/deployments/#list-deployment-statuses
43
+ def deployment_statuses(deployment_url, options = {})
44
+ options = ensure_deployments_api_media_type(options)
45
+ deployment = get(deployment_url, :accept => options[:accept])
46
+ get(deployment.rels[:statuses].href, options)
47
+ end
48
+ alias :list_deployment_statuses :deployment_statuses
49
+
50
+ # Create a deployment status for a Deployment
51
+ #
52
+ # @param deployment_url [String] A URL for a deployment resource
53
+ # @param state [String] The state: pending, success, failure, error
54
+ # @return [Sawyer::Resource] A deployment status
55
+ # @see http://developer.github.com/v3/repos/deployments/#create-a-deployment-status
56
+ def create_deployment_status(deployment_url, state, options = {})
57
+ options = ensure_deployments_api_media_type(options)
58
+ deployment = get(deployment_url, :accept => options[:accept])
59
+ options[:state] = state.to_s.downcase
60
+ post(deployment.rels[:statuses].href, options)
61
+ end
62
+
63
+ private
64
+
65
+ def ensure_deployments_api_media_type(options = {})
66
+ if options[:accept].nil?
67
+ options[:accept] = DEPLOYMENTS_PREVIEW_MEDIA_TYPE
68
+ warn_deployments_preview
69
+ end
70
+
71
+ options
72
+ end
73
+
74
+ def warn_deployments_preview
75
+ warn <<-EOS
76
+ WARNING: The preview version of the Deployments API is not yet suitable for production use.
77
+ You can avoid this message by supplying an appropriate media type in the 'Accept' request
78
+ header. See the blog post for details: http://git.io/o2XZRA
79
+ EOS
80
+ end
81
+ end
82
+ end
83
+ end