octodoggy 4.6.2
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 +7 -0
- data/.document +5 -0
- data/CONTRIBUTING.md +22 -0
- data/LICENSE.md +20 -0
- data/README.md +714 -0
- data/Rakefile +22 -0
- data/lib/ext/sawyer/relation.rb +10 -0
- data/lib/octokit.rb +59 -0
- data/lib/octokit/arguments.rb +14 -0
- data/lib/octokit/authentication.rb +82 -0
- data/lib/octokit/client.rb +238 -0
- data/lib/octokit/client/authorizations.rb +244 -0
- data/lib/octokit/client/commit_comments.rb +95 -0
- data/lib/octokit/client/commits.rb +239 -0
- data/lib/octokit/client/contents.rb +162 -0
- data/lib/octokit/client/deployments.rb +62 -0
- data/lib/octokit/client/downloads.rb +50 -0
- data/lib/octokit/client/emojis.rb +18 -0
- data/lib/octokit/client/events.rb +151 -0
- data/lib/octokit/client/feeds.rb +33 -0
- data/lib/octokit/client/gists.rb +233 -0
- data/lib/octokit/client/gitignore.rb +43 -0
- data/lib/octokit/client/hooks.rb +297 -0
- data/lib/octokit/client/integrations.rb +77 -0
- data/lib/octokit/client/issues.rb +321 -0
- data/lib/octokit/client/labels.rb +156 -0
- data/lib/octokit/client/legacy_search.rb +42 -0
- data/lib/octokit/client/licenses.rb +45 -0
- data/lib/octokit/client/markdown.rb +27 -0
- data/lib/octokit/client/meta.rb +21 -0
- data/lib/octokit/client/milestones.rb +87 -0
- data/lib/octokit/client/notifications.rb +171 -0
- data/lib/octokit/client/objects.rb +141 -0
- data/lib/octokit/client/organizations.rb +768 -0
- data/lib/octokit/client/pages.rb +63 -0
- data/lib/octokit/client/projects.rb +314 -0
- data/lib/octokit/client/pub_sub_hubbub.rb +111 -0
- data/lib/octokit/client/pull_requests.rb +301 -0
- data/lib/octokit/client/rate_limit.rb +54 -0
- data/lib/octokit/client/reactions.rb +158 -0
- data/lib/octokit/client/refs.rb +118 -0
- data/lib/octokit/client/releases.rb +163 -0
- data/lib/octokit/client/repositories.rb +654 -0
- data/lib/octokit/client/repository_invitations.rb +103 -0
- data/lib/octokit/client/reviews.rb +174 -0
- data/lib/octokit/client/say.rb +19 -0
- data/lib/octokit/client/search.rb +76 -0
- data/lib/octokit/client/service_status.rb +38 -0
- data/lib/octokit/client/source_import.rb +161 -0
- data/lib/octokit/client/stats.rb +105 -0
- data/lib/octokit/client/statuses.rb +47 -0
- data/lib/octokit/client/traffic.rb +69 -0
- data/lib/octokit/client/users.rb +354 -0
- data/lib/octokit/configurable.rb +147 -0
- data/lib/octokit/connection.rb +199 -0
- data/lib/octokit/default.rb +166 -0
- data/lib/octokit/enterprise_admin_client.rb +40 -0
- data/lib/octokit/enterprise_admin_client/admin_stats.rb +120 -0
- data/lib/octokit/enterprise_admin_client/license.rb +18 -0
- data/lib/octokit/enterprise_admin_client/orgs.rb +27 -0
- data/lib/octokit/enterprise_admin_client/search_indexing.rb +83 -0
- data/lib/octokit/enterprise_admin_client/users.rb +128 -0
- data/lib/octokit/enterprise_management_console_client.rb +50 -0
- data/lib/octokit/enterprise_management_console_client/management_console.rb +176 -0
- data/lib/octokit/error.rb +286 -0
- data/lib/octokit/gist.rb +36 -0
- data/lib/octokit/middleware/follow_redirects.rb +131 -0
- data/lib/octokit/organization.rb +17 -0
- data/lib/octokit/preview.rb +38 -0
- data/lib/octokit/rate_limit.rb +33 -0
- data/lib/octokit/repo_arguments.rb +19 -0
- data/lib/octokit/repository.rb +93 -0
- data/lib/octokit/response/feed_parser.rb +21 -0
- data/lib/octokit/response/raise_error.rb +21 -0
- data/lib/octokit/user.rb +19 -0
- data/lib/octokit/version.rb +17 -0
- data/lib/octokit/warnable.rb +17 -0
- data/octokit.gemspec +22 -0
- metadata +160 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
module Octokit
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the Commit Comments API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/repos/comments/
|
7
|
+
module CommitComments
|
8
|
+
|
9
|
+
# List all commit comments
|
10
|
+
#
|
11
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
12
|
+
# @return [Array] List of commit comments
|
13
|
+
# @see https://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository
|
14
|
+
def list_commit_comments(repo, options = {})
|
15
|
+
paginate "#{Repository.path repo}/comments", options
|
16
|
+
end
|
17
|
+
|
18
|
+
# List comments for a single commit
|
19
|
+
#
|
20
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
21
|
+
# @param sha [String] The SHA of the commit whose comments will be fetched
|
22
|
+
# @return [Array] List of commit comments
|
23
|
+
# @see https://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit
|
24
|
+
def commit_comments(repo, sha, options = {})
|
25
|
+
paginate "#{Repository.path repo}/commits/#{sha}/comments", options
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get a single commit comment
|
29
|
+
#
|
30
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
31
|
+
# @param id [String] The ID of the comment to fetch
|
32
|
+
# @return [Sawyer::Resource] Commit comment
|
33
|
+
# @see https://developer.github.com/v3/repos/comments/#get-a-single-commit-comment
|
34
|
+
def commit_comment(repo, id, options = {})
|
35
|
+
get "#{Repository.path repo}/comments/#{id}", options
|
36
|
+
end
|
37
|
+
|
38
|
+
# Create a commit comment
|
39
|
+
#
|
40
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
41
|
+
# @param sha [String] Sha of the commit to comment on
|
42
|
+
# @param body [String] Message
|
43
|
+
# @param path [String] Relative path of file to comment on
|
44
|
+
# @param line [Integer] Line number in the file to comment on
|
45
|
+
# @param position [Integer] Line index in the diff to comment on
|
46
|
+
# @return [Sawyer::Resource] Commit comment
|
47
|
+
# @see https://developer.github.com/v3/repos/comments/#create-a-commit-comment
|
48
|
+
# @example Create a commit comment
|
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
|
56
|
+
def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, options = {})
|
57
|
+
params = {
|
58
|
+
:body => body,
|
59
|
+
:path => path,
|
60
|
+
:line => line,
|
61
|
+
:position => position
|
62
|
+
}
|
63
|
+
post "#{Repository.path repo}/commits/#{sha}/comments", options.merge(params)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Update a commit comment
|
67
|
+
#
|
68
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
69
|
+
# @param id [String] The ID of the comment to update
|
70
|
+
# @param body [String] Message
|
71
|
+
# @return [Sawyer::Resource] Updated commit comment
|
72
|
+
# @see https://developer.github.com/v3/repos/comments/#update-a-commit-comment
|
73
|
+
# @example Update a 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
|
+
def update_commit_comment(repo, id, body, options = {})
|
78
|
+
params = {
|
79
|
+
:body => body
|
80
|
+
}
|
81
|
+
patch "#{Repository.path repo}/comments/#{id}", options.merge(params)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Delete a commit comment
|
85
|
+
#
|
86
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
87
|
+
# @param id [String] The ID of the comment to delete
|
88
|
+
# @return [Boolean] Success
|
89
|
+
# @see https://developer.github.com/v3/repos/comments/#delete-a-commit-comment
|
90
|
+
def delete_commit_comment(repo, id, options = {})
|
91
|
+
boolean_from_response :delete, "#{Repository.path repo}/comments/#{id}", options
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,239 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Octokit
|
4
|
+
class Client
|
5
|
+
|
6
|
+
# Methods for the Commits API
|
7
|
+
#
|
8
|
+
# @see https://developer.github.com/v3/repos/commits/
|
9
|
+
module Commits
|
10
|
+
|
11
|
+
# List commits
|
12
|
+
#
|
13
|
+
# @overload commits(repo, sha_or_branch, options = {})
|
14
|
+
# @deprecated
|
15
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
16
|
+
# @param sha_or_branch [String] A commit SHA or branch name
|
17
|
+
# @param options [String] :sha Commit SHA or branch name from which to start the list
|
18
|
+
# @overload commits(repo, options = {})
|
19
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
20
|
+
# @param options [String] :sha Commit SHA or branch name from which to start the list
|
21
|
+
# @return [Array<Sawyer::Resource>] An array of hashes representing commits
|
22
|
+
# @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
|
23
|
+
def commits(*args)
|
24
|
+
arguments = Octokit::RepoArguments.new(args)
|
25
|
+
sha_or_branch = arguments.pop
|
26
|
+
if sha_or_branch
|
27
|
+
arguments.options[:sha] = sha_or_branch
|
28
|
+
end
|
29
|
+
paginate "#{Repository.new(arguments.repo).path}/commits", arguments.options
|
30
|
+
end
|
31
|
+
alias :list_commits :commits
|
32
|
+
|
33
|
+
# Get commits after a specified date
|
34
|
+
#
|
35
|
+
# @overload commits_since(repo, date, options = {})
|
36
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
37
|
+
# @param date [String] Date on which we want to compare
|
38
|
+
# @param options [String] :sha Commit SHA or branch name from which to start the list
|
39
|
+
# @overload commits_since(repo, date, sha_or_branch, options = {})
|
40
|
+
# @deprecated
|
41
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
42
|
+
# @param date [String] Date on which we want to compare
|
43
|
+
# @param sha_or_branch [String] A commit SHA or branch name
|
44
|
+
# @param options [String] :sha Commit SHA or branch name from which to start the list
|
45
|
+
# @return [Array<Sawyer::Resource>] An array of hashes representing commits
|
46
|
+
# @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
|
47
|
+
# @example
|
48
|
+
# Octokit.commits_since('octokit/octokit.rb', '2012-10-01')
|
49
|
+
def commits_since(*args)
|
50
|
+
arguments = Octokit::RepoArguments.new(args)
|
51
|
+
date = parse_date(arguments.shift)
|
52
|
+
params = arguments.options
|
53
|
+
params.merge!(:since => iso8601(date))
|
54
|
+
sha_or_branch = arguments.pop
|
55
|
+
if sha_or_branch
|
56
|
+
params[:sha] = sha_or_branch
|
57
|
+
end
|
58
|
+
commits(arguments.repo, params)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Get commits before a specified date
|
62
|
+
#
|
63
|
+
# @overload commits_before(repo, date, options = {})
|
64
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
65
|
+
# @param date [String] Date on which we want to compare
|
66
|
+
# @overload commits_before(repo, date, sha_or_branch, options = {})
|
67
|
+
# @deprecated
|
68
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
69
|
+
# @param date [String] Date on which we want to compare
|
70
|
+
# @param sha_or_branch [String] Commit SHA or branch name from which to start the list
|
71
|
+
# @return [Array<Sawyer::Resource>] An array of hashes representing commits
|
72
|
+
# @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
|
73
|
+
# @example
|
74
|
+
# Octokit.commits_before('octokit/octokit.rb', '2012-10-01')
|
75
|
+
def commits_before(*args)
|
76
|
+
arguments = Octokit::RepoArguments.new(args)
|
77
|
+
date = parse_date(arguments.shift)
|
78
|
+
params = arguments.options
|
79
|
+
params.merge!(:until => iso8601(date))
|
80
|
+
sha_or_branch = arguments.pop
|
81
|
+
if sha_or_branch
|
82
|
+
params[:sha] = sha_or_branch
|
83
|
+
end
|
84
|
+
commits(arguments.repo, params)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Get commits on a specified date
|
88
|
+
#
|
89
|
+
# @overload commits_on(repo, date, options = {})
|
90
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
91
|
+
# @param date [String] Date on which we want to compare
|
92
|
+
# @overload commits_on(repo, date, sha_or_branch, options = {})
|
93
|
+
# @deprecated
|
94
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
95
|
+
# @param date [String] Date on which we want to compare
|
96
|
+
# @param sha_or_branch [String] Commit SHA or branch name from which to start the list
|
97
|
+
# @return [Array<Sawyer::Resource>] An array of hashes representing commits
|
98
|
+
# @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
|
99
|
+
# @example
|
100
|
+
# Octokit.commits_on('octokit/octokit.rb', '2012-10-01')
|
101
|
+
def commits_on(*args)
|
102
|
+
arguments = Octokit::RepoArguments.new(args)
|
103
|
+
date = parse_date(arguments.shift)
|
104
|
+
params = arguments.options
|
105
|
+
end_date = date + 1
|
106
|
+
params.merge!(:since => iso8601(date), :until => iso8601(end_date))
|
107
|
+
sha_or_branch = arguments.pop
|
108
|
+
if sha_or_branch
|
109
|
+
params[:sha] = sha_or_branch
|
110
|
+
end
|
111
|
+
commits(arguments.repo, params)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Get commits made between two nominated dates
|
115
|
+
#
|
116
|
+
# @overload commits_between(repo, start_date, end_date, options = {})
|
117
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
118
|
+
# @param start_date [String] Start Date on which we want to compare
|
119
|
+
# @param end_date [String] End Date on which we want to compare
|
120
|
+
# @overload commits_between(repo, start_date, end_date, sha_or_branch, options = {})
|
121
|
+
# @deprecated
|
122
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
123
|
+
# @param start_date [String] Start Date on which we want to compare
|
124
|
+
# @param end_date [String] End Date on which we want to compare
|
125
|
+
# @param sha_or_branch [String] Commit SHA or branch name from which to start the list
|
126
|
+
# @return [Array<Sawyer::Resource>] An array of hashes representing commits
|
127
|
+
# @see https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
|
128
|
+
# @example
|
129
|
+
# Octokit.commits_between('octokit/octokit.rb', '2012-10-01', '2012-11-01')
|
130
|
+
def commits_between(*args)
|
131
|
+
arguments = Octokit::RepoArguments.new(args)
|
132
|
+
date = parse_date(arguments.shift)
|
133
|
+
end_date = parse_date(arguments.shift)
|
134
|
+
raise ArgumentError, "Start date #{date} does not precede #{end_date}" if date > end_date
|
135
|
+
|
136
|
+
params = arguments.options
|
137
|
+
params.merge!(:since => iso8601(date), :until => iso8601(end_date))
|
138
|
+
sha_or_branch = arguments.pop
|
139
|
+
if sha_or_branch
|
140
|
+
params[:sha] = sha_or_branch
|
141
|
+
end
|
142
|
+
commits(arguments.repo, params)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Get a single commit
|
146
|
+
#
|
147
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
148
|
+
# @param sha [String] The SHA of the commit to fetch
|
149
|
+
# @return [Sawyer::Resource] A hash representing the commit
|
150
|
+
# @see https://developer.github.com/v3/repos/commits/#get-a-single-commit
|
151
|
+
def commit(repo, sha, options = {})
|
152
|
+
get "#{Repository.path repo}/commits/#{sha}", options
|
153
|
+
end
|
154
|
+
|
155
|
+
# Get a detailed git commit
|
156
|
+
#
|
157
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
158
|
+
# @param sha [String] The SHA of the commit to fetch
|
159
|
+
# @return [Sawyer::Resource] A hash representing the commit
|
160
|
+
# @see https://developer.github.com/v3/git/commits/#get-a-commit
|
161
|
+
def git_commit(repo, sha, options = {})
|
162
|
+
get "#{Repository.path repo}/git/commits/#{sha}", options
|
163
|
+
end
|
164
|
+
|
165
|
+
# Create a commit
|
166
|
+
#
|
167
|
+
# Optionally pass <tt>author</tt> and <tt>committer</tt> hashes in <tt>options</tt>
|
168
|
+
# if you'd like manual control over those parameters. If absent, details will be
|
169
|
+
# inferred from the authenticated user. See <a href="http://developer.github.com/v3/git/commits/">GitHub's documentation</a>
|
170
|
+
# for details about how to format committer identities.
|
171
|
+
#
|
172
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
173
|
+
# @param message [String] The commit message
|
174
|
+
# @param tree [String] The SHA of the tree object the new commit will point to
|
175
|
+
# @param parents [String, Array] One SHA (for a normal commit) or an array of SHAs (for a merge) of the new commit's parent commits. If ommitted or empty, a root commit will be created
|
176
|
+
# @return [Sawyer::Resource] A hash representing the new commit
|
177
|
+
# @see https://developer.github.com/v3/git/commits/#create-a-commit
|
178
|
+
# @example Create a commit
|
179
|
+
# commit = Octokit.create_commit("octocat/Hello-World", "My commit message", "827efc6d56897b048c772eb4087f854f46256132", "7d1b31e74ee336d15cbd21741bc88a537ed063a0")
|
180
|
+
# commit.sha # => "7638417db6d59f3c431d3e1f261cc637155684cd"
|
181
|
+
# commit.tree.sha # => "827efc6d56897b048c772eb4087f854f46256132"
|
182
|
+
# commit.message # => "My commit message"
|
183
|
+
# commit.committer # => { "name" => "Wynn Netherland", "email" => "wynn@github.com", ... }
|
184
|
+
def create_commit(repo, message, tree, parents=nil, options = {})
|
185
|
+
params = { :message => message, :tree => tree }
|
186
|
+
params[:parents] = [parents].flatten if parents
|
187
|
+
post "#{Repository.path repo}/git/commits", options.merge(params)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Compare two commits
|
191
|
+
#
|
192
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
193
|
+
# @param start [String] The sha of the starting commit
|
194
|
+
# @param endd [String] The sha of the ending commit
|
195
|
+
# @return [Sawyer::Resource] A hash representing the comparison
|
196
|
+
# @see https://developer.github.com/v3/repos/commits/#compare-two-commits
|
197
|
+
def compare(repo, start, endd, options = {})
|
198
|
+
get "#{Repository.path repo}/compare/#{start}...#{endd}", options
|
199
|
+
end
|
200
|
+
|
201
|
+
# Merge a branch or sha
|
202
|
+
#
|
203
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
204
|
+
# @param base [String] The name of the base branch to merge into
|
205
|
+
# @param head [String] The branch or SHA1 to merge
|
206
|
+
# @option options [String] :commit_message The commit message for the merge
|
207
|
+
# @return [Sawyer::Resource] A hash representing the comparison
|
208
|
+
# @see https://developer.github.com/v3/repos/merging/#perform-a-merge
|
209
|
+
def merge(repo, base, head, options = {})
|
210
|
+
params = {
|
211
|
+
:base => base,
|
212
|
+
:head => head
|
213
|
+
}.merge(options)
|
214
|
+
post "#{Repository.path repo}/merges", params
|
215
|
+
end
|
216
|
+
|
217
|
+
protected
|
218
|
+
|
219
|
+
def iso8601(date)
|
220
|
+
if date.respond_to?(:iso8601)
|
221
|
+
date.iso8601
|
222
|
+
else
|
223
|
+
date.strftime("%Y-%m-%dT%H:%M:%S%Z")
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
# Parses the given string representation of a date, throwing a meaningful exception
|
228
|
+
# (containing the date that failed to parse) in case of failure.
|
229
|
+
#
|
230
|
+
# @param date [String] String representation of a date
|
231
|
+
# @return [DateTime]
|
232
|
+
def parse_date(date)
|
233
|
+
date = DateTime.parse(date.to_s)
|
234
|
+
rescue ArgumentError
|
235
|
+
raise ArgumentError, "#{date} is not a valid date"
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module Octokit
|
4
|
+
class Client
|
5
|
+
|
6
|
+
# Methods for the Repo Contents API
|
7
|
+
#
|
8
|
+
# @see https://developer.github.com/v3/repos/contents/
|
9
|
+
module Contents
|
10
|
+
|
11
|
+
# Receive the default Readme for a repository
|
12
|
+
#
|
13
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
14
|
+
# @option options [String] :ref name of the Commit/Branch/Tag. Defaults to “master”.
|
15
|
+
# @return [Sawyer::Resource] The detail of the readme
|
16
|
+
# @see https://developer.github.com/v3/repos/contents/#get-the-readme
|
17
|
+
# @example Get the readme file for a repo
|
18
|
+
# Octokit.readme("octokit/octokit.rb")
|
19
|
+
def readme(repo, options={})
|
20
|
+
get "#{Repository.path repo}/readme", options
|
21
|
+
end
|
22
|
+
|
23
|
+
# Receive a listing of a repository folder or the contents of a file
|
24
|
+
#
|
25
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
26
|
+
# @option options [String] :path A folder or file path
|
27
|
+
# @option options [String] :ref name of the Commit/Branch/Tag. Defaults to “master”.
|
28
|
+
# @return [Sawyer::Resource] The contents of a file or list of the files in the folder
|
29
|
+
# @see https://developer.github.com/v3/repos/contents/#get-contents
|
30
|
+
# @example List the contents of lib/octokit.rb
|
31
|
+
# Octokit.contents("octokit/octokit.rb", :path => 'lib/octokit.rb')
|
32
|
+
def contents(repo, options={})
|
33
|
+
repo_path = options.delete :path
|
34
|
+
url = "#{Repository.path repo}/contents/#{repo_path}"
|
35
|
+
get url, options
|
36
|
+
end
|
37
|
+
alias :content :contents
|
38
|
+
|
39
|
+
# Add content to a repository
|
40
|
+
#
|
41
|
+
# @overload create_contents(repo, path, message, content = nil, options = {})
|
42
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
43
|
+
# @param path [String] A path for the new content
|
44
|
+
# @param message [String] A commit message for adding the content
|
45
|
+
# @param optional content [String] The content for the file
|
46
|
+
# @option options [String] :branch The branch on which to add the content
|
47
|
+
# @option options [String] :file Path or Ruby File object for content
|
48
|
+
# @return [Sawyer::Resource] The contents and commit info for the addition
|
49
|
+
# @see https://developer.github.com/v3/repos/contents/#create-a-file
|
50
|
+
# @example Add content at lib/octokit.rb
|
51
|
+
# Octokit.create_contents("octokit/octokit.rb",
|
52
|
+
# "lib/octokit.rb",
|
53
|
+
# "Adding content",
|
54
|
+
# "File content",
|
55
|
+
# :branch => "my-new-feature")
|
56
|
+
def create_contents(*args)
|
57
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
58
|
+
repo = args.shift
|
59
|
+
path = args.shift
|
60
|
+
message = args.shift
|
61
|
+
content = args.shift
|
62
|
+
if content.nil? && file = options.delete(:file)
|
63
|
+
case file
|
64
|
+
when String
|
65
|
+
if File.exist?(file)
|
66
|
+
file = File.open(file, "r")
|
67
|
+
content = file.read
|
68
|
+
file.close
|
69
|
+
end
|
70
|
+
when File, Tempfile
|
71
|
+
content = file.read
|
72
|
+
file.close
|
73
|
+
end
|
74
|
+
end
|
75
|
+
raise ArgumentError.new("content or :file option required") if content.nil?
|
76
|
+
options[:content] = Base64.respond_to?(:strict_encode64) ?
|
77
|
+
Base64.strict_encode64(content) :
|
78
|
+
Base64.encode64(content).delete("\n") # Ruby 1.9.2
|
79
|
+
options[:message] = message
|
80
|
+
url = "#{Repository.path repo}/contents/#{path}"
|
81
|
+
put url, options
|
82
|
+
end
|
83
|
+
alias :create_content :create_contents
|
84
|
+
alias :add_content :create_contents
|
85
|
+
alias :add_contents :create_contents
|
86
|
+
|
87
|
+
# Update content in a repository
|
88
|
+
#
|
89
|
+
# @overload update_contents(repo, path, message, sha, content = nil, options = {})
|
90
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
91
|
+
# @param path [String] A path for the content to update
|
92
|
+
# @param message [String] A commit message for updating the content
|
93
|
+
# @param sha [String] The _blob sha_ of the content to update
|
94
|
+
# @param content [String] The content for the file
|
95
|
+
# @option options [String] :branch The branch on which to update the content
|
96
|
+
# @option options [String] :file Path or Ruby File object for content
|
97
|
+
# @return [Sawyer::Resource] The contents and commit info for the update
|
98
|
+
# @see https://developer.github.com/v3/repos/contents/#update-a-file
|
99
|
+
# @example Update content at lib/octokit.rb
|
100
|
+
# Octokit.update_contents("octokit/octokit.rb",
|
101
|
+
# "lib/octokit.rb",
|
102
|
+
# "Updating content",
|
103
|
+
# "7eb95f97e1a0636015df3837478d3f15184a5f49",
|
104
|
+
# "File content",
|
105
|
+
# :branch => "my-new-feature")
|
106
|
+
def update_contents(*args)
|
107
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
108
|
+
repo = args.shift
|
109
|
+
path = args.shift
|
110
|
+
message = args.shift
|
111
|
+
sha = args.shift
|
112
|
+
content = args.shift
|
113
|
+
options.merge!(:sha => sha)
|
114
|
+
create_contents(repo, path, message, content, options)
|
115
|
+
end
|
116
|
+
alias :update_content :update_contents
|
117
|
+
|
118
|
+
# Delete content in a repository
|
119
|
+
#
|
120
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
121
|
+
# @param path [String] A path for the content to delete
|
122
|
+
# @param message [String] A commit message for deleting the content
|
123
|
+
# @param sha [String] The _blob sha_ of the content to delete
|
124
|
+
# @option options [String] :branch The branch on which to delete the content
|
125
|
+
# @return [Sawyer::Resource] The commit info for the delete
|
126
|
+
# @see https://developer.github.com/v3/repos/contents/#delete-a-file
|
127
|
+
# @example Delete content at lib/octokit.rb
|
128
|
+
# Octokit.delete_contents("octokit/octokit.rb",
|
129
|
+
# "lib/octokit.rb",
|
130
|
+
# "Deleting content",
|
131
|
+
# "7eb95f97e1a0636015df3837478d3f15184a5f49",
|
132
|
+
# :branch => "my-new-feature")
|
133
|
+
def delete_contents(repo, path, message, sha, options = {})
|
134
|
+
options[:message] = message
|
135
|
+
options[:sha] = sha
|
136
|
+
url = "#{Repository.path repo}/contents/#{path}"
|
137
|
+
delete url, options
|
138
|
+
end
|
139
|
+
alias :delete_content :delete_contents
|
140
|
+
alias :remove_content :delete_contents
|
141
|
+
alias :remove_contents :delete_contents
|
142
|
+
|
143
|
+
# This method will provide a URL to download a tarball or zipball archive for a repository.
|
144
|
+
#
|
145
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository.
|
146
|
+
# @option options format [String] Either tarball (default) or zipball.
|
147
|
+
# @option options [String] :ref Optional valid Git reference, defaults to master.
|
148
|
+
# @return [String] Location of the download
|
149
|
+
# @see https://developer.github.com/v3/repos/contents/#get-archive-link
|
150
|
+
# @example Get archive link for octokit/octokit.rb
|
151
|
+
# Octokit.archive_link("octokit/octokit.rb")
|
152
|
+
def archive_link(repo, options={})
|
153
|
+
repo_ref = options.delete :ref
|
154
|
+
format = (options.delete :format) || 'tarball'
|
155
|
+
url = "#{Repository.path repo}/#{format}/#{repo_ref}"
|
156
|
+
|
157
|
+
response = client_without_redirects.head(url, options)
|
158
|
+
response.headers['Location']
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|