octokit 4.25.0 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fb998f706df43131e06c214bd4db92440fe39efa77569b1e883f0a31a8fa8f4
4
- data.tar.gz: 9ae3da4441db278a0a143b6d6cd38734beb6060ecc8339b002c483156da6069a
3
+ metadata.gz: abc3f58113bc1ba895a10399af08ffa4cb77046d7ec70b58772fd562a7136f7c
4
+ data.tar.gz: ccb63539ce291e0146c604643445ca0a4013d6329f6345f3dee4a92d01206970
5
5
  SHA512:
6
- metadata.gz: d01307c7c2a1ab08c1867ffcdbd26633c83844834345637acbde2dc794b02cf219181e3d90031beda91169812483a1637b3c2cf7af5028a01b03ce7b58d95785
7
- data.tar.gz: 30da625ea0b0d89b1cc000ffee759fb3f8a4289940190281899a397c15dce692ebf3dced181b2a9e863ea7a118b7f23fefe491da8f1af0650c3e6d8856edd479
6
+ metadata.gz: ca2ff431a0b98c1e38ec32c6fe46c405d5f741a97b33b3288bf44c1cb6641da1ddbd91988114f2174a0740c75c5ab4a63b2b61111a77dfe06ce77ea2b02280dd
7
+ data.tar.gz: 83638f66161513b9f437906515e3f83bc205b1003d9c7fa11d96579d3bab05b19adfd2969c4b59f44d568b9924c75f16fd5aee91b907d6dc3d655e816a9317b4
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Octokit
2
2
 
3
+ > **Note**
4
+ > We've recently renamed the `4-stable` branch to `main`. This might affect you if you're making changes to Octokit's code locally. For more details and for the steps to reconfigure your local clone for the new branch name, check out [this post](https://github.com/octokit/octokit.rb/discussions/1455).
5
+
3
6
  Ruby toolkit for the GitHub API.
4
7
 
