github_api 0.10.2 → 0.11.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/README.md +78 -59
- data/features/cassettes/repos/assets/delete.yml +52 -0
- data/features/cassettes/repos/assets/edit.yml +65 -0
- data/features/cassettes/repos/assets/get.yml +74 -0
- data/features/cassettes/repos/assets/list.yml +73 -0
- data/features/cassettes/repos/assets/upload.yml +66 -0
- data/features/cassettes/repos/list_org.yml +167 -0
- data/features/cassettes/repos/list_org_instance.yml +300 -0
- data/features/cassettes/repos/releases/create.yml +64 -0
- data/features/cassettes/repos/releases/delete.yml +52 -0
- data/features/cassettes/repos/releases/edit.yml +63 -0
- data/features/cassettes/repos/releases/get.yml +78 -0
- data/features/cassettes/repos/releases/list.yml +81 -0
- data/features/cassettes/search/code.yml +252 -0
- data/features/cassettes/search/code_query.yml +65 -0
- data/features/cassettes/search/issues.yml +616 -170
- data/features/cassettes/search/legacy/email.yml +72 -0
- data/features/cassettes/search/legacy/issues.yml +119 -0
- data/features/cassettes/search/legacy/repos.yml +394 -0
- data/features/cassettes/search/legacy/users.yml +72 -0
- data/features/cassettes/search/legacy/users_keyword.yml +63 -0
- data/features/cassettes/search/repos.yml +375 -364
- data/features/cassettes/search/users.yml +40 -22
- data/features/cassettes/search/users_keyword.yml +51 -56
- data/features/repos.feature +22 -0
- data/features/repos/assets.feature +59 -0
- data/features/repos/releases.feature +58 -0
- data/features/search.feature +24 -13
- data/features/search/legacy.feature +59 -0
- data/features/settings.yml +2 -5
- data/features/step_definitions/github_api_steps.rb +12 -0
- data/lib/github_api/configuration.rb +3 -1
- data/lib/github_api/error.rb +6 -17
- data/lib/github_api/error/unknown_media.rb +18 -0
- data/lib/github_api/params_hash.rb +20 -10
- data/lib/github_api/repos.rb +26 -15
- data/lib/github_api/repos/releases.rb +146 -0
- data/lib/github_api/repos/releases/assets.rb +126 -0
- data/lib/github_api/request.rb +14 -9
- data/lib/github_api/resource.rb +8 -1
- data/lib/github_api/search.rb +68 -27
- data/lib/github_api/search/legacy.rb +94 -0
- data/lib/github_api/ssl_certs/cacert.pem +41 -0
- data/lib/github_api/ssl_certs/cacerts.pem +2183 -0
- data/lib/github_api/version.rb +2 -2
- data/spec/fixtures/repos/asset.json +12 -0
- data/spec/fixtures/repos/assets.json +14 -0
- data/spec/fixtures/repos/release.json +15 -0
- data/spec/fixtures/repos/releases.json +17 -0
- data/spec/fixtures/search/code.json +76 -0
- data/spec/fixtures/search/issues.json +47 -16
- data/spec/fixtures/search/issues_legacy.json +23 -0
- data/spec/fixtures/search/repos.json +39 -0
- data/spec/fixtures/search/{repositories.json → repos_legacy.json} +0 -0
- data/spec/fixtures/search/users.json +15 -19
- data/spec/fixtures/search/users_legacy.json +24 -0
- data/spec/github/configuration_spec.rb +2 -0
- data/spec/github/error/unknown_media_spec.rb +21 -0
- data/spec/github/git_data/references/create_spec.rb +1 -1
- data/spec/github/git_data/references/get_spec.rb +6 -4
- data/spec/github/git_data/references/list_spec.rb +6 -16
- data/spec/github/pagination/iterator/number_spec.rb +2 -2
- data/spec/github/pagination/iterator/sha_spec.rb +2 -2
- data/spec/github/params_hash_spec.rb +6 -0
- data/spec/github/repos/assets/delete_spec.rb +40 -0
- data/spec/github/repos/assets/edit_spec.rb +40 -0
- data/spec/github/repos/assets/get_spec.rb +45 -0
- data/spec/github/repos/assets/list_spec.rb +55 -0
- data/spec/github/repos/assets/upload_spec.rb +44 -0
- data/spec/github/repos/downloads/upload_spec.rb +5 -5
- data/spec/github/repos/releases/create_spec.rb +44 -0
- data/spec/github/repos/releases/delete_spec.rb +40 -0
- data/spec/github/repos/releases/edit_spec.rb +40 -0
- data/spec/github/repos/releases/get_spec.rb +45 -0
- data/spec/github/repos/releases/list_spec.rb +54 -0
- data/spec/github/request/endpoint_spec.rb +1 -3
- data/spec/github/request/request_spec.rb +4 -8
- data/spec/github/request_spec.rb +3 -3
- data/spec/github/response_wrapper_spec.rb +3 -3
- data/spec/github/s3_uploader_spec.rb +2 -3
- data/spec/github/search/code_spec.rb +38 -0
- data/spec/github/search/issues_spec.rb +38 -0
- data/spec/github/search/legacy/email_spec.rb +34 -0
- data/spec/github/search/legacy/issues_spec.rb +39 -0
- data/spec/github/search/legacy/repos_spec.rb +36 -0
- data/spec/github/search/legacy/users_spec.rb +36 -0
- data/spec/github/search/repos_spec.rb +38 -0
- data/spec/github/search/users_spec.rb +38 -0
- data/spec/github/users/get_spec.rb +1 -1
- data/spec/github/validations/presence_spec.rb +2 -5
- data/spec/integration/repos_spec.rb +4 -0
- data/spec/integration/search_spec.rb +12 -0
- metadata +122 -62
- data/features/cassettes/search/email.yml +0 -99
- data/spec/github/search_spec.rb +0 -102
data/features/settings.yml
CHANGED
|
@@ -12,6 +12,18 @@ Given /^I have "([^"]*)" instance$/ do |api_classes|
|
|
|
12
12
|
)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
Given /^I do not verify ssl$/ do
|
|
16
|
+
@instance.ssl = {:verify => false}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
Given /^I set the following (?:attribute|attributes) of instance:$/ do |table|
|
|
20
|
+
table.hashes.each do |element|
|
|
21
|
+
element.each do |attr, val|
|
|
22
|
+
@instance.send(:"#{attr}=", val)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
15
27
|
When /^I am not authorized$/ do
|
|
16
28
|
[:basic_auth, :login, :password, :oauth_token].each do |attr|
|
|
17
29
|
@instance.send("#{attr}=", nil)
|
|
@@ -51,7 +51,9 @@ module Github
|
|
|
51
51
|
DEFAULT_SITE = 'https://github.com'.freeze
|
|
52
52
|
|
|
53
53
|
# The default SSL configuration
|
|
54
|
-
DEFAULT_SSL = {
|
|
54
|
+
DEFAULT_SSL = {
|
|
55
|
+
:ca_file => File.expand_path('../ssl_certs/cacerts.pem', __FILE__)
|
|
56
|
+
}
|
|
55
57
|
|
|
56
58
|
# The value sent in the http header for 'User-Agent' if none is set
|
|
57
59
|
DEFAULT_USER_AGENT = "Github Ruby Gem #{Github::VERSION::STRING}".freeze
|
data/lib/github_api/error.rb
CHANGED
|
@@ -28,21 +28,10 @@ module Github
|
|
|
28
28
|
end # Error
|
|
29
29
|
end # Github
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
not_acceptable
|
|
38
|
-
unprocessable_entity
|
|
39
|
-
internal_server_error
|
|
40
|
-
service_unavailable
|
|
41
|
-
client_error
|
|
42
|
-
invalid_options
|
|
43
|
-
required_params
|
|
44
|
-
unknown_value
|
|
45
|
-
validations
|
|
46
|
-
].each do |error|
|
|
47
|
-
require "github_api/error/#{error}"
|
|
31
|
+
require 'github_api/error/service_error'
|
|
32
|
+
require 'github_api/error/client_error'
|
|
33
|
+
Dir[File.dirname(__FILE__) + '/error/*.rb'].sort.each do |path|
|
|
34
|
+
filename = File.basename(path)
|
|
35
|
+
next if ['service_error.rb', 'client_error.rb'].include?(filename)
|
|
36
|
+
require "github_api/error/#{filename}"
|
|
48
37
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Github #:nodoc
|
|
4
|
+
# Raised when invalid options are passed to a request body
|
|
5
|
+
module Error
|
|
6
|
+
class UnknownMedia < ClientError
|
|
7
|
+
def initialize(file)
|
|
8
|
+
super(
|
|
9
|
+
generate_message(
|
|
10
|
+
:problem => "Unknown content type for: '#{file}' provided for this request.",
|
|
11
|
+
:summary => "Github gem infers the content type of the resource by calling the mime-types gem type inference.",
|
|
12
|
+
:resolution => "Please install mime-types gem to infer the resource content type."
|
|
13
|
+
)
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end # Error
|
|
18
|
+
end # Github
|
|
@@ -14,19 +14,25 @@ module Github
|
|
|
14
14
|
super(normalize!(Hash[hash]))
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
# Create empty hash
|
|
18
|
+
#
|
|
19
|
+
def self.empty
|
|
20
|
+
new({})
|
|
21
|
+
end
|
|
22
|
+
|
|
17
23
|
# Extract and parse media type param
|
|
18
24
|
#
|
|
19
25
|
# [.version].param[+json]
|
|
20
26
|
#
|
|
21
27
|
def media
|
|
22
|
-
parse(
|
|
28
|
+
parse(delete('media'))
|
|
23
29
|
end
|
|
24
30
|
|
|
25
31
|
# Return accept header if present
|
|
26
32
|
#
|
|
27
33
|
def accept
|
|
28
34
|
if has_key?('accept')
|
|
29
|
-
|
|
35
|
+
delete('accept')
|
|
30
36
|
elsif has_key?('media')
|
|
31
37
|
media
|
|
32
38
|
else
|
|
@@ -34,26 +40,30 @@ module Github
|
|
|
34
40
|
end
|
|
35
41
|
end
|
|
36
42
|
|
|
37
|
-
# Extract request data from
|
|
43
|
+
# Extract request data from parameters
|
|
38
44
|
#
|
|
39
45
|
def data
|
|
40
46
|
if has_key?('data') && !self['data'].nil?
|
|
41
|
-
return
|
|
47
|
+
return delete('data')
|
|
42
48
|
else
|
|
43
|
-
return
|
|
49
|
+
return to_hash
|
|
44
50
|
end
|
|
45
51
|
end
|
|
46
52
|
|
|
47
53
|
# Any client configuration options
|
|
48
54
|
#
|
|
49
55
|
def options
|
|
50
|
-
|
|
56
|
+
opts = has_key?('options') ? delete('options') : {}
|
|
57
|
+
headers = opts.fetch(:headers) { {} }
|
|
51
58
|
if value = accept
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
headers[:accept] = value
|
|
60
|
+
end
|
|
61
|
+
if value = delete('content_type')
|
|
62
|
+
headers[:content_type] = value
|
|
54
63
|
end
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
opts[:raw] = has_key?('raw') ? delete('raw') : false
|
|
65
|
+
opts[:headers] = headers unless headers.empty?
|
|
66
|
+
opts
|
|
57
67
|
end
|
|
58
68
|
|
|
59
69
|
# Update hash with default parameters for non existing keys
|
data/lib/github_api/repos.rb
CHANGED
|
@@ -16,6 +16,7 @@ module Github
|
|
|
16
16
|
:Keys => 'keys',
|
|
17
17
|
:Merging => 'merging',
|
|
18
18
|
:PubSubHubbub => 'pub_sub_hubbub',
|
|
19
|
+
:Releases => 'releases',
|
|
19
20
|
:Statistics => 'statistics',
|
|
20
21
|
:Statuses => 'statuses'
|
|
21
22
|
|
|
@@ -52,7 +53,7 @@ module Github
|
|
|
52
53
|
|
|
53
54
|
# Access to Repos::Comments API
|
|
54
55
|
def comments(options={}, &block)
|
|
55
|
-
@
|
|
56
|
+
@comments ||= ApiFactory.new('Repos::Comments', current_options.merge(options), &block)
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
# Access to Repos::Commits API
|
|
@@ -87,7 +88,7 @@ module Github
|
|
|
87
88
|
|
|
88
89
|
# Access to Repos::Merging API
|
|
89
90
|
def merging(options={}, &block)
|
|
90
|
-
@
|
|
91
|
+
@merging ||= ApiFactory.new('Repos::Merging', current_options.merge(options), &block)
|
|
91
92
|
end
|
|
92
93
|
|
|
93
94
|
# Access to Repos::PubSubHubbub API
|
|
@@ -95,6 +96,11 @@ module Github
|
|
|
95
96
|
@pubsubhubbub ||= ApiFactory.new('Repos::PubSubHubbub', current_options.merge(options), &block)
|
|
96
97
|
end
|
|
97
98
|
|
|
99
|
+
# Access to Repos::Releases API
|
|
100
|
+
def releases(options={}, &block)
|
|
101
|
+
@releases ||= ApiFactory.new('Repos::Releases', current_options.merge(options), &block)
|
|
102
|
+
end
|
|
103
|
+
|
|
98
104
|
# Access to Repos::Statistics API
|
|
99
105
|
def stats(options={}, &block)
|
|
100
106
|
@stats ||= ApiFactory.new('Repos::Statistics', current_options.merge(options), &block)
|
|
@@ -143,15 +149,15 @@ module Github
|
|
|
143
149
|
end
|
|
144
150
|
params = arguments.params
|
|
145
151
|
|
|
146
|
-
response = if (user_name =
|
|
152
|
+
response = if (user_name = params.delete('user') || user)
|
|
147
153
|
get_request("/users/#{user_name}/repos", params)
|
|
148
|
-
elsif (org_name =
|
|
154
|
+
elsif (org_name = params.delete('org') || org)
|
|
149
155
|
get_request("/orgs/#{org_name}/repos", params)
|
|
150
|
-
elsif args.map(&:to_s).include?(
|
|
151
|
-
get_request(
|
|
156
|
+
elsif args.map(&:to_s).include?('every')
|
|
157
|
+
get_request('/repositories', params)
|
|
152
158
|
else
|
|
153
159
|
# For authenticated user
|
|
154
|
-
get_request(
|
|
160
|
+
get_request('/user/repos', params)
|
|
155
161
|
end
|
|
156
162
|
return response unless block_given?
|
|
157
163
|
response.each { |el| yield el }
|
|
@@ -180,11 +186,17 @@ module Github
|
|
|
180
186
|
# <tt>:name</tt> - Required string
|
|
181
187
|
# <tt>:description</tt> - Optional string
|
|
182
188
|
# <tt>:homepage</tt> - Optional string
|
|
183
|
-
# <tt>:private</tt> - Optional boolean - <tt>true</tt> to create a private
|
|
184
|
-
#
|
|
185
|
-
# <tt>:
|
|
186
|
-
#
|
|
187
|
-
# <tt>:
|
|
189
|
+
# <tt>:private</tt> - Optional boolean - <tt>true</tt> to create a private
|
|
190
|
+
# repository, <tt>false</tt> to create a public one.
|
|
191
|
+
# <tt>:has_issues</tt> - Optional boolean - <tt>true</tt> to enable issues
|
|
192
|
+
# for this repository, <tt>false</tt> to disable them
|
|
193
|
+
# <tt>:has_wiki</tt> - Optional boolean - <tt>true</tt> to enable the wiki
|
|
194
|
+
# for this repository, <tt>false</tt> to disable it.
|
|
195
|
+
# Default is <tt>true</tt>
|
|
196
|
+
# <tt>:has_downloads</tt> - Optional boolean - <tt>true</tt> to enable
|
|
197
|
+
# downloads for this repository
|
|
198
|
+
# <tt>:org</tt> Optional string - The organisation in which this repository
|
|
199
|
+
# will be created
|
|
188
200
|
# <tt>:team_id</tt> Optional number - The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization
|
|
189
201
|
# <tt>:auto_init</tt> Optional boolean - true to create an initial commit with empty README. Default is false.
|
|
190
202
|
# <tt>:gitignore_template</tt> Optional string - Desired language or platform .gitignore template to apply. Use the name of the template without the extension. For example, “Haskell” Ignored if auto_init parameter is not provided.
|
|
@@ -214,10 +226,10 @@ module Github
|
|
|
214
226
|
params = arguments.params
|
|
215
227
|
|
|
216
228
|
# Requires authenticated user
|
|
217
|
-
if (org = params.delete(
|
|
229
|
+
if (org = params.delete('org') || org)
|
|
218
230
|
post_request("/orgs/#{org}/repos", params.merge_default(DEFAULT_REPO_OPTIONS))
|
|
219
231
|
else
|
|
220
|
-
post_request(
|
|
232
|
+
post_request('/user/repos', params.merge_default(DEFAULT_REPO_OPTIONS))
|
|
221
233
|
end
|
|
222
234
|
end
|
|
223
235
|
|
|
@@ -324,7 +336,6 @@ module Github
|
|
|
324
336
|
# def branches(user_name, repo_name, params={})
|
|
325
337
|
def branches(*args)
|
|
326
338
|
arguments(args, :required => [:user, :repo])
|
|
327
|
-
params = arguments.params
|
|
328
339
|
|
|
329
340
|
response = get_request("/repos/#{user}/#{repo}/branches", arguments.params)
|
|
330
341
|
return response unless block_given?
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Github
|
|
4
|
+
|
|
5
|
+
# The Releases API
|
|
6
|
+
class Repos::Releases < API
|
|
7
|
+
extend AutoloadHelper
|
|
8
|
+
|
|
9
|
+
autoload_all 'github_api/repos/releases',
|
|
10
|
+
:Assets => 'assets'
|
|
11
|
+
|
|
12
|
+
VALID_RELEASE_PARAM_NAMES = %w[
|
|
13
|
+
tag_name
|
|
14
|
+
target_commitish
|
|
15
|
+
name
|
|
16
|
+
body
|
|
17
|
+
draft
|
|
18
|
+
prerelease
|
|
19
|
+
].freeze # :nodoc:
|
|
20
|
+
|
|
21
|
+
# Access to Repos::Releases::Assets API
|
|
22
|
+
def assets(options = {}, &block)
|
|
23
|
+
@assets ||= ApiFactory.new('Repos::Releases::Assets', current_options.merge(options), &block)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# List releases for a repository
|
|
27
|
+
#
|
|
28
|
+
# Users with push access to the repository will receive all releases
|
|
29
|
+
# (i.e., published releases and draft releases). Users with pull access
|
|
30
|
+
# will receive published releases only.
|
|
31
|
+
#
|
|
32
|
+
# = Examples
|
|
33
|
+
# github = Github.new
|
|
34
|
+
# github.repos.releases.list 'owner', 'repo'
|
|
35
|
+
# github.repos.releases.list 'owner', 'repo' { |release| ... }
|
|
36
|
+
#
|
|
37
|
+
def list(*args)
|
|
38
|
+
params = arguments(args, required: [:owner, :repo]).params
|
|
39
|
+
response = get_request("/repos/#{owner}/#{repo}/releases", params)
|
|
40
|
+
return response unless block_given?
|
|
41
|
+
response.each { |el| yield el }
|
|
42
|
+
end
|
|
43
|
+
alias :all :list
|
|
44
|
+
|
|
45
|
+
# Get a single release
|
|
46
|
+
#
|
|
47
|
+
# = Examples
|
|
48
|
+
# github = Github.new
|
|
49
|
+
# github.repos.releases.get 'owner', 'repo', 'id'
|
|
50
|
+
#
|
|
51
|
+
def get(*args)
|
|
52
|
+
params = arguments(args, required: [:owner, :repo, :id]).params
|
|
53
|
+
get_request("/repos/#{owner}/#{repo}/releases/#{id}" , params)
|
|
54
|
+
end
|
|
55
|
+
alias :find :get
|
|
56
|
+
|
|
57
|
+
# Create a release
|
|
58
|
+
#
|
|
59
|
+
# = Inputs
|
|
60
|
+
# * <tt>:tag_name</tt> - Required string
|
|
61
|
+
# * <tt>:target_commitish</tt> - Optional string - Specifies the commitish
|
|
62
|
+
# value that determines where the Git tag is created from. Can be
|
|
63
|
+
# any branch or commit SHA. Defaults to the repository's default
|
|
64
|
+
# branch (usually 'master'). Unused if the Git tag already exists.
|
|
65
|
+
# * <tt>:name</tt> - Optional string
|
|
66
|
+
# * <tt>:body</tt> - Optional string
|
|
67
|
+
# * <tt>:draft</tt> - Optional boolean - <tt>true</tt> to create a draft
|
|
68
|
+
# (unpublished) release, <tt>false</tt> to create
|
|
69
|
+
# a published one. Default is false.
|
|
70
|
+
# * <tt>:prerelease</tt> - Optional boolean - <tt>true</tt> to identify
|
|
71
|
+
# the release as a prerelease. false to identify
|
|
72
|
+
# the release as a full release. Default is false.
|
|
73
|
+
#
|
|
74
|
+
# = Examples
|
|
75
|
+
# github = Github.new
|
|
76
|
+
# github.repos.releases.create 'owner', 'repo', 'tag-name',
|
|
77
|
+
# "tag_name": "v1.0.0",
|
|
78
|
+
# "target_commitish": "master",
|
|
79
|
+
# "name": "v1.0.0",
|
|
80
|
+
# "body": "Description of the release",
|
|
81
|
+
# "draft": false,
|
|
82
|
+
# "prerelease": false
|
|
83
|
+
#
|
|
84
|
+
def create(*args)
|
|
85
|
+
arguments(args, required: [:owner, :repo, :tag_name]) do
|
|
86
|
+
sift VALID_RELEASE_PARAM_NAMES
|
|
87
|
+
end
|
|
88
|
+
params = arguments.params
|
|
89
|
+
params['tag_name'] = tag_name
|
|
90
|
+
|
|
91
|
+
post_request("/repos/#{owner}/#{repo}/releases", params)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Edit a release
|
|
95
|
+
#
|
|
96
|
+
# = Inputs
|
|
97
|
+
# * <tt>:tag_name</tt> - Required string
|
|
98
|
+
# * <tt>:target_commitish</tt> - Optional string - Specifies the commitish
|
|
99
|
+
# value that determines where the Git tag is created from. Can be
|
|
100
|
+
# any branch or commit SHA. Defaults to the repository's default
|
|
101
|
+
# branch (usually 'master'). Unused if the Git tag already exists.
|
|
102
|
+
# * <tt>:name</tt> - Optional string
|
|
103
|
+
# * <tt>:body</tt> - Optional string
|
|
104
|
+
# * <tt>:draft</tt> - Optional boolean - <tt>true</tt> to create a draft
|
|
105
|
+
# (unpublished) release, <tt>false</tt> to create
|
|
106
|
+
# a published one. Default is false.
|
|
107
|
+
# * <tt>:prerelease</tt> - Optional boolean - <tt>true</tt> to identify
|
|
108
|
+
# the release as a prerelease. false to identify
|
|
109
|
+
# the release as a full release. Default is false.
|
|
110
|
+
#
|
|
111
|
+
# = Examples
|
|
112
|
+
# github = Github.new
|
|
113
|
+
# github.repos.releases.edit 'owner', 'repo', 'id',
|
|
114
|
+
# "tag_name": "v1.0.0",
|
|
115
|
+
# "target_commitish": "master",
|
|
116
|
+
# "name": "v1.0.0",
|
|
117
|
+
# "body": "Description of the release",
|
|
118
|
+
# "draft": false,
|
|
119
|
+
# "prerelease": false
|
|
120
|
+
#
|
|
121
|
+
def edit(*args)
|
|
122
|
+
arguments(args, required: [:owner, :repo, :id]) do
|
|
123
|
+
sift VALID_RELEASE_PARAM_NAMES
|
|
124
|
+
end
|
|
125
|
+
params = arguments.params
|
|
126
|
+
|
|
127
|
+
patch_request("/repos/#{owner}/#{repo}/releases/#{id}", params)
|
|
128
|
+
end
|
|
129
|
+
alias :update :edit
|
|
130
|
+
|
|
131
|
+
# Delete a release
|
|
132
|
+
#
|
|
133
|
+
# Users with push access to the repository can delete a release.
|
|
134
|
+
#
|
|
135
|
+
# = Examples
|
|
136
|
+
# github = Github.new
|
|
137
|
+
# github.repos.releases.delete 'owner', 'repo', 'id'
|
|
138
|
+
#
|
|
139
|
+
def delete(*args)
|
|
140
|
+
params = arguments(args, required: [:owner, :repo, :id]).params
|
|
141
|
+
|
|
142
|
+
delete_request("/repos/#{owner}/#{repo}/releases/#{id}", params)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
end # Repos::Statuses
|
|
146
|
+
end # Github
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Github
|
|
4
|
+
|
|
5
|
+
# The Release Assets API
|
|
6
|
+
class Repos::Releases::Assets < API
|
|
7
|
+
|
|
8
|
+
VALID_ASSET_PARAM_NAMES = %w[
|
|
9
|
+
name
|
|
10
|
+
label
|
|
11
|
+
content_type
|
|
12
|
+
].freeze # :nodoc:
|
|
13
|
+
|
|
14
|
+
# List assets for a release
|
|
15
|
+
#
|
|
16
|
+
# = Examples
|
|
17
|
+
# github = Github.new
|
|
18
|
+
# github.repos.releases.assets.list 'owner', 'repo', 'id'
|
|
19
|
+
# github.repos.releases.assets.list 'owner', 'repo', 'id' { |asset| ... }
|
|
20
|
+
#
|
|
21
|
+
def list(*args)
|
|
22
|
+
params = arguments(args, required: [:owner, :repo, :id]).params
|
|
23
|
+
|
|
24
|
+
response = get_request("/repos/#{owner}/#{repo}/releases/#{id}/assets", params)
|
|
25
|
+
return response unless block_given?
|
|
26
|
+
response.each { |el| yield el }
|
|
27
|
+
end
|
|
28
|
+
alias :all :list
|
|
29
|
+
|
|
30
|
+
# Get a single release asset
|
|
31
|
+
#
|
|
32
|
+
# = Examples
|
|
33
|
+
# github = Github.new
|
|
34
|
+
# github.repos.releases.assets.get 'owner', 'repo', 'id'
|
|
35
|
+
#
|
|
36
|
+
def get(*args)
|
|
37
|
+
params = arguments(args, required: [:owner, :repo, :id]).params
|
|
38
|
+
|
|
39
|
+
get_request("/repos/#{owner}/#{repo}/releases/assets/#{id}" , params)
|
|
40
|
+
end
|
|
41
|
+
alias :find :get
|
|
42
|
+
|
|
43
|
+
# Upload a release asset
|
|
44
|
+
#
|
|
45
|
+
# = Inputs
|
|
46
|
+
# * <tt>:name</tt> - Required string - The file name of the asset
|
|
47
|
+
# * <tt>:content_type</tt> - Required string - The content type
|
|
48
|
+
# of the asset. Example: “application/zip”.
|
|
49
|
+
#
|
|
50
|
+
# = Examples
|
|
51
|
+
# github = Github.new
|
|
52
|
+
# github.repos.releases.assets.upload 'owner', 'repo', 'id', 'file-path'
|
|
53
|
+
# "name": "batman.jpg",
|
|
54
|
+
# "content_type": "application/octet-stream"
|
|
55
|
+
#
|
|
56
|
+
def upload(*args)
|
|
57
|
+
arguments(args, required: [:owner, :repo, :id, :filepath]) do
|
|
58
|
+
sift VALID_ASSET_PARAM_NAMES
|
|
59
|
+
end
|
|
60
|
+
params = arguments.params
|
|
61
|
+
|
|
62
|
+
unless type = params['content_type']
|
|
63
|
+
type = infer_media(filepath)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
file = Faraday::UploadIO.new(filepath, type)
|
|
67
|
+
options = {
|
|
68
|
+
headers: { content_type: type },
|
|
69
|
+
endpoint: 'https://uploads.github.com',
|
|
70
|
+
query: {'name' => params['name']}
|
|
71
|
+
}
|
|
72
|
+
params['data'] = file.read
|
|
73
|
+
params['options'] = options
|
|
74
|
+
|
|
75
|
+
post_request("/repos/#{owner}/#{repo}/releases/#{id}/assets", params)
|
|
76
|
+
ensure
|
|
77
|
+
file.close if file
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Infer media type of the asset
|
|
81
|
+
#
|
|
82
|
+
def infer_media(filepath)
|
|
83
|
+
require 'mime/types'
|
|
84
|
+
types = MIME::Types.type_for(filepath)
|
|
85
|
+
types.empty? ? 'application/octet-stream' : types.first
|
|
86
|
+
rescue LoadError
|
|
87
|
+
raise Github::Error::UnknownMedia.new(filepath)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Edit a release asset
|
|
91
|
+
#
|
|
92
|
+
# = Inputs
|
|
93
|
+
# * <tt>:name</tt> - Required string - the filename of the asset
|
|
94
|
+
# * <tt>:label</tt> - Optional string - An alternate short description of
|
|
95
|
+
# the asset. Used in place of the filename.
|
|
96
|
+
#
|
|
97
|
+
# = Examples
|
|
98
|
+
# github = Github.new
|
|
99
|
+
# github.repos.releases.assets.edit 'owner', 'repo', 'id',
|
|
100
|
+
# "name": "foo-1.0.0-osx.zip",
|
|
101
|
+
# "label": "Mac binary"
|
|
102
|
+
#
|
|
103
|
+
def edit(*args)
|
|
104
|
+
arguments(args, required: [:owner, :repo, :id]) do
|
|
105
|
+
sift VALID_ASSET_PARAM_NAMES
|
|
106
|
+
end
|
|
107
|
+
params = arguments.params
|
|
108
|
+
|
|
109
|
+
patch_request("/repos/#{owner}/#{repo}/releases/assets/#{id}", params)
|
|
110
|
+
end
|
|
111
|
+
alias :update :edit
|
|
112
|
+
|
|
113
|
+
# Delete a release asset
|
|
114
|
+
#
|
|
115
|
+
# = Examples
|
|
116
|
+
# github = Github.new
|
|
117
|
+
# github.repos.releases.assets.delete 'owner', 'repo', 'id'
|
|
118
|
+
#
|
|
119
|
+
def delete(*args)
|
|
120
|
+
params = arguments(args, required: [:owner, :repo, :id]).params
|
|
121
|
+
|
|
122
|
+
delete_request("/repos/#{owner}/#{repo}/releases/assets/#{id}", params)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end # Repos::Statuses
|
|
126
|
+
end # Github
|