octokit 7.2.0 → 8.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab72372e0317944ac3a6c8b4e166bad268bea9524ef8bde2f5cacb13ee471d28
4
- data.tar.gz: 19be89924891fb2a771d17fb739fad7454bc8cb79c66950d7c64eb426ab2aef5
3
+ metadata.gz: dead7bdb61143c1a0b84afa0b02b567a29e117b0b15e0d0ee10271bb9dc62a17
4
+ data.tar.gz: 648cb60f5d7f8765f925ec2a673dd00331151d3222b392a9814e856e6d303a67
5
5
  SHA512:
6
- metadata.gz: 38724e4929489a803f1aa9e3186633217bd8473585b35a90ee82fd2985abc361b03af97c96e089759e1c1d2388fcb6cc4fba2d496aae0abfcc214265e0a54770
7
- data.tar.gz: b2b589fccec5e74cddc322b850ac9bd04a0dd7300476b6b3758059bcba62b7651a10d634683f0e427ea4c049e78ee52542319206571493ce84241a326af5d6d7
6
+ metadata.gz: 9b5d2d09d0665466a4bdca1d523758ad447db67c911284c2738a311c400267dbbabcf4c92079c83550339b1cd5361abe841a672a89bc77a7345940d3041cee65
7
+ data.tar.gz: ca2ced14c1bb869c41f94806427fbd16917eadd6486c35c58c69c59c44b384c323b282266ae95b84bd6109674051a963d6b2d1fea15609bbc61c033a55b6e90f
data/README.md CHANGED
@@ -213,15 +213,7 @@ user.login
213
213
  # => "defunkt"
214
214
  ```
215
215
 
216
- You can [create access tokens through your GitHub Account Settings](https://help.github.com/articles/creating-an-access-token-for-command-line-use)
217
- or with a basic authenticated Octokit client:
218
-
219
- ```ruby
220
- client = Octokit::Client.new(:login => 'defunkt', :password => 'c0d3b4ssssss!')
221
-
222
- client.create_authorization(:scopes => ["user"], :note => "Name of token")
223
- # => <your new oauth token>
224
- ```
216
+ You can [create access tokens through your GitHub Account Settings](https://help.github.com/articles/creating-an-access-token-for-command-line-use).
225
217
 
226
218
  ### Two-Factor Authentication
227
219
 
@@ -237,18 +229,6 @@ client = Octokit::Client.new \
237
229
  user = client.user("defunkt", :headers => { "X-GitHub-OTP" => "<your 2FA token>" })
238
230
  ```
239
231
 
240
- As you can imagine, this gets annoying quickly since two-factor auth tokens are very short lived. So it is recommended to create an oauth token for the user to communicate with the API:
241
-
242
- ```ruby
243
- client = Octokit::Client.new \
244
- :login => 'defunkt',
245
- :password => 'c0d3b4ssssss!'
246
-
247
- client.create_authorization(:scopes => ["user"], :note => "Name of token",
248
- :headers => { "X-GitHub-OTP" => "<your 2FA token>" })
249
- # => <your new oauth token>
250
- ```
251
-
252
232
  ### Using a .netrc file
253
233
 