5
8
  ![logo](https://docs.github.com/assets/images/gundamcat.png)
@@ -740,8 +743,6 @@ when writing new specs.
740
743
  This library aims to support and is [tested against][actions] the following Ruby
741
744
  implementations:
742
745
 
743
- * Ruby 2.5
744
- * Ruby 2.6
745
746
  * Ruby 2.7
746
747
  * Ruby 3.0
747
748
  * Ruby 3.1
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Methods for the Actions Workflows jobs API
6
+ #
7
+ # @see https://docs.github.com/rest/actions/workflow-jobs
8
+ module ActionsWorkflowJobs
9
+ # Get a job for a workflow run
10
+ #
11
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
12
+ # @param job_id [Integer, String] Id of the job
13
+ #
14
+ # @return [Sawyer::Resource] Job information
15
+ # @see https://docs.github.com/rest/actions/workflow-jobs#get-a-job-for-a-workflow-run
16
+ def workflow_run_job(repo, job_id, options = {})
17
+ get "#{Repository.path repo}/actions/jobs/#{job_id}", options
18
+ end
19
+
20
+ # Download job logs for a workflow run
21
+ #
22
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
23
+ # @param job_id [Integer, String] Id of the job
24
+ #
25
+ # @return [String] URL to the archived log files of the job
26
+ # @see https://docs.github.com/rest/actions/workflow-jobs#download-job-logs-for-a-workflow-run
27
+ def workflow_run_job_logs(repo, job_id, options = {})
28
+ url = "#{Repository.path repo}/actions/jobs/#{job_id}/logs"
29
+
30
+ response = client_without_redirects.head(url, options)
31
+ response.headers['Location']
32
+ end
33
+
34
+ # List jobs for a workflow run attempt
35
+ #
36
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
37
+ # @param run_id [Integer, String] Id of the workflow run
38
+ # @param attempt_number [Integer, String] Attempt number of the workflow run
39
+ #
40
+ # @return [Sawyer::Resource] Jobs information
41
+ # @see https://docs.github.com/rest/actions/workflow-jobs#list-jobs-for-a-workflow-run-attempt
42
+ def workflow_run_attempt_jobs(repo, run_id, attempt_number, options = {})
43
+ paginate "#{Repository.path repo}/actions/runs/#{run_id}/attempts/#{attempt_number}/jobs", options
44
+ end
45
+ alias list_workflow_run_attempt_jobs workflow_run_attempt_jobs
46
+
47
+ # List jobs for a workflow run
48
+ #
49
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
50
+ # @param run_id [Integer, String] Id of the workflow run
51
+ # @option options [String] :filter Optional filtering by a `completed_at` timestamp
52
+ #
53
+ # @return [Sawyer::Resource] Jobs information
54
+ # @see https://docs.github.com/rest/actions/workflow-jobs#list-jobs-for-a-workflow-run
55
+ def workflow_run_jobs(repo, run_id, options = {})
56
+ paginate "#{Repository.path repo}/actions/runs/#{run_id}/jobs", options
57
+ end
58
+ alias list_workflow_run_jobs workflow_run_jobs
59
+ end
60
+ end
61
+ end
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Octokit
4
4
  class Client
5
+ # Methods for the Actions Workflows runs API
6
+ #
7
+ # @see https://docs.github.com/rest/actions/workflow-runs
5
8
  module ActionsWorkflowRuns
6
9
  # List all runs for a repository workflow
7
10
  #
@@ -92,7 +95,7 @@ module Octokit
92
95
  response.headers['Location']
93
96
  end
94
97
 
95
- # Delets all log files of a workflow run
98
+ # Delete all log files of a workflow run
96
99
  #
97
100
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
98
101
  # @param id [Integer] Id of a workflow run
@@ -102,6 +105,17 @@ module Octokit
102
105
  def delete_workflow_run_logs(repo, id, options = {})
103
106
  boolean_from_response :delete, "#{Repository.path repo}/actions/runs/#{id}/logs", options
104
107
  end
108
+
109
+ # Get workflow run usage
110
+ #
111
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
112
+ # @param id [Integer] Id of a workflow run
113
+ #
114
+ # @return [Sawyer::Resource] Run usage
115
+ # @see https://developer.github.com/v3/actions/workflow-runs/#get-workflow-run-usage
116
+ def workflow_run_usage(repo, id, options = {})
117
+ get "#{Repository.path repo}/actions/runs/#{id}/timing", options
118
+ end
105
119
  end
106
120
  end
107
121
  end
@@ -39,6 +39,28 @@ module Octokit
39
39
  def workflow_dispatch(repo, id, ref, options = {})
40
40
  boolean_from_response :post, "#{Repository.path repo}/actions/workflows/#{id}/dispatches", options.merge({ ref: ref })
41
41
  end
42
+
43
+ # Enable a workflow
44
+ #
45
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
46
+ # @param id [Integer, String] Id or file name of the workflow
47
+ #
48
+ # @return [Boolean] True if workflow was enabled, false otherwise
49
+ # @see https://docs.github.com/en/rest/actions/workflows#enable-a-workflow
50
+ def workflow_enable(repo, id, options = {})
51
+ boolean_from_response :put, "#{Repository.path repo}/actions/workflows/#{id}/enable", options
52
+ end
53
+
54
+ # Disable a workflow
55
+ #
56
+ # @param repo [Integer, String, Repository, Hash] A GitHub repository
57
+ # @param id [Integer, String] Id or file name of the workflow
58
+ #
59
+ # @return [Boolean] True if workflow was disabled, false otherwise
60
+ # @see https://docs.github.com/en/rest/actions/workflows#disable-a-workflow
61
+ def workflow_disable(repo, id, options = {})
62
+ boolean_from_response :put, "#{Repository.path repo}/actions/workflows/#{id}/disable", options
63
+ end
42
64
  end
43
65
  end
44
66
  end
@@ -29,9 +29,9 @@ module Octokit
29
29
 
30
30
  def find_integration_installations(options = {})
31
31
  octokit_warn(
32
- 'Deprecated: Octokit::Client::Apps#find_integration_installations '\
33
- 'method is deprecated. Please update your call to use '\
34
- 'Octokit::Client::Apps#find_app_installations before the next major '\
32
+ 'Deprecated: Octokit::Client::Apps#find_integration_installations ' \
33
+ 'method is deprecated. Please update your call to use ' \
34
+ 'Octokit::Client::Apps#find_app_installations before the next major ' \
35
35
  'Octokit version update.'
36
36
  )
37
37
  find_app_installations(options)
@@ -76,9 +76,9 @@ module Octokit
76
76
 
77
77
  def create_integration_installation_access_token(installation, options = {})
78
78
  octokit_warn(
79
- 'Deprecated: Octokit::Client::Apps#create_integration_installation_access_token '\
80
- 'method is deprecated. Please update your call to use '\
81
- 'Octokit::Client::Apps#create_app_installation_access_token before the next major '\
79
+ 'Deprecated: Octokit::Client::Apps#create_integration_installation_access_token ' \
80
+ 'method is deprecated. Please update your call to use ' \
81
+ 'Octokit::Client::Apps#create_app_installation_access_token before the next major ' \
82
82
  'Octokit version update.'
83
83
  )
84
84
  create_app_installation_access_token(installation, options)
@@ -136,9 +136,9 @@ module Octokit
136
136
 
137
137
  def list_integration_installation_repositories(options = {})
138
138
  octokit_warn(
139
- 'Deprecated: Octokit::Client::Apps#list_integration_installation_repositories '\
140
- 'method is deprecated. Please update your call to use '\
141
- 'Octokit::Client::Apps#list_app_installation_repositories before the next major '\
139
+ 'Deprecated: Octokit::Client::Apps#list_integration_installation_repositories ' \
140
+ 'method is deprecated. Please update your call to use ' \
141
+ 'Octokit::Client::Apps#list_app_installation_repositories before the next major ' \
142
142
  'Octokit version update.'
143
143
  )
144
144
  list_app_installation_repositories(options)
@@ -160,9 +160,9 @@ module Octokit
160
160
 
161
161
  def add_repository_to_integration_installation(installation, repo, options = {})
162
162
  octokit_warn(
163
- 'Deprecated: Octokit::Client::Apps#add_repository_to_integration_installation '\
164
- 'method is deprecated. Please update your call to use '\
165
- 'Octokit::Client::Apps#add_repository_to_app_installation before the next major '\
163
+ 'Deprecated: Octokit::Client::Apps#add_repository_to_integration_installation ' \
164
+ 'method is deprecated. Please update your call to use ' \
165
+ 'Octokit::Client::Apps#add_repository_to_app_installation before the next major ' \
166
166
  'Octokit version update.'
167
167
  )
168
168
  add_repository_to_app_installation(installation, repo, options)
@@ -184,9 +184,9 @@ module Octokit
184
184
 
185
185
  def remove_repository_from_integration_installation(installation, repo, options = {})
186
186
  octokit_warn(
187
- 'Deprecated: Octokit::Client::Apps#remove_repository_from_integration_installation '\
188
- 'method is deprecated. Please update your call to use '\
189
- 'Octokit::Client::Apps#remove_repository_from_app_installation before the next major '\
187
+ 'Deprecated: Octokit::Client::Apps#remove_repository_from_integration_installation ' \
188
+ 'method is deprecated. Please update your call to use ' \
189
+ 'Octokit::Client::Apps#remove_repository_from_app_installation before the next major ' \
190
190
  'Octokit version update.'
191
191
  )
192
192
  remove_repository_from_app_installation(installation, repo, options)
@@ -18,11 +18,11 @@ module Octokit
18
18
  # client.subscribe("https://github.com/joshk/devise_imapable/events/push", "github://Email?address=josh.kalderimis@gmail.com")
19
19
  def subscribe(topic, callback, secret = nil)
20
20
  options = {
21
- "hub.callback": callback,
22
- "hub.mode": 'subscribe',
23
- "hub.topic": topic
21
+ 'hub.callback': callback,
22
+ 'hub.mode': 'subscribe',
23
+ 'hub.topic': topic
24
24
  }
25
- options.merge!("hub.secret": secret) unless secret.nil?
25
+ options.merge!('hub.secret': secret) unless secret.nil?
26
26
 
27
27
  response = pub_sub_hubbub_request(options)
28
28
 
@@ -40,9 +40,9 @@ module Octokit
40
40
  # client.unsubscribe("https://github.com/joshk/devise_imapable/events/push", "github://Email?address=josh.kalderimis@gmail.com")
41
41
  def unsubscribe(topic, callback)
42
42
  options = {
43
- "hub.callback": callback,
44
- "hub.mode": 'unsubscribe',
45
- "hub.topic": topic
43
+ 'hub.callback': callback,
44
+ 'hub.mode': 'unsubscribe',
45
+ 'hub.topic': topic
46
46
  }
47
47
  response = pub_sub_hubbub_request(options)
48
48
 
@@ -91,7 +91,7 @@ module Octokit
91
91
  conn = Faraday.new(url: @api_endpoint) do |http|
92
92
  http.headers[:user_agent] = user_agent
93
93
  if basic_authenticated?
94
- http.request *FARADAY_BASIC_AUTH_KEYS, @login, @password
94
+ http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
95
95
  elsif token_authenticated?
96
96
  http.request :authorization, 'token', @access_token
97
97
  end
@@ -13,9 +13,7 @@ module Octokit
13
13
  # @return [Boolean]
14
14
  def repository?(repo, options = {})
15
15
  !!repository(repo, options)
16
- rescue Octokit::InvalidRepository
17
- false
18
- rescue Octokit::NotFound
16
+ rescue Octokit::InvalidRepository, Octokit::NotFound
19
17
  false
20
18
  end
21
19
 
@@ -161,7 +161,7 @@ module Octokit
161
161
  # TODO(5.0): remove deprecated behavior
162
162
  if reviewers.is_a?(Array)
163
163
  octokit_warn(
164
- 'Deprecated: Octokit::Client#request_pull_request_review '\
164
+ 'Deprecated: Octokit::Client#request_pull_request_review ' \
165
165
  "no longer takes a separate :reviewers argument.\n" \
166
166
  'Please update your call to pass :reviewers and :team_reviewers as part of the options hash.'
167
167
  )
@@ -194,7 +194,7 @@ module Octokit
194
194
  # TODO(5.0): remove deprecated behavior
195
195
  if !reviewers.empty? && !options.empty?
196
196
  octokit_warn(
197
- 'Deprecated: Octokit::Client#delete_pull_request_review_request '\
197
+ 'Deprecated: Octokit::Client#delete_pull_request_review_request ' \
198
198
  "no longer takes a separate :reviewers argument.\n" \
199
199
  'Please update your call to pass :reviewers and :team_reviewers as part of the options hash.'
200
200
  )
@@ -64,6 +64,20 @@ module Octokit
64
64
  end
65
65
  alias search_repos search_repositories
66
66
 
67
+ # Search topics
68
+ #
69
+ # @param query [String] Search term and qualifiers
70
+ # @param options [Hash] Sort and pagination options
71
+ # @option options [String] :sort Sort field
72
+ # @option options [String] :order Sort order (asc or desc)
73
+ # @option options [Integer] :page Page of paginated results
74
+ # @option options [Integer] :per_page Number of items per page
75
+ # @return [Sawyer::Resource] Search results object
76
+ # @see https://developer.github.com/v3/search/#search-topics
77
+ def search_topics(query, options = {})
78
+ search 'search/topics', query, options
79
+ end
80
+
67
81
  # Search users
68
82
  #
69
83
  # @param query [String] Search term and qualifiers
@@ -14,6 +14,7 @@ require 'octokit/organization'
14
14
  require 'octokit/preview'
15
15
  require 'octokit/client/actions_secrets'
16
16
  require 'octokit/client/actions_workflows'
17
+ require 'octokit/client/actions_workflow_jobs'
17
18
  require 'octokit/client/actions_workflow_runs'
18
19
  require 'octokit/client/apps'
19
20
  require 'octokit/client/authorizations'
@@ -93,6 +94,7 @@ module Octokit
93
94
  include Octokit::Client::Gitignore
94
95
  include Octokit::Client::Hooks
95
96
  include Octokit::Client::ActionsWorkflows
97
+ include Octokit::Client::ActionsWorkflowJobs
96
98
  include Octokit::Client::ActionsWorkflowRuns
97
99
  include Octokit::Client::Apps
98
100
  include Octokit::Client::Issues
@@ -252,7 +254,7 @@ module Octokit
252
254
  conn_opts[:ssl] = { verify_mode: @ssl_verify_mode } if @ssl_verify_mode
253
255
  conn = Faraday.new(conn_opts) do |http|
254
256
  if basic_authenticated?
255
- http.request *FARADAY_BASIC_AUTH_KEYS, @login, @password
257
+ http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
256
258
  elsif token_authenticated?
257
259
  http.request :authorization, 'token', @access_token
258
260
  elsif bearer_authenticated?
@@ -134,9 +134,7 @@ module Octokit
134
134
  end
135
135
 
136
136
  def login
137
- @login ||= begin
138
- user.login if token_authenticated?
139
- end
137
+ @login ||= (user.login if token_authenticated?)
140
138
  end
141
139
 
142
140
  def netrc?
@@ -146,7 +144,7 @@ module Octokit
146
144
  private
147
145
 
148
146
  def options
149
- Hash[Octokit::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }]
147
+ Octokit::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }.to_h
150
148
  end
