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,118 @@
|
|
1
|
+
module Octokit
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for References for Git Data API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/git/refs/
|
7
|
+
module Refs
|
8
|
+
|
9
|
+
# List all refs for a given user and repo
|
10
|
+
#
|
11
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
12
|
+
# @param namespace [String] The ref namespace, e.g. <tt>tag</tt> or <tt>heads</tt>
|
13
|
+
# @return [Array<Sawyer::Resource>] A list of references matching the repo and the namespace
|
14
|
+
# @see https://developer.github.com/v3/git/refs/#get-all-references
|
15
|
+
# @example Fetch all refs for sferik/rails_admin
|
16
|
+
# Octokit.refs("sferik/rails_admin")
|
17
|
+
def refs(repo, namespace = nil, options = {})
|
18
|
+
path = "#{Repository.path repo}/git/refs"
|
19
|
+
path += "/#{namespace}" unless namespace.nil?
|
20
|
+
paginate path, options
|
21
|
+
end
|
22
|
+
alias :list_refs :refs
|
23
|
+
alias :references :refs
|
24
|
+
alias :list_references :refs
|
25
|
+
|
26
|
+
# Fetch a given reference
|
27
|
+
#
|
28
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
29
|
+
# @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
|
30
|
+
# @return [Sawyer::Resource] The reference matching the given repo and the ref id
|
31
|
+
# @see https://developer.github.com/v3/git/refs/#get-a-reference
|
32
|
+
# @example Fetch tags/v0.0.3 for sferik/rails_admin
|
33
|
+
# Octokit.ref("sferik/rails_admin","tags/v0.0.3")
|
34
|
+
def ref(repo, ref, options = {})
|
35
|
+
get "#{Repository.path repo}/git/refs/#{ref}", options
|
36
|
+
end
|
37
|
+
alias :reference :ref
|
38
|
+
|
39
|
+
# Create a reference
|
40
|
+
#
|
41
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
42
|
+
# @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
|
43
|
+
# @param sha [String] A SHA, e.g. <tt>827efc6d56897b048c772eb4087f854f46256132</tt>
|
44
|
+
# @return [Array<Sawyer::Resource>] The list of references, already containing the new one
|
45
|
+
# @see https://developer.github.com/v3/git/refs/#create-a-reference
|
46
|
+
# @example Create refs/heads/master for octocat/Hello-World with sha 827efc6d56897b048c772eb4087f854f46256132
|
47
|
+
# Octokit.create_ref("octocat/Hello-World", "heads/master", "827efc6d56897b048c772eb4087f854f46256132")
|
48
|
+
def create_ref(repo, ref, sha, options = {})
|
49
|
+
ref = "refs/#{ref}" unless ref =~ %r{refs/}
|
50
|
+
parameters = {
|
51
|
+
:ref => ref,
|
52
|
+
:sha => sha
|
53
|
+
}
|
54
|
+
post "#{Repository.path repo}/git/refs", options.merge(parameters)
|
55
|
+
end
|
56
|
+
alias :create_reference :create_ref
|
57
|
+
|
58
|
+
# Update a reference
|
59
|
+
#
|
60
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
61
|
+
# @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
|
62
|
+
# @param sha [String] A SHA, e.g. <tt>827efc6d56897b048c772eb4087f854f46256132</tt>
|
63
|
+
# @param force [Boolean] A flag indicating one wants to force the update to make sure the update is a fast-forward update.
|
64
|
+
# @return [Array<Sawyer::Resource>] The list of references updated
|
65
|
+
# @see https://developer.github.com/v3/git/refs/#update-a-reference
|
66
|
+
# @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
|
67
|
+
# Octokit.update_ref("octocat/Hello-World", "heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
|
68
|
+
def update_ref(repo, ref, sha, force = true, options = {})
|
69
|
+
parameters = {
|
70
|
+
:sha => sha,
|
71
|
+
:force => force
|
72
|
+
}
|
73
|
+
patch "#{Repository.path repo}/git/refs/#{ref}", options.merge(parameters)
|
74
|
+
end
|
75
|
+
alias :update_reference :update_ref
|
76
|
+
|
77
|
+
# Update a branch
|
78
|
+
#
|
79
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
80
|
+
# @param branch [String] The ref, e.g. <tt>feature/new-shiny</tt>
|
81
|
+
# @param sha [String] A SHA, e.g. <tt>827efc6d56897b048c772eb4087f854f46256132</tt>
|
82
|
+
# @param force [Boolean] A flag indicating one wants to force the update to make sure the update is a fast-forward update.
|
83
|
+
# @return [Array<Sawyer::Resource>] The list of references updated
|
84
|
+
# @see https://developer.github.com/v3/git/refs/#update-a-reference
|
85
|
+
# @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
|
86
|
+
# Octokit.update_ref("octocat/Hello-World","sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
|
87
|
+
def update_branch(repo, branch, sha, force = true, options = {})
|
88
|
+
update_ref repo, "heads/#{branch}", sha, force, options
|
89
|
+
end
|
90
|
+
|
91
|
+
# Delete a single branch
|
92
|
+
#
|
93
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
94
|
+
# @param branch [String] The branch, e.g. <tt>fix-refs</tt>
|
95
|
+
# @return [Boolean] Success
|
96
|
+
# @see https://developer.github.com/v3/git/refs/#delete-a-reference
|
97
|
+
# @example Delete uritemplate for sigmavirus24/github3.py
|
98
|
+
# Octokit.delete_branch("sigmavirus24/github3.py", "uritemplate")
|
99
|
+
def delete_branch(repo, branch, options = {})
|
100
|
+
delete_ref repo, "heads/#{branch}", options
|
101
|
+
end
|
102
|
+
|
103
|
+
# Delete a single reference
|
104
|
+
#
|
105
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
106
|
+
# @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
|
107
|
+
# @return [Boolean] Success
|
108
|
+
# @see https://developer.github.com/v3/git/refs/#delete-a-reference
|
109
|
+
# @example Delete tags/v0.0.3 for sferik/rails_admin
|
110
|
+
# Octokit.delete_ref("sferik/rails_admin","tags/v0.0.3")
|
111
|
+
def delete_ref(repo, ref, options = {})
|
112
|
+
boolean_from_response :delete, "#{Repository.path repo}/git/refs/#{ref}", options
|
113
|
+
end
|
114
|
+
alias :delete_reference :delete_ref
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
module Octokit
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the Releases API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/repos/releases/
|
7
|
+
module Releases
|
8
|
+
|
9
|
+
# List releases for a repository
|
10
|
+
#
|
11
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
12
|
+
# @return [Array<Sawyer::Resource>] A list of releases
|
13
|
+
# @see https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository
|
14
|
+
def releases(repo, options = {})
|
15
|
+
paginate "#{Repository.path repo}/releases", options
|
16
|
+
end
|
17
|
+
alias :list_releases :releases
|
18
|
+
|
19
|
+
# Create a release
|
20
|
+
#
|
21
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
22
|
+
# @param tag_name [String] Git tag from which to create release
|
23
|
+
# @option options [String] :target_commitish Specifies the commitish value that determines where the Git tag is created from.
|
24
|
+
# @option options [String] :name Name for the release
|
25
|
+
# @option options [String] :body Content for release notes
|
26
|
+
# @option options [Boolean] :draft Mark this release as a draft
|
27
|
+
# @option options [Boolean] :prerelease Mark this release as a pre-release
|
28
|
+
# @return [Sawyer::Resource] The release
|
29
|
+
# @see https://developer.github.com/v3/repos/releases/#create-a-release
|
30
|
+
def create_release(repo, tag_name, options = {})
|
31
|
+
opts = options.merge(:tag_name => tag_name)
|
32
|
+
post "#{Repository.path repo}/releases", opts
|
33
|
+
end
|
34
|
+
|
35
|
+
# Get a release
|
36
|
+
#
|
37
|
+
# @param url [String] URL for the release as returned from .releases
|
38
|
+
# @return [Sawyer::Resource] The release
|
39
|
+
# @see https://developer.github.com/v3/repos/releases/#get-a-single-release
|
40
|
+
def release(url, options = {})
|
41
|
+
get url, options
|
42
|
+
end
|
43
|
+
|
44
|
+
# Update a release
|
45
|
+
#
|
46
|
+
# @param url [String] URL for the release as returned from .releases
|
47
|
+
# @option options [String] :target_commitish Specifies the commitish value that determines where the Git tag is created from.
|
48
|
+
# @option options [String] :name Name for the release
|
49
|
+
# @option options [String] :body Content for release notes
|
50
|
+
# @option options [Boolean] :draft Mark this release as a draft
|
51
|
+
# @option options [Boolean] :prerelease Mark this release as a pre-release
|
52
|
+
# @return [Sawyer::Resource] The release
|
53
|
+
# @see https://developer.github.com/v3/repos/releases/#edit-a-release
|
54
|
+
def update_release(url, options = {})
|
55
|
+
patch url, options
|
56
|
+
end
|
57
|
+
alias :edit_release :update_release
|
58
|
+
|
59
|
+
# Delete a release
|
60
|
+
#
|
61
|
+
# @param url [String] URL for the release as returned from .releases
|
62
|
+
# @return [Boolean] Success or failure
|
63
|
+
# @see https://developer.github.com/v3/repos/releases/#delete-a-release
|
64
|
+
def delete_release(url, options = {})
|
65
|
+
boolean_from_response(:delete, url, options)
|
66
|
+
end
|
67
|
+
|
68
|
+
# List release assets
|
69
|
+
#
|
70
|
+
# @param release_url [String] URL for the release as returned from .releases
|
71
|
+
# @return [Array<Sawyer::Resource>] A list of release assets
|
72
|
+
# @see https://developer.github.com/v3/repos/releases/#list-assets-for-a-release
|
73
|
+
def release_assets(release_url, options = {})
|
74
|
+
paginate release(release_url).rels[:assets].href, options
|
75
|
+
end
|
76
|
+
|
77
|
+
# Upload a release asset
|
78
|
+
#
|
79
|
+
# @param release_url [String] URL for the release as returned from .releases
|
80
|
+
# @param path_or_file [String] Path to file to upload
|
81
|
+
# @option options [String] :content_type The MIME type for the file to upload
|
82
|
+
# @option options [String] :name The name for the file
|
83
|
+
# @return [Sawyer::Resource] The release asset
|
84
|
+
# @see https://developer.github.com/v3/repos/releases/#upload-a-release-asset
|
85
|
+
def upload_asset(release_url, path_or_file, options = {})
|
86
|
+
file = path_or_file.respond_to?(:read) ? path_or_file : File.new(path_or_file, "rb")
|
87
|
+
options[:content_type] ||= content_type_from_file(file)
|
88
|
+
raise Octokit::MissingContentType.new if options[:content_type].nil?
|
89
|
+
unless name = options[:name]
|
90
|
+
name = File.basename(file.path)
|
91
|
+
end
|
92
|
+
upload_url = release(release_url).rels[:upload].href_template.expand(:name => name)
|
93
|
+
|
94
|
+
request :post, upload_url, file.read, parse_query_and_convenience_headers(options)
|
95
|
+
ensure
|
96
|
+
file.close if file
|
97
|
+
end
|
98
|
+
|
99
|
+
# Get a single release asset
|
100
|
+
#
|
101
|
+
#
|
102
|
+
# @param asset_url [String] URL for the asset as returned from .release_assets
|
103
|
+
# @return [Sawyer::Resource] The release asset
|
104
|
+
# @see https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
|
105
|
+
def release_asset(asset_url, options = {})
|
106
|
+
get(asset_url, options)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Update a release asset
|
110
|
+
#
|
111
|
+
# @param asset_url [String] URL for the asset as returned from .release_assets
|
112
|
+
# @option options [String] :name The name for the file
|
113
|
+
# @option options [String] :label The download text for the file
|
114
|
+
# @return [Sawyer::Resource] The release asset
|
115
|
+
# @see https://developer.github.com/v3/repos/releases/#edit-a-release-asset
|
116
|
+
def update_release_asset(asset_url, options = {})
|
117
|
+
patch(asset_url, options)
|
118
|
+
end
|
119
|
+
alias :edit_release_asset :update_release_asset
|
120
|
+
|
121
|
+
# Delete a release asset
|
122
|
+
#
|
123
|
+
# @param asset_url [String] URL for the asset as returned from .release_assets
|
124
|
+
# @return [Boolean] Success or failure
|
125
|
+
# @see https://developer.github.com/v3/repos/releases/#delete-a-release-asset
|
126
|
+
def delete_release_asset(asset_url, options = {})
|
127
|
+
boolean_from_response(:delete, asset_url, options)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Get the release for a given tag
|
131
|
+
#
|
132
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
133
|
+
# @param tag_name [String] the name for a tag
|
134
|
+
# @return [Sawyer::Resource] The release
|
135
|
+
# @see https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name
|
136
|
+
def release_for_tag(repo, tag_name, options = {})
|
137
|
+
get "#{Repository.path repo}/releases/tags/#{tag_name}", options
|
138
|
+
end
|
139
|
+
|
140
|
+
# Get the latest release
|
141
|
+
#
|
142
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
143
|
+
# @return [Sawyer::Resource] The release
|
144
|
+
# @see https://developer.github.com/v3/repos/releases/#get-the-latest-release
|
145
|
+
def latest_release(repo, options = {})
|
146
|
+
get "#{Repository.path repo}/releases/latest", options
|
147
|
+
end
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
def content_type_from_file(file)
|
152
|
+
require 'mime/types'
|
153
|
+
if mime_type = MIME::Types.type_for(file.path).first
|
154
|
+
mime_type.content_type
|
155
|
+
end
|
156
|
+
rescue LoadError
|
157
|
+
msg = "Please pass content_type or install mime-types gem to guess content type from file"
|
158
|
+
raise Octokit::MissingContentType.new(msg)
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,654 @@
|
|
1
|
+
module Octokit
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Methods for the Repositories API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/repos/
|
7
|
+
module Repositories
|
8
|
+
|
9
|
+
# Check if a repository exists
|
10
|
+
#
|
11
|
+
# @see https://developer.github.com/v3/repos/#get
|
12
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
13
|
+
# @return [Sawyer::Resource] if a repository exists, false otherwise
|
14
|
+
def repository?(repo, options = {})
|
15
|
+
!!repository(repo, options)
|
16
|
+
rescue Octokit::InvalidRepository
|
17
|
+
false
|
18
|
+
rescue Octokit::NotFound
|
19
|
+
false
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get a single repository
|
23
|
+
#
|
24
|
+
# @see https://developer.github.com/v3/repos/#get
|
25
|
+
# @see https://developer.github.com/v3/licenses/#get-a-repositorys-license
|
26
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
27
|
+
# @return [Sawyer::Resource] Repository information
|
28
|
+
def repository(repo, options = {})
|
29
|
+
get Repository.path(repo), options
|
30
|
+
end
|
31
|
+
alias :repo :repository
|
32
|
+
|
33
|
+
# Edit a repository
|
34
|
+
#
|
35
|
+
# @see https://developer.github.com/v3/repos/#edit
|
36
|
+
# @param repo [String, Hash, Repository] A GitHub repository
|
37
|
+
# @param options [Hash] Repository information to update
|
38
|
+
# @option options [String] :name Name of the repo
|
39
|
+
# @option options [String] :description Description of the repo
|
40
|
+
# @option options [String] :homepage Home page of the repo
|
41
|
+
# @option options [String] :private `true` makes the repository private, and `false` makes it public.
|
42
|
+
# @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
|
43
|
+
# @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
|
44
|
+
# @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
|
45
|
+
# @option options [String] :default_branch Update the default branch for this repository.
|
46
|
+
# @return [Sawyer::Resource] Repository information
|
47
|
+
def edit_repository(repo, options = {})
|
48
|
+
repo = Repository.new(repo)
|
49
|
+
options[:name] ||= repo.name
|
50
|
+
patch "repos/#{repo}", options
|
51
|
+
end
|
52
|
+
alias :edit :edit_repository
|
53
|
+
alias :update_repository :edit_repository
|
54
|
+
alias :update :edit_repository
|
55
|
+
|
56
|
+
# List user repositories
|
57
|
+
#
|
58
|
+
# If user is not supplied, repositories for the current
|
59
|
+
# authenticated user are returned.
|
60
|
+
#
|
61
|
+
# @note If the user provided is a GitHub organization, only the
|
62
|
+
# organization's public repositories will be listed. For retrieving
|
63
|
+
# organization repositories the {Organizations#organization_repositories}
|
64
|
+
# method should be used instead.
|
65
|
+
# @see https://developer.github.com/v3/repos/#list-your-repositories
|
66
|
+
# @see https://developer.github.com/v3/repos/#list-user-repositories
|
67
|
+
# @param user [Integer, String] Optional GitHub user login or id for which
|
68
|
+
# to list repos.
|
69
|
+
# @return [Array<Sawyer::Resource>] List of repositories
|
70
|
+
def repositories(user=nil, options = {})
|
71
|
+
paginate "#{User.path user}/repos", options
|
72
|
+
end
|
73
|
+
alias :list_repositories :repositories
|
74
|
+
alias :list_repos :repositories
|
75
|
+
alias :repos :repositories
|
76
|
+
|
77
|
+
# List all repositories
|
78
|
+
#
|
79
|
+
# This provides a dump of every repository, in the order that they were
|
80
|
+
# created.
|
81
|
+
#
|
82
|
+
# @see https://developer.github.com/v3/repos/#list-all-public-repositories
|
83
|
+
#
|
84
|
+
# @param options [Hash] Optional options
|
85
|
+
# @option options [Integer] :since The integer ID of the last Repository
|
86
|
+
# that you’ve seen.
|
87
|
+
# @return [Array<Sawyer::Resource>] List of repositories.
|
88
|
+
def all_repositories(options = {})
|
89
|
+
paginate 'repositories', options
|
90
|
+
end
|
91
|
+
|
92
|
+
# Star a repository
|
93
|
+
#
|
94
|
+
# @param repo [String, Hash, Repository] A GitHub repository
|
95
|
+
# @return [Boolean] `true` if successfully starred
|
96
|
+
# @see https://developer.github.com/v3/activity/starring/#star-a-repository
|
97
|
+
def star(repo, options = {})
|
98
|
+
boolean_from_response :put, "user/starred/#{Repository.new(repo)}", options
|
99
|
+
end
|
100
|
+
|
101
|
+
# Unstar a repository
|
102
|
+
#
|
103
|
+
# @param repo [String, Hash, Repository] A GitHub repository
|
104
|
+
# @return [Boolean] `true` if successfully unstarred
|
105
|
+
# @see https://developer.github.com/v3/activity/starring/#unstar-a-repository
|
106
|
+
def unstar(repo, options = {})
|
107
|
+
boolean_from_response :delete, "user/starred/#{Repository.new(repo)}", options
|
108
|
+
end
|
109
|
+
|
110
|
+
# Watch a repository
|
111
|
+
#
|
112
|
+
# @param repo [String, Hash, Repository] A GitHub repository
|
113
|
+
# @return [Boolean] `true` if successfully watched
|
114
|
+
# @deprecated Use #star instead
|
115
|
+
# @see https://developer.github.com/v3/activity/watching/#watch-a-repository-legacy
|
116
|
+
def watch(repo, options = {})
|
117
|
+
boolean_from_response :put, "user/watched/#{Repository.new(repo)}", options
|
118
|
+
end
|
119
|
+
|
120
|
+
# Unwatch a repository
|
121
|
+
#
|
122
|
+
# @param repo [String, Hash, Repository] A GitHub repository
|
123
|
+
# @return [Boolean] `true` if successfully unwatched
|
124
|
+
# @deprecated Use #unstar instead
|
125
|
+
# @see https://developer.github.com/v3/activity/watching/#stop-watching-a-repository-legacy
|
126
|
+
def unwatch(repo, options = {})
|
127
|
+
boolean_from_response :delete, "user/watched/#{Repository.new(repo)}", options
|
128
|
+
end
|
129
|
+
|
130
|
+
# Fork a repository
|
131
|
+
#
|
132
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
133
|
+
# @return [Sawyer::Resource] Repository info for the new fork
|
134
|
+
# @see https://developer.github.com/v3/repos/forks/#create-a-fork
|
135
|
+
def fork(repo, options = {})
|
136
|
+
post "#{Repository.path repo}/forks", options
|
137
|
+
end
|
138
|
+
|
139
|
+
# Create a repository for a user or organization
|
140
|
+
#
|
141
|
+
# @param name [String] Name of the new repo
|
142
|
+
# @option options [String] :description Description of the repo
|
143
|
+
# @option options [String] :homepage Home page of the repo
|
144
|
+
# @option options [String] :private `true` makes the repository private, and `false` makes it public.
|
145
|
+
# @option options [String] :has_issues `true` enables issues for this repo, `false` disables issues.
|
146
|
+
# @option options [String] :has_wiki `true` enables wiki for this repo, `false` disables wiki.
|
147
|
+
# @option options [String] :has_downloads `true` enables downloads for this repo, `false` disables downloads.
|
148
|
+
# @option options [String] :organization Short name for the org under which to create the repo.
|
149
|
+
# @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.
|
150
|
+
# @option options [Boolean] :auto_init `true` to create an initial commit with empty README. Default is `false`.
|
151
|
+
# @option options [String] :gitignore_template Desired language or platform .gitignore template to apply. Ignored if auto_init parameter is not provided.
|
152
|
+
# @return [Sawyer::Resource] Repository info for the new repository
|
153
|
+
# @see https://developer.github.com/v3/repos/#create
|
154
|
+
def create_repository(name, options = {})
|
155
|
+
opts = options.dup
|
156
|
+
organization = opts.delete :organization
|
157
|
+
opts.merge! :name => name
|
158
|
+
|
159
|
+
if organization.nil?
|
160
|
+
post 'user/repos', opts
|
161
|
+
else
|
162
|
+
post "#{Organization.path organization}/repos", opts
|
163
|
+
end
|
164
|
+
end
|
165
|
+
alias :create_repo :create_repository
|
166
|
+
alias :create :create_repository
|
167
|
+
|
168
|
+
# Delete repository
|
169
|
+
#
|
170
|
+
# Note: If OAuth is used, 'delete_repo' scope is required
|
171
|
+
#
|
172
|
+
# @see https://developer.github.com/v3/repos/#delete-a-repository
|
173
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
174
|
+
# @return [Boolean] `true` if repository was deleted
|
175
|
+
def delete_repository(repo, options = {})
|
176
|
+
boolean_from_response :delete, Repository.path(repo), options
|
177
|
+
end
|
178
|
+
alias :delete_repo :delete_repository
|
179
|
+
|
180
|
+
# Hide a public repository
|
181
|
+
#
|
182
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
183
|
+
# @return [Sawyer::Resource] Updated repository info
|
184
|
+
def set_private(repo, options = {})
|
185
|
+
# GitHub Api for setting private updated to use private attr, rather than public
|
186
|
+
update_repository repo, options.merge({ :private => true })
|
187
|
+
end
|
188
|
+
|
189
|
+
# Unhide a private repository
|
190
|
+
#
|
191
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
192
|
+
# @return [Sawyer::Resource] Updated repository info
|
193
|
+
def set_public(repo, options = {})
|
194
|
+
# GitHub Api for setting private updated to use private attr, rather than public
|
195
|
+
update_repository repo, options.merge({ :private => false })
|
196
|
+
end
|
197
|
+
|
198
|
+
# Get deploy keys on a repo
|
199
|
+
#
|
200
|
+
# Requires authenticated client.
|
201
|
+
#
|
202
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
203
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing deploy keys.
|
204
|
+
# @see https://developer.github.com/v3/repos/keys/#list-deploy-keys
|
205
|
+
# @example
|
206
|
+
# @client.deploy_keys('octokit/octokit.rb')
|
207
|
+
# @example
|
208
|
+
# @client.list_deploy_keys('octokit/octokit.rb')
|
209
|
+
def deploy_keys(repo, options = {})
|
210
|
+
paginate "#{Repository.path repo}/keys", options
|
211
|
+
end
|
212
|
+
alias :list_deploy_keys :deploy_keys
|
213
|
+
|
214
|
+
# Get a single deploy key for a repo
|
215
|
+
#
|
216
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
217
|
+
# @param id [Integer] Deploy key ID.
|
218
|
+
# @return [Sawyer::Resource] Deploy key.
|
219
|
+
# @see https://developer.github.com/v3/repos/keys/#get-a-deploy-key
|
220
|
+
# @example
|
221
|
+
# @client.deploy_key('octokit/octokit.rb', 8675309)
|
222
|
+
def deploy_key(repo, id, options={})
|
223
|
+
get "#{Repository.path repo}/keys/#{id}", options
|
224
|
+
end
|
225
|
+
|
226
|
+
# Add deploy key to a repo
|
227
|
+
#
|
228
|
+
# Requires authenticated client.
|
229
|
+
#
|
230
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
231
|
+
# @param title [String] Title reference for the deploy key.
|
232
|
+
# @param key [String] Public key.
|
233
|
+
# @return [Sawyer::Resource] Hash representing newly added key.
|
234
|
+
# @see https://developer.github.com/v3/repos/keys/#add-a-new-deploy-key
|
235
|
+
# @example
|
236
|
+
# @client.add_deploy_key('octokit/octokit.rb', 'Staging server', 'ssh-rsa AAA...')
|
237
|
+
def add_deploy_key(repo, title, key, options = {})
|
238
|
+
post "#{Repository.path repo}/keys", options.merge(:title => title, :key => key)
|
239
|
+
end
|
240
|
+
|
241
|
+
# Edit a deploy key
|
242
|
+
#
|
243
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
244
|
+
# @param id [Integer] Deploy key ID.
|
245
|
+
# @param options [Hash] Attributes to edit.
|
246
|
+
# @option title [String] Key title.
|
247
|
+
# @option key [String] Public key.
|
248
|
+
# @return [Sawyer::Resource] Updated deploy key.
|
249
|
+
# @deprecated This method is no longer supported in the API
|
250
|
+
# @see https://developer.github.com/changes/2014-02-24-finer-grained-scopes-for-ssh-keys/
|
251
|
+
# @see https://developer.github.com/v3/repos/keys/#edit-a-deploy-key
|
252
|
+
# @example Update the key for a deploy key.
|
253
|
+
# @client.edit_deploy_key('octokit/octokit.rb', 8675309, :key => 'ssh-rsa BBB...')
|
254
|
+
# @example
|
255
|
+
# @client.update_deploy_key('octokit/octokit.rb', 8675309, :title => 'Uber', :key => 'ssh-rsa BBB...'))
|
256
|
+
def edit_deploy_key(repo, id, options)
|
257
|
+
patch "#{Repository.path repo}/keys/#{id}", options
|
258
|
+
end
|
259
|
+
alias :update_deploy_key :edit_deploy_key
|
260
|
+
|
261
|
+
# Remove deploy key from a repo
|
262
|
+
#
|
263
|
+
# Requires authenticated client.
|
264
|
+
#
|
265
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
266
|
+
# @param id [Integer] Id of the deploy key to remove.
|
267
|
+
# @return [Boolean] True if key removed, false otherwise.
|
268
|
+
# @see https://developer.github.com/v3/repos/keys/#remove-a-deploy-key
|
269
|
+
# @example
|
270
|
+
# @client.remove_deploy_key('octokit/octokit.rb', 100000)
|
271
|
+
def remove_deploy_key(repo, id, options = {})
|
272
|
+
boolean_from_response :delete, "#{Repository.path repo}/keys/#{id}", options
|
273
|
+
end
|
274
|
+
|
275
|
+
# List collaborators
|
276
|
+
#
|
277
|
+
# Requires authenticated client for private repos.
|
278
|
+
#
|
279
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
280
|
+
# @option options [String] :affiliation Filters the return array by affiliation.
|
281
|
+
# Can be one of: <tt>outside</tt> or <tt>all</tt>.
|
282
|
+
# If not specified, defaults to <tt>all</tt>
|
283
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing collaborating users.
|
284
|
+
# @see https://developer.github.com/v3/repos/collaborators/#list-collaborators
|
285
|
+
# @example
|
286
|
+
# Octokit.collaborators('octokit/octokit.rb')
|
287
|
+
# @example
|
288
|
+
# Octokit.collabs('octokit/octokit.rb')
|
289
|
+
# @example
|
290
|
+
# @client.collabs('octokit/octokit.rb')
|
291
|
+
def collaborators(repo, options = {})
|
292
|
+
paginate "#{Repository.path repo}/collaborators", options
|
293
|
+
end
|
294
|
+
alias :collabs :collaborators
|
295
|
+
|
296
|
+
# Add collaborator to repo
|
297
|
+
#
|
298
|
+
# This can also be used to update the permission of an existing collaborator
|
299
|
+
#
|
300
|
+
# Requires authenticated client.
|
301
|
+
#
|
302
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
303
|
+
# @param collaborator [String] Collaborator GitHub username to add.
|
304
|
+
# @option options [String] :permission The permission to grant the collaborator.
|
305
|
+
# Only valid on organization-owned repositories.
|
306
|
+
# Can be one of: <tt>pull</tt>, <tt>push</tt>, or <tt>admin</tt>.
|
307
|
+
# If not specified, defaults to <tt>push</tt>
|
308
|
+
# @return [Boolean] True if collaborator added, false otherwise.
|
309
|
+
# @see https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator
|
310
|
+
# @example
|
311
|
+
# @client.add_collaborator('octokit/octokit.rb', 'holman')
|
312
|
+
# @example
|
313
|
+
# @client.add_collab('octokit/octokit.rb', 'holman')
|
314
|
+
# @example Add a collaborator with admin permissions
|
315
|
+
# @client.add_collaborator('octokit/octokit.rb', 'holman', permission: 'admin')
|
316
|
+
def add_collaborator(repo, collaborator, options = {})
|
317
|
+
boolean_from_response :put, "#{Repository.path repo}/collaborators/#{collaborator}", options
|
318
|
+
end
|
319
|
+
alias :add_collab :add_collaborator
|
320
|
+
|
321
|
+
# Remove collaborator from repo.
|
322
|
+
#
|
323
|
+
# Requires authenticated client.
|
324
|
+
#
|
325
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
326
|
+
# @param collaborator [String] Collaborator GitHub username to remove.
|
327
|
+
# @return [Boolean] True if collaborator removed, false otherwise.
|
328
|
+
# @see https://developer.github.com/v3/repos/collaborators/#remove-user-as-a-collaborator
|
329
|
+
# @example
|
330
|
+
# @client.remove_collaborator('octokit/octokit.rb', 'holman')
|
331
|
+
# @example
|
332
|
+
# @client.remove_collab('octokit/octokit.rb', 'holman')
|
333
|
+
def remove_collaborator(repo, collaborator, options = {})
|
334
|
+
boolean_from_response :delete, "#{Repository.path repo}/collaborators/#{collaborator}", options
|
335
|
+
end
|
336
|
+
alias :remove_collab :remove_collaborator
|
337
|
+
|
338
|
+
# Checks if a user is a collaborator for a repo.
|
339
|
+
#
|
340
|
+
# Requires authenticated client.
|
341
|
+
#
|
342
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
343
|
+
# @param collaborator [String] Collaborator GitHub username to check.
|
344
|
+
# @return [Boolean] True if user is a collaborator, false otherwise.
|
345
|
+
# @see https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-collaborator
|
346
|
+
# @example
|
347
|
+
# @client.collaborator?('octokit/octokit.rb', 'holman')
|
348
|
+
def collaborator?(repo, collaborator, options={})
|
349
|
+
boolean_from_response :get, "#{Repository.path repo}/collaborators/#{collaborator}", options
|
350
|
+
end
|
351
|
+
|
352
|
+
# Get a user's permission level for a repo.
|
353
|
+
#
|
354
|
+
# Requires authenticated client
|
355
|
+
#
|
356
|
+
# @return [Sawyer::Resource] Hash representing the user's permission level for the given repository
|
357
|
+
# @see https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level
|
358
|
+
# @example
|
359
|
+
# @client.permission_level('octokit/octokit.rb', 'lizzhale')
|
360
|
+
def permission_level(repo, collaborator, options={})
|
361
|
+
options = ensure_api_media_type(:org_memberships, options)
|
362
|
+
get "#{Repository.path repo}/collaborators/#{collaborator}/permission", options
|
363
|
+
end
|
364
|
+
|
365
|
+
# List teams for a repo
|
366
|
+
#
|
367
|
+
# Requires authenticated client that is an owner or collaborator of the repo.
|
368
|
+
#
|
369
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
370
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing teams.
|
371
|
+
# @see https://developer.github.com/v3/repos/#list-teams
|
372
|
+
# @example
|
373
|
+
# @client.repository_teams('octokit/pengwynn')
|
374
|
+
# @example
|
375
|
+
# @client.repo_teams('octokit/pengwynn')
|
376
|
+
# @example
|
377
|
+
# @client.teams('octokit/pengwynn')
|
378
|
+
def repository_teams(repo, options = {})
|
379
|
+
paginate "#{Repository.path repo}/teams", options
|
380
|
+
end
|
381
|
+
alias :repo_teams :repository_teams
|
382
|
+
alias :teams :repository_teams
|
383
|
+
|
384
|
+
# List contributors to a repo
|
385
|
+
#
|
386
|
+
# Requires authenticated client for private repos.
|
387
|
+
#
|
388
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
389
|
+
# @param anon [Boolean] Set true to include anonymous contributors.
|
390
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing users.
|
391
|
+
# @see https://developer.github.com/v3/repos/#list-contributors
|
392
|
+
# @example
|
393
|
+
# Octokit.contributors('octokit/octokit.rb', true)
|
394
|
+
# @example
|
395
|
+
# Octokit.contribs('octokit/octokit.rb')
|
396
|
+
# @example
|
397
|
+
# @client.contribs('octokit/octokit.rb')
|
398
|
+
def contributors(repo, anon = nil, options = {})
|
399
|
+
options[:anon] = 1 if anon.to_s[/1|true/]
|
400
|
+
paginate "#{Repository.path repo}/contributors", options
|
401
|
+
end
|
402
|
+
alias :contribs :contributors
|
403
|
+
|
404
|
+
# List stargazers of a repo
|
405
|
+
#
|
406
|
+
# Requires authenticated client for private repos.
|
407
|
+
#
|
408
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
409
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing users.
|
410
|
+
# @see https://developer.github.com/v3/activity/starring/#list-stargazers
|
411
|
+
# @example
|
412
|
+
# Octokit.stargazers('octokit/octokit.rb')
|
413
|
+
# @example
|
414
|
+
# @client.stargazers('octokit/octokit.rb')
|
415
|
+
def stargazers(repo, options = {})
|
416
|
+
paginate "#{Repository.path repo}/stargazers", options
|
417
|
+
end
|
418
|
+
|
419
|
+
# @deprecated Use {#stargazers} instead
|
420
|
+
#
|
421
|
+
# List watchers of repo.
|
422
|
+
#
|
423
|
+
# Requires authenticated client for private repos.
|
424
|
+
#
|
425
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
426
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing users.
|
427
|
+
# @see https://developer.github.com/v3/repos/watching/#list-watchers
|
428
|
+
# @example
|
429
|
+
# Octokit.watchers('octokit/octokit.rb')
|
430
|
+
# @example
|
431
|
+
# @client.watchers('octokit/octokit.rb')
|
432
|
+
def watchers(repo, options = {})
|
433
|
+
paginate "#{Repository.path repo}/watchers", options
|
434
|
+
end
|
435
|
+
|
436
|
+
# List forks
|
437
|
+
#
|
438
|
+
# Requires authenticated client for private repos.
|
439
|
+
#
|
440
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
441
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing repos.
|
442
|
+
# @see https://developer.github.com/v3/repos/forks/#list-forks
|
443
|
+
# @example
|
444
|
+
# Octokit.forks('octokit/octokit.rb')
|
445
|
+
# @example
|
446
|
+
# Octokit.network('octokit/octokit.rb')
|
447
|
+
# @example
|
448
|
+
# @client.forks('octokit/octokit.rb')
|
449
|
+
def forks(repo, options = {})
|
450
|
+
paginate "#{Repository.path repo}/forks", options
|
451
|
+
end
|
452
|
+
alias :network :forks
|
453
|
+
|
454
|
+
# List languages of code in the repo.
|
455
|
+
#
|
456
|
+
# Requires authenticated client for private repos.
|
457
|
+
#
|
458
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
459
|
+
# @return [Array<Sawyer::Resource>] Array of Hashes representing languages.
|
460
|
+
# @see https://developer.github.com/v3/repos/#list-languages
|
461
|
+
# @example
|
462
|
+
# Octokit.languages('octokit/octokit.rb')
|
463
|
+
# @example
|
464
|
+
# @client.languages('octokit/octokit.rb')
|
465
|
+
def languages(repo, options = {})
|
466
|
+
paginate "#{Repository.path repo}/languages", options
|
467
|
+
end
|
468
|
+
|
469
|
+
# List tags
|
470
|
+
#
|
471
|
+
# Requires authenticated client for private repos.
|
472
|
+
#
|
473
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
474
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing tags.
|
475
|
+
# @see https://developer.github.com/v3/repos/#list-tags
|
476
|
+
# @example
|
477
|
+
# Octokit.tags('octokit/octokit.rb')
|
478
|
+
# @example
|
479
|
+
# @client.tags('octokit/octokit.rb')
|
480
|
+
def tags(repo, options = {})
|
481
|
+
paginate "#{Repository.path repo}/tags", options
|
482
|
+
end
|
483
|
+
|
484
|
+
# List branches
|
485
|
+
#
|
486
|
+
# Requires authenticated client for private repos.
|
487
|
+
#
|
488
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
489
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing branches.
|
490
|
+
# @see https://developer.github.com/v3/repos/#list-branches
|
491
|
+
# @example
|
492
|
+
# Octokit.branches('octokit/octokit.rb')
|
493
|
+
# @example
|
494
|
+
# @client.branches('octokit/octokit.rb')
|
495
|
+
def branches(repo, options = {})
|
496
|
+
paginate "#{Repository.path repo}/branches", options
|
497
|
+
end
|
498
|
+
|
499
|
+
# Get a single branch from a repository
|
500
|
+
#
|
501
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
502
|
+
# @param branch [String] Branch name
|
503
|
+
# @return [Sawyer::Resource] The branch requested, if it exists
|
504
|
+
# @see https://developer.github.com/v3/repos/#get-branch
|
505
|
+
# @example Get branch 'master` from octokit/octokit.rb
|
506
|
+
# Octokit.branch("octokit/octokit.rb", "master")
|
507
|
+
def branch(repo, branch, options = {})
|
508
|
+
get "#{Repository.path repo}/branches/#{branch}", options
|
509
|
+
end
|
510
|
+
alias :get_branch :branch
|
511
|
+
|
512
|
+
# Lock a single branch from a repository
|
513
|
+
#
|
514
|
+
# Requires authenticated client
|
515
|
+
#
|
516
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
517
|
+
# @param branch [String] Branch name
|
518
|
+
# @option options [Hash] :required_status_checks If not null, the following keys are required:
|
519
|
+
# <tt>:include_admins [boolean] Enforce required status checks for repository administrators.</tt>
|
520
|
+
# <tt>:strict [boolean] Require branches to be up to date before merging.</tt>
|
521
|
+
# <tt>:contexts [Array] The list of status checks to require in order to merge into this branch</tt>
|
522
|
+
#
|
523
|
+
# @option options [Hash] :restrictions If not null, the following keys are required:
|
524
|
+
# <tt>:users [Array] The list of user logins with push access</tt>
|
525
|
+
# <tt>:teams [Array] The list of team slugs with push access</tt>.
|
526
|
+
#
|
527
|
+
# Teams and users restrictions are only available for organization-owned repositories.
|
528
|
+
# @return [Sawyer::Resource] The protected branch
|
529
|
+
# @see https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection
|
530
|
+
# @example
|
531
|
+
# @client.protect_branch('octokit/octokit.rb', 'master', foo)
|
532
|
+
def protect_branch(repo, branch, options = {})
|
533
|
+
opts = ensure_api_media_type(:branch_protection, options)
|
534
|
+
opts[:restrictions] ||= nil
|
535
|
+
opts[:required_status_checks] ||= nil
|
536
|
+
put "#{Repository.path repo}/branches/#{branch}/protection", opts
|
537
|
+
end
|
538
|
+
|
539
|
+
# Get branch protection summary
|
540
|
+
#
|
541
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
542
|
+
# @param branch [String] Branch name
|
543
|
+
# @return [Sawyer::Resource, nil] Branch protection summary or nil if the branch
|
544
|
+
# is not protected
|
545
|
+
# @see https://developer.github.com/v3/repos/branches/#get-branch-protection
|
546
|
+
# @example
|
547
|
+
# @client.branch_protection('octokit/octokit.rb', 'master')
|
548
|
+
def branch_protection(repo, branch, options = {})
|
549
|
+
opts = ensure_api_media_type(:branch_protection, options)
|
550
|
+
begin
|
551
|
+
get "#{Repository.path repo}/branches/#{branch}/protection", opts
|
552
|
+
rescue Octokit::BranchNotProtected
|
553
|
+
nil
|
554
|
+
end
|
555
|
+
end
|
556
|
+
|
557
|
+
# Unlock a single branch from a repository
|
558
|
+
#
|
559
|
+
# Requires authenticated client
|
560
|
+
#
|
561
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
562
|
+
# @param branch [String] Branch name
|
563
|
+
# @return [Sawyer::Resource] The unprotected branch
|
564
|
+
# @see https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection
|
565
|
+
# @example
|
566
|
+
# @client.unprotect_branch('octokit/octokit.rb', 'master')
|
567
|
+
def unprotect_branch(repo, branch, options = {})
|
568
|
+
opts = ensure_api_media_type(:branch_protection, options)
|
569
|
+
boolean_from_response :delete, "#{Repository.path repo}/branches/#{branch}/protection", opts
|
570
|
+
end
|
571
|
+
|
572
|
+
# List users available for assigning to issues.
|
573
|
+
#
|
574
|
+
# Requires authenticated client for private repos.
|
575
|
+
#
|
576
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
577
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing users.
|
578
|
+
# @see https://developer.github.com/v3/issues/assignees/#list-assignees
|
579
|
+
# @example
|
580
|
+
# Octokit.repository_assignees('octokit/octokit.rb')
|
581
|
+
# @example
|
582
|
+
# Octokit.repo_assignees('octokit/octokit.rb')
|
583
|
+
# @example
|
584
|
+
# @client.repository_assignees('octokit/octokit.rb')
|
585
|
+
def repository_assignees(repo, options = {})
|
586
|
+
paginate "#{Repository.path repo}/assignees", options
|
587
|
+
end
|
588
|
+
alias :repo_assignees :repository_assignees
|
589
|
+
|
590
|
+
# Check to see if a particular user is an assignee for a repository.
|
591
|
+
#
|
592
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
593
|
+
# @param assignee [String] User login to check
|
594
|
+
# @return [Boolean] True if assignable on project, false otherwise.
|
595
|
+
# @see https://developer.github.com/v3/issues/assignees/#check-assignee
|
596
|
+
# @example
|
597
|
+
# Octokit.check_assignee('octokit/octokit.rb', 'andrew')
|
598
|
+
def check_assignee(repo, assignee, options = {})
|
599
|
+
boolean_from_response :get, "#{Repository.path repo}/assignees/#{assignee}", options
|
600
|
+
end
|
601
|
+
|
602
|
+
# List watchers subscribing to notifications for a repo
|
603
|
+
#
|
604
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
605
|
+
# @return [Array<Sawyer::Resource>] Array of users watching.
|
606
|
+
# @see https://developer.github.com/v3/activity/watching/#list-watchers
|
607
|
+
# @example
|
608
|
+
# @client.subscribers("octokit/octokit.rb")
|
609
|
+
def subscribers(repo, options = {})
|
610
|
+
paginate "#{Repository.path repo}/subscribers", options
|
611
|
+
end
|
612
|
+
|
613
|
+
# Get a repository subscription
|
614
|
+
#
|
615
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
616
|
+
# @return [Sawyer::Resource] Repository subscription.
|
617
|
+
# @see https://developer.github.com/v3/activity/watching/#get-a-repository-subscription
|
618
|
+
# @example
|
619
|
+
# @client.subscription("octokit/octokit.rb")
|
620
|
+
def subscription(repo, options = {})
|
621
|
+
get "#{Repository.path repo}/subscription", options
|
622
|
+
end
|
623
|
+
|
624
|
+
# Update repository subscription
|
625
|
+
#
|
626
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
627
|
+
# @param options [Hash]
|
628
|
+
#
|
629
|
+
# @option options [Boolean] :subscribed Determines if notifications
|
630
|
+
# should be received from this repository.
|
631
|
+
# @option options [Boolean] :ignored Deterimines if all notifications
|
632
|
+
# should be blocked from this repository.
|
633
|
+
# @return [Sawyer::Resource] Updated repository subscription.
|
634
|
+
# @see https://developer.github.com/v3/activity/watching/#set-a-repository-subscription
|
635
|
+
# @example Subscribe to notifications for a repository
|
636
|
+
# @client.update_subscription("octokit/octokit.rb", {subscribed: true})
|
637
|
+
def update_subscription(repo, options = {})
|
638
|
+
put "#{Repository.path repo}/subscription", options
|
639
|
+
end
|
640
|
+
|
641
|
+
# Delete a repository subscription
|
642
|
+
#
|
643
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
644
|
+
# @return [Boolean] True if subscription deleted, false otherwise.
|
645
|
+
# @see https://developer.github.com/v3/activity/watching/#delete-a-repository-subscription
|
646
|
+
#
|
647
|
+
# @example
|
648
|
+
# @client.delete_subscription("octokit/octokit.rb")
|
649
|
+
def delete_subscription(repo, options = {})
|
650
|
+
boolean_from_response :delete, "#{Repository.path repo}/subscription", options
|
651
|
+
end
|
652
|
+
end
|
653
|
+
end
|
654
|
+
end
|