254
234
  Octokit supports reading credentials from a netrc file (defaulting to
@@ -15,6 +15,15 @@ module Octokit
15
15
  get "#{Repository.path repo}/actions/secrets/public-key"
16
16
  end
17
17
 
18
+ # Get public key for secrets encryption
19
+ #
20
+ # @param org [String] A GitHub organization
21
+ # @return [Hash] key_id and key
22
+ # @see https://developer.github.com/v3/actions/secrets/#get-your-public-key
23
+ def get_org_actions_public_key(org)
24
+ get "#{Organization.path org}/actions/secrets/public-key"
25
+ end
26
+
18
27
  # List secrets
19
28
  #
20
29
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -26,6 +35,17 @@ module Octokit
26
35
  end
27
36
  end
28
37
 
38
+ # List org secrets
39
+ #
40
+ # @param org [String] A GitHub organization
41
+ # @return [Hash] total_count and list of secrets (each item is hash with name, created_at and updated_at)
42
+ # @see https://developer.github.com/v3/actions/secrets/#list-organization-secrets
43
+ def list_org_actions_secrets(org)
44
+ paginate "#{Organization.path org}/actions/secrets" do |data, last_response|
45
+ data.secrets.concat last_response.data.secrets
46
+ end
47
+ end
48
+
29
49
  # Get a secret
30
50
  #
31
51
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -36,6 +56,16 @@ module Octokit
36
56
  get "#{Repository.path repo}/actions/secrets/#{name}"
37
57
  end
38
58
 
59
+ # Get an org secret
60
+ #
61
+ # @param org [String] A GitHub organization
62
+ # @param name [String] Name of secret
63
+ # @return [Hash] name, created_at and updated_at
64
+ # @see https://developer.github.com/v3/actions/secrets/#get-a-secret
65
+ def get_org_actions_secret(org, name)
66
+ get "#{Organization.path org}/actions/secrets/#{name}"
67
+ end
68
+
39
69
  # Create or update secrets
40
70
  #
41
71
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -46,6 +76,16 @@ module Octokit
46
76
  put "#{Repository.path repo}/actions/secrets/#{name}", options
47
77
  end
48
78
 
79
+ # Create or update org secrets
80
+ #
81
+ # @param org [String] A GitHub organization
82
+ # @param name [String] Name of secret
83
+ # @param options [Hash] encrypted_value and key_id
84
+ # @see https://developer.github.com/v3/actions/secrets/#create-or-update-a-secret
85
+ def create_or_update_org_actions_secret(org, name, options)
86
+ put "#{Organization.path org}/actions/secrets/#{name}", options
87
+ end
88
+
49
89
  # Delete a secret
50
90
  #
51
91
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -55,6 +95,15 @@ module Octokit
55
95
  boolean_from_response :delete, "#{Repository.path repo}/actions/secrets/#{name}"
56
96
  end
57
97
 
98
+ # Delete an org secret
99
+ #
100
+ # @param org [String] A GitHub organization
101
+ # @param name [String] Name of secret
102
+ # @see https://developer.github.com/v3/actions/secrets/#delete-a-secret
103
+ def delete_org_actions_secret(org, name)
104
+ boolean_from_response :delete, "#{Organization.path org}/actions/secrets/#{name}"
105
+ end
106
+
58
107
  # Get environment public key for secrets encryption
59
108
  #
60
109
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -15,6 +15,15 @@ module Octokit
15
15
  get "#{Repository.path repo}/codespaces/secrets/public-key"
16
16
  end
17
17
 
18
+ # Get public key for secrets encryption
19
+ #
20
+ # @param org [String] A GitHub organization
21
+ # @return [Hash] key_id and key
22
+ # @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#get-an-organization-public-key
23
+ def get_org_codespaces_public_key(org)
24
+ get "#{Organization.path org}/codespaces/secrets/public-key"
25
+ end
26
+
18
27
  # List secrets
19
28
  #
20
29
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -26,6 +35,17 @@ module Octokit
26
35
  end
27
36
  end
28
37
 
38
+ # List org secrets
39
+ #
40
+ # @param org [String] A GitHub organization
41
+ # @return [Hash] total_count and list of secrets (each item is hash with name, created_at and updated_at)
42
+ # @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#list-organization-secrets
43
+ def list_org_codespaces_secrets(org)
44
+ paginate "#{Organization.path org}/codespaces/secrets" do |data, last_response|
45
+ data.secrets.concat last_response.data.secrets
46
+ end
47
+ end
48
+
29
49
  # Get a secret
30
50
  #
31
51
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -36,6 +56,16 @@ module Octokit
36
56
  get "#{Repository.path repo}/codespaces/secrets/#{name}"
37
57
  end
38
58
 
59
+ # Get an org secret
60
+ #
61
+ # @param org [String] A GitHub organization
62
+ # @param name [String] Name of secret
63
+ # @return [Hash] name, created_at, updated_at, and visibility
64
+ # @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#get-an-organization-secret
65
+ def get_org_codespaces_secret(org, name)
66
+ get "#{Organization.path org}/codespaces/secrets/#{name}"
67
+ end
68
+
39
69
  # Create or update secrets
40
70
  #
41
71
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -46,6 +76,16 @@ module Octokit
46
76
  put "#{Repository.path repo}/codespaces/secrets/#{name}", options
47
77
  end
48
78
 
79
+ # Create or update org secrets
80
+ #
81
+ # @param org [String] A GitHub organization
82
+ # @param name [String] Name of secret
83
+ # @param options [Hash] encrypted_value and key_id
84
+ # @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret
85
+ def create_or_update_org_codespaces_secret(org, name, options)
86
+ put "#{Organization.path org}/codespaces/secrets/#{name}", options
87
+ end
88
+
49
89
  # Delete a secret
50
90
  #
51
91
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -54,6 +94,15 @@ module Octokit
54
94
  def delete_codespaces_secret(repo, name)
55
95
  boolean_from_response :delete, "#{Repository.path repo}/codespaces/secrets/#{name}"
56
96
  end
97
+
98
+ # Delete an org secret
99
+ #
100
+ # @param org [String] A GitHub organization
101
+ # @param name [String] Name of secret
102
+ # @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#delete-an-organization-secret
103
+ def delete_org_codespaces_secret(org, name)
104
+ boolean_from_response :delete, "#{Organization.path org}/codespaces/secrets/#{name}"
105
+ end
57
106
  end
58
107
  end
59
108
  end
@@ -15,6 +15,15 @@ module Octokit
15
15
  get "#{Repository.path repo}/dependabot/secrets/public-key"
16
16
  end
17
17
 
18
+ # Get public key for secrets encryption
19
+ #
20
+ # @param org [String] A GitHub organization
21
+ # @return [Hash] key_id and key
22
+ # @see https://docs.github.com/en/rest/dependabot/organization-secrets?apiVersion=2022-11-28#get-an-organization-public-key
23
+ def get_org_dependabot_public_key(org)
24
+ get "#{Organization.path org}/dependabot/secrets/public-key"
25
+ end
26
+
18
27
  # List secrets
19
28
  #
20
29
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -26,6 +35,17 @@ module Octokit
26
35
  end
27
36
  end
28
37
 
38
+ # List org secrets
39
+ #
40
+ # @param org [String] A GitHub organization
41
+ # @return [Hash] total_count and list of secrets (each item is hash with name, created_at and updated_at)
42
+ # @see https://docs.github.com/en/rest/dependabot/organization-secrets?apiVersion=2022-11-28#list-organization-secrets
43
+ def list_org_dependabot_secrets(org)
44
+ paginate "#{Organization.path org}/dependabot/secrets" do |data, last_response|
45
+ data.secrets.concat last_response.data.secrets
46
+ end
47
+ end
48
+
29
49
  # Get a secret
30
50
  #
31
51
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -36,6 +56,16 @@ module Octokit
36
56
  get "#{Repository.path repo}/dependabot/secrets/#{name}"
37
57
  end
38
58
 
59
+ # Get an org secret
60
+ #
61
+ # @param org [String] A GitHub organization
62
+ # @param name [String] Name of secret
63
+ # @return [Hash] name, created_at, updated_at, and visibility
64
+ # @see https://docs.github.com/en/rest/dependabot/organization-secrets?apiVersion=2022-11-28#get-an-organization-secret
65
+ def get_org_dependabot_secret(org, name)
66
+ get "#{Organization.path org}/dependabot/secrets/#{name}"
67
+ end
68
+
39
69
  # Create or update secrets
40
70
  #
41
71
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -46,6 +76,16 @@ module Octokit
46
76
  put "#{Repository.path repo}/dependabot/secrets/#{name}", options
47
77
  end
48
78
 
79
+ # Create or update org secrets
80
+ #
81
+ # @param org [String] A GitHub organization
82
+ # @param name [String] Name of secret
83
+ # @param options [Hash] encrypted_value and key_id
84
+ # @see https://docs.github.com/en/rest/dependabot/organization-secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret
85
+ def create_or_update_org_dependabot_secret(org, name, options)
86
+ put "#{Organization.path org}/dependabot/secrets/#{name}", options
87
+ end
88
+
49
89
  # Delete a secret
50
90
  #
51
91
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -54,6 +94,15 @@ module Octokit
54
94
  def delete_dependabot_secret(repo, name)
55
95
  boolean_from_response :delete, "#{Repository.path repo}/dependabot/secrets/#{name}"
56
96
  end
97
+
98
+ # Delete an org secret
99
+ #
100
+ # @param org [String] A GitHub organization
101
+ # @param name [String] Name of secret
102
+ # @see https://docs.github.com/en/rest/dependabot/organization-secrets?apiVersion=2022-11-28#delete-an-organization-secret
103
+ def delete_org_dependabot_secret(org, name)
104
+ boolean_from_response :delete, "#{Organization.path org}/dependabot/secrets/#{name}"
105
+ end
57
106
  end
58
107
  end
59
108
  end
@@ -22,7 +22,7 @@ module Octokit
22
22
  # @return [Array<Sawyer::Resource>] A list of deployments
23
23
  # @see https://developer.github.com/v3/repos/deployments/#list-deployments
24
24
  def deployments(repo, options = {})
25
- get("#{Repository.path repo}/deployments", options)
25
+ paginate("#{Repository.path repo}/deployments", options)
26
26
  end
27
27
  alias list_deployments deployments
28
28
 
@@ -60,7 +60,7 @@ module Octokit
60
60
  # @see https://developer.github.com/v3/repos/deployments/#list-deployment-statuses
61
61
  def deployment_statuses(deployment_url, options = {})
62
62
  deployment = get(deployment_url, accept: options[:accept])
63
- get(deployment.rels[:statuses].href, options)
63
+ paginate(deployment.rels[:statuses].href, options)
64
64
  end
65
65
  alias list_deployment_statuses deployment_statuses
66
66
 
@@ -65,7 +65,7 @@ module Octokit
65
65
  #
66
66
  # @example
67
67
  # client = Octokit::Client.new(:client_id => 'abcdefg12345', :client_secret => 'secret')
68
- # client.delete_token('deadbeef1234567890deadbeef987654321')
68
+ # client.delete_app_token('deadbeef1234567890deadbeef987654321')
69
69
  def delete_app_token(access_token, options = {})
70
70
  options[:access_token] = access_token
71
71
 
@@ -197,20 +197,21 @@ module Octokit
197
197
  # @param body [String] Comment content
198
198
  # @param commit_id [String] Sha of the commit to comment on.
199
199
  # @param path [String] Relative path of the file to comment on.
200
- # @param position [Integer] Line index in the diff to comment on.
200
+ # @param line [Integer] Line index in the diff to comment on.
201
+ # For a multi-line comment, the last line of the range
202
+ # and specify 'start_line' in the 'options'.
201
203
  # @return [Sawyer::Resource] Hash representing the new comment
202
204
  # @deprecated The position will be deprecated in the next major version. Please refer to the details below.
203
205
  # @see https://developer.github.com/v3/pulls/comments/#create-a-comment
204
206
  # @example
205
207
  # @client.create_pull_request_comment("octokit/octokit.rb", 163, ":shipit:",
206
208
  # "2d3201e4440903d8b04a5487842053ca4883e5f0", "lib/octokit/request.rb", 47)
207
- def create_pull_request_comment(repo, pull_id, body, commit_id, path, position, options = {})
208
- octokit_warn 'Deprecated: The position will be deprecated in the next major version.'
209
+ def create_pull_request_comment(repo, pull_id, body, commit_id, path, line, options = {})
209
210
  options.merge!({
210
211
  body: body,
211
212
  commit_id: commit_id,
212
213
  path: path,
213
- position: position
214
+ line: line
214
215
  })
215
216
  post "#{Repository.path repo}/pulls/#{pull_id}/comments", options
216
217
  end
@@ -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
@@ -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
@@ -15,7 +15,7 @@ module Octokit
15
15
  attr_reader :response
16
16
 
17
17
  def initialize(response)
18
- super "too many redirects; last one to: #{response['location']}"
18
+ super("too many redirects; last one to: #{response['location']}")
19
19
  @response = response
20
20
  end
21
21
  end
@@ -3,11 +3,11 @@
3
3
  module Octokit
4
4
  # Current major release.
5
5
  # @return [Integer]
6
- MAJOR = 7
6
+ MAJOR = 8
7
7
 
8
8
  # Current minor release.
9
9
  # @return [Integer]
10
- MINOR = 2
10
+ MINOR = 1
11
11
 
12
12
  # Current patch level.
13
13
  # @return [Integer]
data/octokit.gemspec CHANGED
@@ -5,6 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'octokit/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
+ spec.add_dependency 'base64'
8
9
  spec.add_dependency 'faraday', '>= 1', '< 3'
9
10
  spec.add_dependency 'sawyer', '~> 0.9'
10
11
  spec.authors = ['Wynn Netherland', 'Erik Michaels-Ober', 'Clint Shryock']
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: 7.2.0
4
+ version: 8.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wynn Netherland
@@ -10,8 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-09-29 00:00:00.000000000 Z
13
+ date: 2024-02-01 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: base64
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: faraday
17
31
  requirement: !ruby/object:Gem::Requirement