151
149
 
152
150
  def fetch_client_id_and_secret(overrides = {})
@@ -107,13 +107,13 @@ module Octokit
107
107
  http.headers[:content_type] = 'application/json'
108
108
  http.headers[:user_agent] = user_agent
109
109
  if basic_authenticated?
110
- http.request *FARADAY_BASIC_AUTH_KEYS, @login, @password
110
+ http.request(*FARADAY_BASIC_AUTH_KEYS, @login, @password)
111
111
  elsif token_authenticated?
112
112
  http.request :authorization, 'token', @access_token
113
113
  elsif bearer_authenticated?
114
114
  http.request :authorization, 'Bearer', @bearer_token
115
115
  elsif application_authenticated?
116
- http.request *FARADAY_BASIC_AUTH_KEYS, @client_id, @client_secret
116
+ http.request(*FARADAY_BASIC_AUTH_KEYS, @client_id, @client_secret)
117
117
  end
118
118
  end
119
119
  end
@@ -201,7 +201,7 @@ module Octokit
201
201
  end
202
202
  query = options.delete(:query)
203
203
  opts = { query: options }
204
- opts[:query].merge!(query) if query&.is_a?(Hash)
204
+ opts[:query].merge!(query) if query.is_a?(Hash)
205
205
  opts[:headers] = headers unless headers.empty?
