octokit 7.2.0 → 9.2.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.
- checksums.yaml +4 -4
- data/README.md +6 -22
- data/lib/octokit/arguments.rb +1 -1
- data/lib/octokit/client/actions_secrets.rb +49 -0
- data/lib/octokit/client/apps.rb +12 -0
- data/lib/octokit/client/code_scanning.rb +139 -2
- data/lib/octokit/client/codespaces_secrets.rb +49 -0
- data/lib/octokit/client/contents.rb +1 -3
- data/lib/octokit/client/dependabot_secrets.rb +49 -0
- data/lib/octokit/client/deployments.rb +2 -2
- data/lib/octokit/client/environments.rb +4 -1
- data/lib/octokit/client/oauth_applications.rb +1 -1
- data/lib/octokit/client/pull_requests.rb +18 -9
- data/lib/octokit/client/reactions.rb +49 -0
- data/lib/octokit/client/repositories.rb +43 -0
- data/lib/octokit/client/users.rb +27 -0
- data/lib/octokit/client.rb +2 -2
- data/lib/octokit/configurable.rb +17 -1
- data/lib/octokit/connection.rb +2 -0
- data/lib/octokit/default.rb +18 -0
- data/lib/octokit/enterprise_management_console_client/management_console.rb +19 -1
- data/lib/octokit/error.rb +6 -0
- data/lib/octokit/manage_ghes_client/manage_ghes.rb +178 -0
- data/lib/octokit/manage_ghes_client.rb +64 -0
- data/lib/octokit/middleware/follow_redirects.rb +1 -1
- data/lib/octokit/repo_arguments.rb +1 -1
- data/lib/octokit/repository.rb +7 -1
- data/lib/octokit/version.rb +1 -1
- data/lib/octokit.rb +16 -1
- metadata +8 -7
- data/lib/octokit/client/pub_sub_hubbub.rb +0 -111
@@ -150,6 +150,55 @@ module Octokit
|
|
150
150
|
def delete_issue_reaction(repo, issue_id, reaction_id, options = {})
|
151
151
|
boolean_from_response :delete, "#{Repository.path repo}/issues/#{issue_id}/reactions/#{reaction_id}", options
|
152
152
|
end
|
153
|
+
|
154
|
+
# List reactions for a release
|
155
|
+
#
|
156
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
157
|
+
# @param id [Integer] The Release id
|
158
|
+
#
|
159
|
+
# @see https://docs.github.com/en/free-pro-team@latest/rest/reactions/reactions?apiVersion=2022-11-28#list-reactions-for-a-release
|
160
|
+
#
|
161
|
+
# @example
|
162
|
+
# @client.release_reactions("octokit/octokit.rb", 1)
|
163
|
+
#
|
164
|
+
# @return [Array<Sawyer::Resource>] Array of Hashes representing the reactions.
|
165
|
+
def release_reactions(repo, release_id, options = {})
|
166
|
+
get "#{Repository.path repo}/releases/#{release_id}/reactions", options
|
167
|
+
end
|
168
|
+
|
169
|
+
# Create reaction for a release
|
170
|
+
#
|
171
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
172
|
+
# @param id [Integer] The Release id
|
173
|
+
# @param reaction [String] The Reaction
|
174
|
+
#
|
175
|
+
# @see https://docs.github.com/en/free-pro-team@latest/rest/reactions/reactions?apiVersion=2022-11-28#create-reaction-for-a-release
|
176
|
+
# @see https://developer.github.com/v3/reactions/#reaction-types
|
177
|
+
#
|
178
|
+
# @example
|
179
|
+
# @client.create_release_reaction("octokit/octokit.rb", 1)
|
180
|
+
#
|
181
|
+
# @return [<Sawyer::Resource>] Hash representing the reaction.
|
182
|
+
def create_release_reaction(repo, release_id, reaction, options = {})
|
183
|
+
options = options.merge(content: reaction)
|
184
|
+
post "#{Repository.path repo}/releases/#{release_id}/reactions", options
|
185
|
+
end
|
186
|
+
|
187
|
+
# Delete a reaction for a release
|
188
|
+
#
|
189
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
190
|
+
# @param issue_id [Integer] The Release id
|
191
|
+
# @param reaction_id [Integer] The Reaction id
|
192
|
+
#
|
193
|
+
# @see https://docs.github.com/en/free-pro-team@latest/rest/reactions/reactions?apiVersion=2022-11-28#delete-a-release-reaction
|
194
|
+
#
|
195
|
+
# @example
|
196
|
+
# @client.delete_release_reaction("octokit/octokit.rb", 1, 2)
|
197
|
+
#
|
198
|
+
# @return [Boolean] Return true if reaction was deleted, false otherwise.
|
199
|
+
def delete_release_reaction(repo, release_id, reaction_id, options = {})
|
200
|
+
boolean_from_response :delete, "#{Repository.path repo}/releases/#{release_id}/reactions/#{reaction_id}", options
|
201
|
+
end
|
153
202
|
end
|
154
203
|
end
|
155
204
|
end
|
@@ -774,6 +774,49 @@ module Octokit
|
|
774
774
|
def disable_vulnerability_alerts(repo, options = {})
|
775
775
|
boolean_from_response(:delete, "#{Repository.path repo}/vulnerability-alerts", options)
|
776
776
|
end
|
777
|
+
|
778
|
+
# Check to see if automated security fixes are enabled for a repository
|
779
|
+
#
|
780
|
+
# The authenticated user must have admin access to the repository.
|
781
|
+
#
|
782
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
783
|
+
# @return [Boolean] True if automated security fixes are enabled, false otherwise.
|
784
|
+
# @see https://docs.github.com/en/rest/reference/repos#check-if-automated-security-fixes-are-enabled-for-a-repository
|
785
|
+
#
|
786
|
+
# @example
|
787
|
+
# @client.automated_security_fixes_enabled?("octokit/octokit.rb")
|
788
|
+
def automated_security_fixes_enabled?(repo, options = {})
|
789
|
+
response = get "#{Repository.path repo}/automated-security-fixes", options
|
790
|
+
return response[:enabled] if @last_response.status == 200
|
791
|
+
|
792
|
+
false
|
793
|
+
end
|
794
|
+
|
795
|
+
# Enable automated security fixes for a repository
|
796
|
+
#
|
797
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
798
|
+
# @param options [Hash]
|
799
|
+
#
|
800
|
+
# @return [Boolean] True if vulnerability alerts enabled, false otherwise.
|
801
|
+
# @see https://docs.github.com/en/rest/reference/repos#automated-security-fixes
|
802
|
+
# @example Enable automated security fixes for a repository
|
803
|
+
# @client.enable_automated_security_fixes("octokit/octokit.rb")
|
804
|
+
def enable_automated_security_fixes(repo, options = {})
|
805
|
+
boolean_from_response(:put, "#{Repository.path repo}/automated-security-fixes", options)
|
806
|
+
end
|
807
|
+
|
808
|
+
# Disable automated security fixes for a repository
|
809
|
+
#
|
810
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
811
|
+
# @param options [Hash]
|
812
|
+
#
|
813
|
+
# @return [Boolean] True if vulnerability alerts disabled, false otherwise.
|
814
|
+
# @see https://docs.github.com/en/rest/reference/repos#automated-security-fixes
|
815
|
+
# @example Disable automated security fixes for a repository
|
816
|
+
# @client.disable_automated_security_fixes("octokit/octokit.rb")
|
817
|
+
def disable_automated_security_fixes(repo, options = {})
|
818
|
+
boolean_from_response(:delete, "#{Repository.path repo}/automated-security-fixes", options)
|
819
|
+
end
|
777
820
|
end
|
778
821
|
end
|
779
822
|
end
|
data/lib/octokit/client/users.rb
CHANGED
@@ -57,6 +57,33 @@ module Octokit
|
|
57
57
|
post "#{web_endpoint}login/oauth/access_token", options
|
58
58
|
end
|
59
59
|
|
60
|
+
# Refresh a user's access token with a refresh token.
|
61
|
+
#
|
62
|
+
# Applications can refresh an access token without requiring a user to re-authorize using refresh access token.
|
63
|
+
#
|
64
|
+
# @param code [String] 40 character GitHub OAuth refresh access token
|
65
|
+
#
|
66
|
+
# @return [Sawyer::Resource]
|
67
|
+
# @see https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/refreshing-user-access-tokens#refreshing-a-user-access-token-with-a-refresh-token
|
68
|
+
#
|
69
|
+
# @example
|
70
|
+
# client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
|
71
|
+
# client.refresh_access_token('40-character-refresh-token')
|
72
|
+
def refresh_access_token(code, app_id = client_id, app_secret = client_secret, options = {})
|
73
|
+
options = options.merge({
|
74
|
+
refresh_token: code,
|
75
|
+
client_id: app_id,
|
76
|
+
client_secret: app_secret,
|
77
|
+
grant_type: 'refresh_token',
|
78
|
+
headers: {
|
79
|
+
content_type: 'application/json',
|
80
|
+
accept: 'application/json'
|
81
|
+
}
|
82
|
+
})
|
83
|
+
|
84
|
+
post "#{web_endpoint}login/oauth/access_token", options
|
85
|
+
end
|
86
|
+
|
60
87
|
# Validate user username and password
|
61
88
|
#
|
62
89
|
# @param options [Hash] User credentials
|
data/lib/octokit/client.rb
CHANGED
@@ -50,7 +50,6 @@ require 'octokit/client/objects'
|
|
50
50
|
require 'octokit/client/organizations'
|
51
51
|
require 'octokit/client/pages'
|
52
52
|
require 'octokit/client/projects'
|
53
|
-
require 'octokit/client/pub_sub_hubbub'
|
54
53
|
require 'octokit/client/pull_requests'
|
55
54
|
require 'octokit/client/rate_limit'
|
56
55
|
require 'octokit/client/reactions'
|
@@ -118,7 +117,6 @@ module Octokit
|
|
118
117
|
include Octokit::Client::Organizations
|
119
118
|
include Octokit::Client::Pages
|
120
119
|
include Octokit::Client::Projects
|
121
|
-
include Octokit::Client::PubSubHubbub
|
122
120
|
include Octokit::Client::PullRequests
|
123
121
|
include Octokit::Client::RateLimit
|
124
122
|
include Octokit::Client::Reactions
|
@@ -261,6 +259,7 @@ module Octokit
|
|
261
259
|
conn_opts[:proxy] = @proxy if @proxy
|
262
260
|
conn_opts[:ssl] = { verify_mode: @ssl_verify_mode } if @ssl_verify_mode
|
263
261
|
conn = Faraday.new(conn_opts) do |http|
|
262
|
+
http_cache_middleware = http.builder.handlers.delete(Faraday::HttpCache) if Faraday.const_defined?(:HttpCache)
|
264
263
|
if basic_authenticated?
|
265
264
|
http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
|
266
265
|
elsif token_authenticated?
|
@@ -268,6 +267,7 @@ module Octokit
|
|
268
267
|
elsif bearer_authenticated?
|
269
268
|
http.request :authorization, 'Bearer', @bearer_token
|
270
269
|
end
|
270
|
+
http.builder.handlers.push(http_cache_middleware) unless http_cache_middleware.nil?
|
271
271
|
http.headers['accept'] = options[:accept] if options.key?(:accept)
|
272
272
|
end
|
273
273
|
conn.builder.delete(Octokit::Middleware::FollowRedirects)
|
data/lib/octokit/configurable.rb
CHANGED
@@ -32,6 +32,12 @@ module Octokit
|
|
32
32
|
# @return [String] An admin password set up for your GitHub Enterprise management console
|
33
33
|
# @!attribute management_console_endpoint
|
34
34
|
# @return [String] Base URL for API requests to the GitHub Enterprise management console
|
35
|
+
# @!attribute manage_ghes_endpoint
|
36
|
+
# @return [String] Base URL for API requests to the GitHub Enterprise Server Manage API
|
37
|
+
# @!attribute manage_ghes_username
|
38
|
+
# @return [String] API username for requests to the GitHub Enterprise Server Manage API
|
39
|
+
# @!attribute manage_ghes_password
|
40
|
+
# @return [String] API user password for requests to the GitHub Enterprise Server Manage API
|
35
41
|
# @!attribute middleware
|
36
42
|
# @see https://github.com/lostisland/faraday
|
37
43
|
# @return [Faraday::Builder or Faraday::RackBuilder] Configure middleware for Faraday
|
@@ -59,7 +65,10 @@ module Octokit
|
|
59
65
|
:middleware, :netrc, :netrc_file,
|
60
66
|
:per_page, :proxy, :ssl_verify_mode, :user_agent
|
61
67
|
attr_writer :password, :web_endpoint, :api_endpoint, :login,
|
62
|
-
:management_console_endpoint, :management_console_password
|
68
|
+
:management_console_endpoint, :management_console_password,
|
69
|
+
:manage_ghes_endpoint,
|
70
|
+
:manage_ghes_username,
|
71
|
+
:manage_ghes_password
|
63
72
|
|
64
73
|
class << self
|
65
74
|
# List of configurable keys for {Octokit::Client}
|
@@ -77,6 +86,9 @@ module Octokit
|
|
77
86
|
login
|
78
87
|
management_console_endpoint
|
79
88
|
management_console_password
|
89
|
+
manage_ghes_endpoint
|
90
|
+
manage_ghes_username
|
91
|
+
manage_ghes_password
|
80
92
|
middleware
|
81
93
|
netrc
|
82
94
|
netrc_file
|
@@ -126,6 +138,10 @@ module Octokit
|
|
126
138
|
File.join(@management_console_endpoint, '')
|
127
139
|
end
|
128
140
|
|
141
|
+
def manage_ghes_endpoint
|
142
|
+
File.join(@manage_ghes_endpoint, '')
|
143
|
+
end
|
144
|
+
|
129
145
|
# Base URL for generated web URLs
|
130
146
|
#
|
131
147
|
# @return [String] Default: https://github.com/
|
data/lib/octokit/connection.rb
CHANGED
@@ -106,6 +106,7 @@ module Octokit
|
|
106
106
|
http.headers[:accept] = default_media_type
|
107
107
|
http.headers[:content_type] = 'application/json'
|
108
108
|
http.headers[:user_agent] = user_agent
|
109
|
+
http_cache_middleware = http.builder.handlers.delete(Faraday::HttpCache) if Faraday.const_defined?(:HttpCache)
|
109
110
|
if basic_authenticated?
|
110
111
|
http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
|
111
112
|
elsif token_authenticated?
|
@@ -115,6 +116,7 @@ module Octokit
|
|
115
116
|
elsif application_authenticated?
|
116
117
|
http.request(*FARADAY_BASIC_AUTH_KEYS, @client_id, @client_secret)
|
117
118
|
end
|
119
|
+
http.builder.handlers.push(http_cache_middleware) unless http_cache_middleware.nil?
|
118
120
|
end
|
119
121
|
end
|
120
122
|
|
data/lib/octokit/default.rb
CHANGED
@@ -102,6 +102,24 @@ module Octokit
|
|
102
102
|
ENV.fetch('OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT', nil)
|
103
103
|
end
|
104
104
|
|
105
|
+
# Default GHES Manage API endpoint from ENV
|
106
|
+
# @return [String]
|
107
|
+
def manage_ghes_endpoint
|
108
|
+
ENV.fetch('OCTOKIT_MANAGE_GHES_ENDPOINT', nil)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Default GHES Manage API username from ENV
|
112
|
+
# @return [String]
|
113
|
+
def manage_ghes_username
|
114
|
+
ENV.fetch('OCTOKIT_MANAGE_GHES_USERNAME', nil)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Default GHES Manage API password from ENV
|
118
|
+
# @return [String]
|
119
|
+
def manage_ghes_password
|
120
|
+
ENV.fetch('OCTOKIT_MANAGE_GHES_PASSWORD', nil)
|
121
|
+
end
|
122
|
+
|
105
123
|
# Default options for Faraday::Connection
|
106
124
|
# @return [Hash]
|
107
125
|
def connection_options
|
@@ -14,6 +14,7 @@ module Octokit
|
|
14
14
|
# @see https://docs.github.com/en/enterprise-server@3.4/rest/enterprise-admin/management-console#create-a-github-license
|
15
15
|
# @return nil
|
16
16
|
def upload_license(license, settings = nil)
|
17
|
+
octokit_warn('The Management Console API will be deprecated in GitHub Enterprise Server 3.15.0, please use the ManageGHES client instead.')
|
17
18
|
conn = faraday_configuration
|
18
19
|
|
19
20
|
params = {}
|
@@ -28,6 +29,7 @@ module Octokit
|
|
28
29
|
#
|
29
30
|
# @return nil
|
30
31
|
def start_configuration
|
32
|
+
octokit_warn('The Management Console API will be deprecated in GitHub Enterprise Server 3.15.0, please use the ManageGHES client instead.')
|
31
33
|
post '/setup/api/configure', password_hash
|
32
34
|
end
|
33
35
|
|
@@ -37,6 +39,7 @@ module Octokit
|
|
37
39
|
#
|
38
40
|
# @return nil
|
39
41
|
def upgrade(license)
|
42
|
+
octokit_warn('The Management Console API will be deprecated in GitHub Enterprise Server 3.15.0, please use the ManageGHES client instead.')
|
40
43
|
conn = faraday_configuration
|
41
44
|
|
42
45
|
params = {}
|
@@ -49,6 +52,7 @@ module Octokit
|
|
49
52
|
#
|
50
53
|
# @return [Sawyer::Resource] The installation information
|
51
54
|
def config_status
|
55
|
+
octokit_warn('The Management Console API will be deprecated in GitHub Enterprise Server 3.15.0, please use the ManageGHES client instead.')
|
52
56
|
get '/setup/api/configcheck', password_hash
|
53
57
|
end
|
54
58
|
alias config_check config_status
|
@@ -57,6 +61,7 @@ module Octokit
|
|
57
61
|
#
|
58
62
|
# @return [Sawyer::Resource] The settings
|
59
63
|
def settings
|
64
|
+
octokit_warn('The Management Console API will be deprecated in GitHub Enterprise Server 3.15.0, please use the ManageGHES client instead.')
|
60
65
|
get '/setup/api/settings', password_hash
|
61
66
|
end
|
62
67
|
alias get_settings settings
|
@@ -67,6 +72,7 @@ module Octokit
|
|
67
72
|
#
|
68
73
|
# @return [nil]
|
69
74
|
def edit_settings(settings)
|
75
|
+
octokit_warn('The Management Console API will be deprecated in GitHub Enterprise Server 3.15.0, please use the ManageGHES client instead.')
|
70
76
|
queries = password_hash
|
71
77
|
queries[:query][:settings] = settings.to_json.to_s
|
72
78
|
put '/setup/api/settings', queries
|
@@ -76,6 +82,7 @@ module Octokit
|
|
76
82
|
#
|
77
83
|
# @return [Sawyer::Resource] The maintenance status
|
78
84
|
def maintenance_status
|
85
|
+
octokit_warn('The Management Console API will be deprecated in GitHub Enterprise Server 3.15.0, please use the ManageGHES client instead.')
|
79
86
|
get '/setup/api/maintenance', password_hash
|
80
87
|
end
|
81
88
|
alias get_maintenance_status maintenance_status
|
@@ -85,6 +92,7 @@ module Octokit
|
|
85
92
|
# @param maintenance [Hash] A hash configuration of the maintenance settings
|
86
93
|
# @return [nil]
|
87
94
|
def set_maintenance_status(maintenance)
|
95
|
+
octokit_warn('The Management Console API will be deprecated in GitHub Enterprise Server 3.15.0, please use the ManageGHES client instead.')
|
88
96
|
queries = password_hash
|
89
97
|
queries[:query][:maintenance] = maintenance.to_json.to_s
|
90
98
|
post '/setup/api/maintenance', queries
|
@@ -95,6 +103,7 @@ module Octokit
|
|
95
103
|
#
|
96
104
|
# @return [Sawyer::Resource] An array of authorized SSH keys
|
97
105
|
def authorized_keys
|
106
|
+
octokit_warn('The Management Console API will be deprecated in GitHub Enterprise Server 3.15.0, please use the ManageGHES client instead.')
|
98
107
|
get '/setup/api/settings/authorized-keys', password_hash
|
99
108
|
end
|
100
109
|
alias get_authorized_keys authorized_keys
|
@@ -104,6 +113,7 @@ module Octokit
|
|
104
113
|
# @param key Either the file path to a key, a File handler to the key, or the contents of the key itself
|
105
114
|
# @return [Sawyer::Resource] An array of authorized SSH keys
|
106
115
|
def add_authorized_key(key)
|
116
|
+
octokit_warn('The Management Console API will be deprecated in GitHub Enterprise Server 3.15.0, please use the ManageGHES client instead.')
|
107
117
|
queries = password_hash
|
108
118
|
case key
|
109
119
|
when String
|
@@ -128,6 +138,7 @@ module Octokit
|
|
128
138
|
# @param key Either the file path to a key, a File handler to the key, or the contents of the key itself
|
129
139
|
# @return [Sawyer::Resource] An array of authorized SSH keys
|
130
140
|
def remove_authorized_key(key)
|
141
|
+
octokit_warn('The Management Console API will be deprecated in GitHub Enterprise Server 3.15.0, please use the ManageGHES client instead.')
|
131
142
|
queries = password_hash
|
132
143
|
case key
|
133
144
|
when String
|
@@ -160,7 +171,14 @@ module Octokit
|
|
160
171
|
def faraday_configuration
|
161
172
|
@faraday_configuration ||= Faraday.new(url: @management_console_endpoint) do |http|
|
162
173
|
http.headers[:user_agent] = user_agent
|
163
|
-
|
174
|
+
begin
|
175
|
+
http.request :multipart
|
176
|
+
rescue Faraday::Error
|
177
|
+
raise Faraday::Error, <<~ERROR
|
178
|
+
The `faraday-multipart` gem is required to upload a license.
|
179
|
+
Please add `gem "faraday-multipart"` to your Gemfile.
|
180
|
+
ERROR
|
181
|
+
end
|
164
182
|
http.request :url_encoded
|
165
183
|
|
166
184
|
# Disabling SSL is essential for certain self-hosted Enterprise instances
|
data/lib/octokit/error.rb
CHANGED
@@ -10,6 +10,7 @@ module Octokit
|
|
10
10
|
#
|
11
11
|
# @param [Hash] response HTTP response
|
12
12
|
# @return [Octokit::Error]
|
13
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
13
14
|
def self.from_response(response)
|
14
15
|
status = response[:status].to_i
|
15
16
|
body = response[:body].to_s
|
@@ -23,6 +24,7 @@ module Octokit
|
|
23
24
|
when 405 then Octokit::MethodNotAllowed
|
24
25
|
when 406 then Octokit::NotAcceptable
|
25
26
|
when 409 then Octokit::Conflict
|
27
|
+
when 410 then Octokit::Deprecated
|
26
28
|
when 415 then Octokit::UnsupportedMediaType
|
27
29
|
when 422 then error_for_422(body)
|
28
30
|
when 451 then Octokit::UnavailableForLegalReasons
|
@@ -36,6 +38,7 @@ module Octokit
|
|
36
38
|
klass.new(response)
|
37
39
|
end
|
38
40
|
end
|
41
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
39
42
|
|
40
43
|
def build_error_context
|
41
44
|
if RATE_LIMITED_ERRORS.include?(self.class)
|
@@ -317,6 +320,9 @@ module Octokit
|
|
317
320
|
# Raised when GitHub returns a 409 HTTP status code
|
318
321
|
class Conflict < ClientError; end
|
319
322
|
|
323
|
+
# Raised when GHES Manage return a 410 HTTP status code
|
324
|
+
class Deprecated < ClientError; end
|
325
|
+
|
320
326
|
# Raised when GitHub returns a 414 HTTP status code
|
321
327
|
class UnsupportedMediaType < ClientError; end
|
322
328
|
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Octokit
|
4
|
+
# Client for the Manage GitHub Enterprise Server API
|
5
|
+
class ManageGHESClient
|
6
|
+
# Methods for the Manage GitHub Enterprise Server API
|
7
|
+
#
|
8
|
+
# @see https://developer.github.com/v3/enterprise-admin/manage-ghes
|
9
|
+
module ManageAPI
|
10
|
+
# Get information about the maintenance status of the GHES instance
|
11
|
+
#
|
12
|
+
# @return [nil]
|
13
|
+
def maintenance_mode
|
14
|
+
conn = authenticated_client
|
15
|
+
|
16
|
+
@last_response = conn.get('/manage/v1/maintenance')
|
17
|
+
end
|
18
|
+
|
19
|
+
# Configure the maintenance mode of the GHES instance
|
20
|
+
#
|
21
|
+
# @param maintenance [Hash] A hash configuration of the maintenance mode status
|
22
|
+
# @return [nil]
|
23
|
+
def set_maintenance_mode(enabled, options = {})
|
24
|
+
conn = authenticated_client
|
25
|
+
|
26
|
+
options[:enabled] = enabled
|
27
|
+
@last_response = conn.post('/manage/v1/maintenance', options)
|
28
|
+
end
|
29
|
+
alias configure_maintenance_mode set_maintenance_mode
|
30
|
+
end
|
31
|
+
|
32
|
+
# Uploads a license for the first time
|
33
|
+
#
|
34
|
+
# @param license [String] The path to your .ghl license file.
|
35
|
+
#
|
36
|
+
# @return [nil]
|
37
|
+
def upload_license(license)
|
38
|
+
conn = authenticated_client
|
39
|
+
begin
|
40
|
+
conn.request :multipart
|
41
|
+
rescue Faraday::Error
|
42
|
+
raise Faraday::Error, <<~ERROR
|
43
|
+
The `faraday-multipart` gem is required to upload a license.
|
44
|
+
Please add `gem "faraday-multipart"` to your Gemfile.
|
45
|
+
ERROR
|
46
|
+
end
|
47
|
+
params = {}
|
48
|
+
params[:license] = Faraday::FilePart.new(license, 'binary')
|
49
|
+
params[:password] = @manage_ghes_password
|
50
|
+
@last_response = conn.post('/manage/v1/config/init', params, { 'Content-Type' => 'multipart/form-data' })
|
51
|
+
end
|
52
|
+
|
53
|
+
# Start a configuration process.
|
54
|
+
#
|
55
|
+
# @return [nil]
|
56
|
+
def start_configuration
|
57
|
+
conn = authenticated_client
|
58
|
+
@last_response = conn.post('/manage/v1/config/apply')
|
59
|
+
end
|
60
|
+
|
61
|
+
# Get information about the Enterprise installation
|
62
|
+
#
|
63
|
+
# @return [nil]
|
64
|
+
def config_status
|
65
|
+
conn = authenticated_client
|
66
|
+
@last_response = conn.get('/manage/v1/config/apply')
|
67
|
+
end
|
68
|
+
alias config_check config_status
|
69
|
+
|
70
|
+
# Get information about the Enterprise installation
|
71
|
+
#
|
72
|
+
# @return [nil]
|
73
|
+
def settings
|
74
|
+
conn = authenticated_client
|
75
|
+
@last_response = conn.get('/manage/v1/config/settings')
|
76
|
+
end
|
77
|
+
alias get_settings settings
|
78
|
+
|
79
|
+
# Modify the Enterprise settings
|
80
|
+
#
|
81
|
+
# @param settings [Hash] A hash configuration of the new settings
|
82
|
+
#
|
83
|
+
# @return [nil]
|
84
|
+
def edit_settings(settings)
|
85
|
+
conn = authenticated_client
|
86
|
+
@last_response = conn.put('/manage/v1/config/settings', settings.to_json.to_s)
|
87
|
+
end
|
88
|
+
|
89
|
+
def authorized_keys
|
90
|
+
conn = authenticated_client
|
91
|
+
@last_response = conn.get('/manage/v1/access/ssh')
|
92
|
+
end
|
93
|
+
alias get_authorized_keys authorized_keys
|
94
|
+
|
95
|
+
# Add an authorized SSH keys on the Enterprise install
|
96
|
+
#
|
97
|
+
# @param key Either the file path to a key, a File handler to the key, or the contents of the key itself
|
98
|
+
# @return [nil]
|
99
|
+
def add_authorized_key(key)
|
100
|
+
conn = authenticated_client
|
101
|
+
case key
|
102
|
+
when String
|
103
|
+
if File.exist?(key)
|
104
|
+
key = File.open(key, 'r')
|
105
|
+
content = key.read.strip
|
106
|
+
key.close
|
107
|
+
else
|
108
|
+
content = key
|
109
|
+
end
|
110
|
+
when File
|
111
|
+
content = key.read.strip
|
112
|
+
key.close
|
113
|
+
end
|
114
|
+
|
115
|
+
queries = {}
|
116
|
+
queries[:key] = content
|
117
|
+
@last_response = conn.post('/manage/v1/access/ssh', queries)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Removes an authorized SSH keys from the Enterprise install
|
121
|
+
#
|
122
|
+
# @param key Either the file path to a key, a File handler to the key, or the contents of the key itself
|
123
|
+
# @return [nil]
|
124
|
+
def remove_authorized_key(key)
|
125
|
+
conn = authenticated_client
|
126
|
+
case key
|
127
|
+
when String
|
128
|
+
if File.exist?(key)
|
129
|
+
key = File.open(key, 'r')
|
130
|
+
content = key.read.strip
|
131
|
+
key.close
|
132
|
+
else
|
133
|
+
content = key
|
134
|
+
end
|
135
|
+
when File
|
136
|
+
content = key.read.strip
|
137
|
+
key.close
|
138
|
+
end
|
139
|
+
|
140
|
+
queries = {}
|
141
|
+
queries[:key] = content
|
142
|
+
@last_response = conn.run_request(:delete, '/manage/v1/access/ssh', queries, nil)
|
143
|
+
end
|
144
|
+
alias delete_authorized_key remove_authorized_key
|
145
|
+
|
146
|
+
private
|
147
|
+
|
148
|
+
def basic_authenticated?
|
149
|
+
!!(@manage_ghes_username && @manage_ghes_password)
|
150
|
+
end
|
151
|
+
|
152
|
+
# If no username is provided, we assume root site admin should be used
|
153
|
+
def root_site_admin_assumed?
|
154
|
+
!@manage_ghes_username
|
155
|
+
end
|
156
|
+
|
157
|
+
def authenticated_client
|
158
|
+
@authenticated_client ||= Faraday.new(url: @manage_ghes_endpoint) do |c|
|
159
|
+
c.headers[:user_agent] = user_agent
|
160
|
+
c.request :json
|
161
|
+
c.response :json
|
162
|
+
c.adapter Faraday.default_adapter
|
163
|
+
|
164
|
+
if root_site_admin_assumed?
|
165
|
+
username = 'api_key'
|
166
|
+
elsif basic_authenticated?
|
167
|
+
username = @manage_ghes_username
|
168
|
+
end
|
169
|
+
c.request(*FARADAY_BASIC_AUTH_KEYS, username, @manage_ghes_password)
|
170
|
+
|
171
|
+
# Disabling SSL is essential for certain self-hosted Enterprise instances
|
172
|
+
c.ssl[:verify] = false if connection_options[:ssl] && !connection_options[:ssl][:verify]
|
173
|
+
|
174
|
+
c.use Octokit::Response::RaiseError
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'octokit/configurable'
|
4
|
+
require 'octokit/connection'
|
5
|
+
require 'octokit/warnable'
|
6
|
+
require 'octokit/manage_ghes_client/manage_ghes'
|
7
|
+
|
8
|
+
module Octokit
|
9
|
+
# ManageGHESClient is only meant to be used by GitHub Enterprise Server (GHES) operators
|
10
|
+
# and provides access to the Manage GHES API endpoints.
|
11
|
+
#
|
12
|
+
# @see Octokit::Client Use Octokit::Client for regular API use for GitHub
|
13
|
+
# and GitHub Enterprise.
|
14
|
+
# @see https://developer.github.com/v3/enterprise-admin/manage-ghes/
|
15
|
+
class ManageGHESClient
|
16
|
+
include Octokit::Configurable
|
17
|
+
include Octokit::Connection
|
18
|
+
include Octokit::Warnable
|
19
|
+
include Octokit::ManageGHESClient::ManageAPI
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
# Use options passed in, but fall back to module defaults
|
23
|
+
# rubocop:disable Style/HashEachMethods
|
24
|
+
#
|
25
|
+
# This may look like a `.keys.each` which should be replaced with `#each_key`, but
|
26
|
+
# this doesn't actually work, since `#keys` is just a method we've defined ourselves.
|
27
|
+
# The class doesn't fulfill the whole `Enumerable` contract.
|
28
|
+
Octokit::Configurable.keys.each do |key|
|
29
|
+
# rubocop:enable Style/HashEachMethods
|
30
|
+
instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}"))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def endpoint
|
37
|
+
manage_ghes_endpoint
|
38
|
+
end
|
39
|
+
|
40
|
+
# Set Manage GHES API endpoint
|
41
|
+
#
|
42
|
+
# @param value [String] Manage GHES API endpoint
|
43
|
+
def manage_ghes_endpoint=(value)
|
44
|
+
reset_agent
|
45
|
+
@manage_ghes_endpoint = value
|
46
|
+
end
|
47
|
+
|
48
|
+
# Set Manage GHES API username
|
49
|
+
#
|
50
|
+
# @param value [String] Manage GHES API username
|
51
|
+
def manage_ghes_username=(value)
|
52
|
+
reset_agent
|
53
|
+
@manage_ghes_username = value
|
54
|
+
end
|
55
|
+
|
56
|
+
# Set Manage GHES API password
|
57
|
+
#
|
58
|
+
# @param value [String] Manage GHES API password
|
59
|
+
def manage_ghes_password=(value)
|
60
|
+
reset_agent
|
61
|
+
@manage_ghes_password = value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/octokit/repository.rb
CHANGED
@@ -81,8 +81,14 @@ module Octokit
|
|
81
81
|
|
82
82
|
private
|
83
83
|
|
84
|
+
ABS_URI_REGEXP = if URI.const_defined?(:RFC2396_PARSER) # Ruby 3.4+
|
85
|
+
URI::RFC2396_PARSER.regexp.fetch(:ABS_URI)
|
86
|
+
else
|
87
|
+
URI::RFC2396_Parser.new.regexp.fetch(:ABS_URI)
|
88
|
+
end
|
89
|
+
|
84
90
|
def validate_owner_and_name!(repo)
|
85
|
-
if @owner.include?('/') || @name.include?('/') || !url.match(
|
91
|
+
if @owner.include?('/') || @name.include?('/') || !url.match?(ABS_URI_REGEXP)
|
86
92
|
raise_invalid_repository!(repo)
|
87
93
|
end
|
88
94
|
end
|