206
206
 
207
207
  opts
@@ -35,8 +35,7 @@ module Octokit
35
35
  # so we use it only when it's available.
36
36
  if defined?(Faraday::Request::Retry)
37
37
  builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError]
38
- end
39
- if defined?(Faraday::Retry::Middleware)
38
+ elsif defined?(Faraday::Retry::Middleware)
40
39
  builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError]
41
40
  end
42
41
 
@@ -50,55 +49,55 @@ module Octokit
50
49
  # Configuration options
51
50
  # @return [Hash]
52
51
  def options
53
- Hash[Octokit::Configurable.keys.map { |key| [key, send(key)] }]
52
+ Octokit::Configurable.keys.map { |key| [key, send(key)] }.to_h
54
53
  end
55
54
 
56
55
  # Default access token from ENV
57
56
  # @return [String]
58
57
  def access_token
59
- ENV['OCTOKIT_ACCESS_TOKEN']
58
+ ENV.fetch('OCTOKIT_ACCESS_TOKEN', nil)
60
59
  end
61
60
 
62
61
  # Default API endpoint from ENV or {API_ENDPOINT}
63
62
  # @return [String]
64
63
  def api_endpoint
65
- ENV['OCTOKIT_API_ENDPOINT'] || API_ENDPOINT
64
+ ENV.fetch('OCTOKIT_API_ENDPOINT') { API_ENDPOINT }
66
65
  end
67
66
 
68
67
  # Default pagination preference from ENV
69
68
  # @return [String]
70
69
  def auto_paginate
71
- ENV['OCTOKIT_AUTO_PAGINATE']
70
+ ENV.fetch('OCTOKIT_AUTO_PAGINATE', nil)
72
71
  end
73
72
 
74
73
  # Default bearer token from ENV
75
74
  # @return [String]
76
75
  def bearer_token
77
- ENV['OCTOKIT_BEARER_TOKEN']
76
+ ENV.fetch('OCTOKIT_BEARER_TOKEN', nil)
78
77
  end
79
78
 
80
79
  # Default OAuth app key from ENV
81
80
  # @return [String]
82
81
  def client_id
83
- ENV['OCTOKIT_CLIENT_ID']
82
+ ENV.fetch('OCTOKIT_CLIENT_ID', nil)
84
83
  end
85
84
 
86
85
  # Default OAuth app secret from ENV
87
86
  # @return [String]
88
87
  def client_secret
89
- ENV['OCTOKIT_SECRET']
88
+ ENV.fetch('OCTOKIT_SECRET', nil)
90
89
  end
91
90
 
92
91
  # Default management console password from ENV
93
92
  # @return [String]
94
93
  def management_console_password
95
- ENV['OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD']
94
+ ENV.fetch('OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD', nil)
96
95
  end
97
96
 
98
97
  # Default management console endpoint from ENV
99
98
  # @return [String]
100
99
  def management_console_endpoint
101
- ENV['OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT']
100
+ ENV.fetch('OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT', nil)
102
101
  end
103
102
 
104
103
  # Default options for Faraday::Connection
@@ -115,13 +114,13 @@ module Octokit
115
114
  # Default media type from ENV or {MEDIA_TYPE}
116
115
  # @return [String]
117
116
  def default_media_type
118
- ENV['OCTOKIT_DEFAULT_MEDIA_TYPE'] || MEDIA_TYPE
117
+ ENV.fetch('OCTOKIT_DEFAULT_MEDIA_TYPE') { MEDIA_TYPE }
119
118
  end
120
119
 
121
120
  # Default GitHub username for Basic Auth from ENV
122
121
  # @return [String]
123
122
  def login
124
- ENV['OCTOKIT_LOGIN']
123
+ ENV.fetch('OCTOKIT_LOGIN', nil)
125
124
  end
126
125
 
127
126
  # Default middleware stack for Faraday::Connection
@@ -134,13 +133,13 @@ module Octokit
134
133
  # Default GitHub password for Basic Auth from ENV
135
134
  # @return [String]
136
135
  def password
137
- ENV['OCTOKIT_PASSWORD']
136
+ ENV.fetch('OCTOKIT_PASSWORD', nil)
138
137
  end
139
138
 
140
139
  # Default pagination page size from ENV
141
140
  # @return [Integer] Page size
142
141
  def per_page
143
- page_size = ENV['OCTOKIT_PER_PAGE']
142
+ page_size = ENV.fetch('OCTOKIT_PER_PAGE', nil)
144
143
 
145
144
  page_size&.to_i
146
145
  end
@@ -148,7 +147,7 @@ module Octokit
148
147
  # Default proxy server URI for Faraday connection from ENV
149
148
  # @return [String]
150
149
  def proxy
151
- ENV['OCTOKIT_PROXY']
150
+ ENV.fetch('OCTOKIT_PROXY', nil)
152
151
  end
153
152
 
154
153
  # Default SSL verify mode from ENV
@@ -163,25 +162,25 @@ module Octokit
163
162
  # Default User-Agent header string from ENV or {USER_AGENT}
164
163
  # @return [String]
165
164
  def user_agent
166
- ENV['OCTOKIT_USER_AGENT'] || USER_AGENT
165
+ ENV.fetch('OCTOKIT_USER_AGENT') { USER_AGENT }
167
166
  end
168
167
 
169
168
  # Default web endpoint from ENV or {WEB_ENDPOINT}
170
169
  # @return [String]
171
170
  def web_endpoint
172
- ENV['OCTOKIT_WEB_ENDPOINT'] || WEB_ENDPOINT
171
+ ENV.fetch('OCTOKIT_WEB_ENDPOINT') { WEB_ENDPOINT }
173
172
  end
174
173
 
175
174
  # Default behavior for reading .netrc file
176
175
  # @return [Boolean]
177
176
  def netrc
178
- ENV['OCTOKIT_NETRC'] || false
177
+ ENV.fetch('OCTOKIT_NETRC', false)
179
178
  end
180
179
 
181
180
  # Default path for .netrc file
182
181
  # @return [String]
183
182
  def netrc_file
184
- ENV['OCTOKIT_NETRC_FILE'] || File.join(ENV['HOME'].to_s, '.netrc')
183
+ ENV.fetch('OCTOKIT_NETRC_FILE') { File.join(Dir.home.to_s, '.netrc') }
185
184
  end
186
185
  end
187
186
  end
data/lib/octokit/error.rb CHANGED
@@ -4,6 +4,7 @@ module Octokit
4
4
  # Custom error class for rescuing from all GitHub errors
5
5
  class Error < StandardError
6
6
  attr_reader :context
7
+
7
8
  # Returns the appropriate Octokit::Error subclass based
8
9
  # on status and response message
9
10
  #
@@ -57,7 +58,9 @@ module Octokit
57
58
 
58
59
  # Returns most appropriate error for 401 HTTP status code
59
60
  # @private
61
+ # rubocop:disable Naming/VariableNumber
60
62
  def self.error_for_401(headers)
63
+ # rubocop:enbale Naming/VariableNumber
61
64
  if Octokit::OneTimePasswordRequired.required_header(headers)
62
65
  Octokit::OneTimePasswordRequired
63
66
  else
@@ -68,27 +71,27 @@ module Octokit
68
71
  # Returns most appropriate error for 403 HTTP status code
69
72
  # @private
70
73
  def self.error_for_403(body)
71
- if body =~ /rate limit exceeded/i
72
- Octokit::TooManyRequests
73
- elsif body =~ /exceeded a secondary rate limit/i
74
+ # rubocop:enable Naming/VariableNumber
75
+ case body
76
+ when /rate limit exceeded/i, /exceeded a secondary rate limit/i
74
77
  Octokit::TooManyRequests
75
- elsif body =~ /login attempts exceeded/i
78
+ when /login attempts exceeded/i
76
79
  Octokit::TooManyLoginAttempts
77
- elsif body =~ /returns blobs up to [0-9]+ MB/i
80
+ when /returns blobs up to [0-9]+ MB/i
78
81
  Octokit::TooLargeContent
79
- elsif body =~ /abuse/i
82
+ when /abuse/i
80
83
  Octokit::AbuseDetected
81
- elsif body =~ /repository access blocked/i
84
+ when /repository access blocked/i
82
85
  Octokit::RepositoryUnavailable
83
- elsif body =~ /email address must be verified/i
86
+ when /email address must be verified/i
84
87
  Octokit::UnverifiedEmail
85
- elsif body =~ /account was suspended/i
88
+ when /account was suspended/i
86
89
  Octokit::AccountSuspended
87
- elsif body =~ /billing issue/i
90
+ when /billing issue/i
88
91
  Octokit::BillingIssue
89
- elsif body =~ /Resource protected by organization SAML enforcement/i
92
+ when /Resource protected by organization SAML enforcement/i
90
93
  Octokit::SAMLProtected
91
- elsif body =~ /suspended your access|This installation has been suspended/i
94
+ when /suspended your access|This installation has been suspended/i
92
95
  Octokit::InstallationSuspended
93
96
  else
94
97
  Octokit::Forbidden
@@ -97,7 +100,9 @@ module Octokit
97
100
 
98
101
  # Return most appropriate error for 404 HTTP status code
99
102
  # @private
103
+ # rubocop:disable Naming/VariableNumber
100
104
  def self.error_for_404(body)
105
+ # rubocop:enable Naming/VariableNumber
101
106
  if body =~ /Branch not protected/i
102
107
  Octokit::BranchNotProtected
103
108
  else
@@ -107,7 +112,9 @@ module Octokit
107
112
 
108
113
  # Return most appropriate error for 422 HTTP status code
109
114
  # @private
115
+ # rubocop:disable Naming/VariableNumber
110
116
  def self.error_for_422(body)
117
+ # rubocop:enable Naming/VariableNumber
111
118
  if body =~ /PullRequestReviewComment/i && body =~ /(commit_id|end_commit_oid) is not part of the pull request/i
112
119
  Octokit::CommitIsNotPartOfPullRequest
113
120
  elsif body =~ /Path diff too large/i
@@ -120,7 +127,7 @@ module Octokit
120
127
  # Array of validation errors
121
128
  # @return [Array<Hash>] Error info
122
129
  def errors
123
- if data&.is_a?(Hash)
130
+ if data.is_a?(Hash)
124
131
  data[:errors] || []
125
132
  else
126
133
  []
@@ -196,7 +203,7 @@ module Octokit
196
203
  return nil if @response.nil?
197
204
 
198
205
  message = +"#{@response[:method].to_s.upcase} "
199
- message << redact_url(@response[:url].to_s.dup) + ': '
206
+ message << "#{redact_url(@response[:url].to_s.dup)}: "
200
207
  message << "#{@response[:status]} - "
201
208
  message << response_message.to_s unless response_message.nil?
202
209
  message << response_error.to_s unless response_error.nil?
@@ -127,7 +127,7 @@ module Octokit
127
127
  # risk double-escaping.
128
128
  def safe_escape(uri)
129
129
  uri.to_s.gsub(URI_UNSAFE) do |match|
130
- '%' + match.unpack('H2' * match.bytesize).join('%').upcase
130
+ "%#{match.unpack('H2' * match.bytesize).join('%').upcase}"
131
131
  end
132
132
  end
133
133
  end
@@ -20,7 +20,7 @@ module Octokit
20
20
  # @return [RateLimit]
21
21
  def self.from_response(response)
22
22
  info = new
23
- if response&.respond_to?(:headers) && !response.headers.nil?
23
+ if response.respond_to?(:headers) && !response.headers.nil?
24
24
  info.limit = (response.headers['X-RateLimit-Limit'] || 1).to_i
25
25
  info.remaining = (response.headers['X-RateLimit-Remaining'] || 1).to_i
26
26
  info.resets_at = Time.at((response.headers['X-RateLimit-Reset'] || Time.now).to_i)
@@ -5,6 +5,7 @@ module Octokit
5
5
  # URLs and to generate URLs
6
6
  class Repository
7
7
  attr_accessor :owner, :name, :id
8
+
8
9
  NAME_WITH_OWNER_PATTERN = %r{\A[\w.-]+/[\w.-]+\z}i.freeze
9
10
 
10
11
  # Instantiate from a GitHub repository URL
@@ -3,11 +3,11 @@
3
3
  module Octokit
4
4
  # Current major release.
5
5
  # @return [Integer]
6
- MAJOR = 4
6
+ MAJOR = 5
7
7
 
8
8
  # Current minor release.
9
9
  # @return [Integer]
10
- MINOR = 25
10
+ MINOR = 1
11
11
 
12
12
  # Current patch level.
13
13
  # @return [Integer]
data/octokit.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.licenses = ['MIT']
18
18
  spec.name = 'octokit'
19
19
  spec.require_paths = ['lib']
20
- spec.required_ruby_version = '>= 2.0.0'
20
+ spec.required_ruby_version = '>= 2.7.0'
21
21
  spec.required_rubygems_version = '>= 1.3.5'
22
22
  spec.summary = 'Ruby toolkit for working with the GitHub API'
23
23
  spec.version = Octokit::VERSION.dup
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octokit
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.25.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wynn Netherland
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-06-15 00:00:00.000000000 Z
13
+ date: 2022-07-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -86,6 +86,7 @@ files:
86
86
  - lib/octokit/authentication.rb
87
87
  - lib/octokit/client.rb
88
88
  - lib/octokit/client/actions_secrets.rb
89
+ - lib/octokit/client/actions_workflow_jobs.rb
89
90
  - lib/octokit/client/actions_workflow_runs.rb
90
91
  - lib/octokit/client/actions_workflows.rb
91
92
  - lib/octokit/client/apps.rb
@@ -175,14 +176,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
176
  requirements:
176
177
  - - ">="
177
178
  - !ruby/object:Gem::Version
178
- version: 2.0.0
179
+ version: 2.7.0
179
180
  required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  requirements:
181
182
  - - ">="
182
183
  - !ruby/object:Gem::Version
183
184
  version: 1.3.5
184
185
  requirements: []
185
- rubygems_version: 3.1.2
186
+ rubygems_version: 3.3.7
186
187
  signing_key:
187
188
  specification_version: 4
188
189
  summary: Ruby toolkit for working with the GitHub API