octokit 4.6.2 → 6.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.md +14 -13
  3. data/LICENSE.md +1 -1
  4. data/README.md +239 -118
  5. data/Rakefile +12 -12
  6. data/lib/ext/sawyer/relation.rb +4 -2
  7. data/lib/octokit/arguments.rb +2 -2
  8. data/lib/octokit/authentication.rb +20 -14
  9. data/lib/octokit/client/actions_artifacts.rb +71 -0
  10. data/lib/octokit/client/actions_secrets.rb +59 -0
  11. data/lib/octokit/client/actions_workflow_jobs.rb +65 -0
  12. data/lib/octokit/client/actions_workflow_runs.rb +125 -0
  13. data/lib/octokit/client/actions_workflows.rb +68 -0
  14. data/lib/octokit/client/apps.rb +222 -0
  15. data/lib/octokit/client/checks.rb +200 -0
  16. data/lib/octokit/client/commit_branches.rb +20 -0
  17. data/lib/octokit/client/commit_comments.rb +8 -8
  18. data/lib/octokit/client/commit_pulls.rb +20 -0
  19. data/lib/octokit/client/commits.rb +31 -34
  20. data/lib/octokit/client/community_profile.rb +21 -0
  21. data/lib/octokit/client/contents.rb +25 -20
  22. data/lib/octokit/client/deployments.rb +25 -5
  23. data/lib/octokit/client/downloads.rb +5 -6
  24. data/lib/octokit/client/emojis.rb +3 -3
  25. data/lib/octokit/client/environments.rb +55 -0
  26. data/lib/octokit/client/events.rb +4 -4
  27. data/lib/octokit/client/feeds.rb +4 -5
  28. data/lib/octokit/client/gists.rb +7 -6
  29. data/lib/octokit/client/gitignore.rb +3 -3
  30. data/lib/octokit/client/hooks.rb +9 -19
  31. data/lib/octokit/client/issues.rb +60 -14
  32. data/lib/octokit/client/labels.rb +17 -17
  33. data/lib/octokit/client/legacy_search.rb +3 -3
  34. data/lib/octokit/client/licenses.rb +4 -7
  35. data/lib/octokit/client/markdown.rb +3 -3
  36. data/lib/octokit/client/marketplace.rb +56 -0
  37. data/lib/octokit/client/meta.rb +4 -5
  38. data/lib/octokit/client/milestones.rb +5 -5
  39. data/lib/octokit/client/notifications.rb +6 -10
  40. data/lib/octokit/client/oauth_applications.rb +116 -0
  41. data/lib/octokit/client/objects.rb +14 -14
  42. data/lib/octokit/client/organizations.rb +238 -61
  43. data/lib/octokit/client/pages.rb +5 -7
  44. data/lib/octokit/client/projects.rb +50 -70
  45. data/lib/octokit/client/pub_sub_hubbub.rb +16 -16
  46. data/lib/octokit/client/pull_requests.rb +58 -46
  47. data/lib/octokit/client/rate_limit.rb +11 -13
  48. data/lib/octokit/client/reactions.rb +6 -11
  49. data/lib/octokit/client/refs.rb +32 -19
  50. data/lib/octokit/client/releases.rb +14 -13
  51. data/lib/octokit/client/repositories.rb +195 -54
  52. data/lib/octokit/client/repository_invitations.rb +4 -11
  53. data/lib/octokit/client/reviews.rb +227 -0
  54. data/lib/octokit/client/say.rb +4 -5
  55. data/lib/octokit/client/search.rb +46 -17
  56. data/lib/octokit/client/service_status.rb +19 -9
  57. data/lib/octokit/client/source_import.rb +8 -13
  58. data/lib/octokit/client/stats.rb +12 -9
  59. data/lib/octokit/client/statuses.rb +6 -6
  60. data/lib/octokit/client/tokens.rb +31 -0
  61. data/lib/octokit/client/traffic.rb +6 -11
  62. data/lib/octokit/client/users.rb +106 -25
  63. data/lib/octokit/client.rb +66 -17
  64. data/lib/octokit/configurable.rb +42 -30
  65. data/lib/octokit/connection.rb +43 -21
  66. data/lib/octokit/default.rb +63 -34
  67. data/lib/octokit/enterprise_admin_client/admin_stats.rb +14 -15
  68. data/lib/octokit/enterprise_admin_client/license.rb +4 -5
  69. data/lib/octokit/enterprise_admin_client/orgs.rb +5 -6
  70. data/lib/octokit/enterprise_admin_client/search_indexing.rb +8 -9
  71. data/lib/octokit/enterprise_admin_client/users.rb +17 -16
  72. data/lib/octokit/enterprise_admin_client.rb +9 -3
  73. data/lib/octokit/enterprise_management_console_client/management_console.rb +33 -33
  74. data/lib/octokit/enterprise_management_console_client.rb +9 -3
  75. data/lib/octokit/error.rb +107 -26
  76. data/lib/octokit/gist.rb +4 -5
  77. data/lib/octokit/middleware/follow_redirects.rb +17 -13
  78. data/lib/octokit/organization.rb +3 -1
  79. data/lib/octokit/rate_limit.rb +11 -9
  80. data/lib/octokit/repo_arguments.rb +2 -3
  81. data/lib/octokit/repository.rb +27 -25
  82. data/lib/octokit/response/base_middleware.rb +10 -0
  83. data/lib/octokit/response/feed_parser.rb +5 -9
  84. data/lib/octokit/response/raise_error.rb +4 -6
  85. data/lib/octokit/user.rb +4 -2
  86. data/lib/octokit/version.rb +5 -3
  87. data/lib/octokit/warnable.rb +4 -5
  88. data/lib/octokit.rb +15 -8
  89. data/octokit.gemspec +13 -10
  90. metadata +55 -22
  91. data/lib/octokit/client/authorizations.rb +0 -244
  92. data/lib/octokit/preview.rb +0 -35
@@ -1,17 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for API rate limiting info
5
6
  #
6
7
  # @see https://developer.github.com/v3/#rate-limiting
7
8
  module RateLimit
8
-
9
9
  # Get rate limit info from last response if available
10
10
  # or make a new request to fetch rate limit
11
11
  #
12
12
  # @see https://developer.github.com/v3/rate_limit/#rate-limit
13
13
  # @return [Octokit::RateLimit] Rate limit info
14
- def rate_limit(options = {})
14
+ def rate_limit(_options = {})
15
15
  return rate_limit! if last_response.nil?
16
16
 
17
17
  Octokit::RateLimit.from_response(last_response)
@@ -21,9 +21,9 @@ module Octokit
21
21
  # Get number of rate limted requests remaining
22
22
  #
23
23
  # @see https://developer.github.com/v3/rate_limit/#rate-limit
24
- # @return [Fixnum] Number of requests remaining in this period
25
- def rate_limit_remaining(options = {})
26
- octokit_warn "Deprecated: Please use .rate_limit.remaining"
24
+ # @return [Integer] Number of requests remaining in this period
25
+ def rate_limit_remaining(_options = {})
26
+ octokit_warn 'Deprecated: Please use .rate_limit.remaining'
27
27
  rate_limit.remaining
28
28
  end
29
29
  alias ratelimit_remaining rate_limit_remaining
@@ -32,8 +32,8 @@ module Octokit
32
32
  #
33
33
  # @see https://developer.github.com/v3/rate_limit/#rate-limit
34
34
  # @return [Octokit::RateLimit] Rate limit info
35
- def rate_limit!(options = {})
36
- get "rate_limit"
35
+ def rate_limit!(_options = {})
36
+ get 'rate_limit'
37
37
  Octokit::RateLimit.from_response(last_response)
38
38
  end
39
39
  alias ratelimit! rate_limit!
@@ -41,14 +41,12 @@ module Octokit
41
41
  # Refresh rate limit info and get number of rate limted requests remaining
42
42
  #
43
43
  # @see https://developer.github.com/v3/rate_limit/#rate-limit
44
- # @return [Fixnum] Number of requests remaining in this period
45
- def rate_limit_remaining!(options = {})
46
- octokit_warn "Deprecated: Please use .rate_limit!.remaining"
44
+ # @return [Integer] Number of requests remaining in this period
45
+ def rate_limit_remaining!(_options = {})
46
+ octokit_warn 'Deprecated: Please use .rate_limit!.remaining'
47
47
  rate_limit!.remaining
48
48
  end
49
49
  alias ratelimit_remaining! rate_limit_remaining!
50
-
51
50
  end
52
51
  end
53
52
  end
54
-
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for the Reacions API
5
6
  #
6
7
  # @see https://developer.github.com/v3/reactions/
7
8
  module Reactions
8
-
9
9
  # List reactions for a commit comment
10
10
  #
11
11
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -17,7 +17,6 @@ module Octokit
17
17
  #
18
18
  # @return [Array<Sawyer::Resource>] Array of Hashes representing the reactions.
19
19
  def commit_comment_reactions(repo, id, options = {})
20
- options = ensure_api_media_type(:reactions, options)
21
20
  get "#{Repository.path repo}/comments/#{id}/reactions", options
22
21
  end
23
22
 
@@ -34,7 +33,7 @@ module Octokit
34
33
  #
35
34
  # @return [<Sawyer::Resource>] Hash representing the reaction
36
35
  def create_commit_comment_reaction(repo, id, reaction, options = {})
37
- options = ensure_api_media_type(:reactions, options.merge(:content => reaction))
36
+ options = options.merge(content: reaction)
38
37
  post "#{Repository.path repo}/comments/#{id}/reactions", options
39
38
  end
40
39
 
@@ -49,7 +48,6 @@ module Octokit
49
48
  #
50
49
  # @return [Array<Sawyer::Resource>] Array of Hashes representing the reactions.
51
50
  def issue_reactions(repo, number, options = {})
52
- options = ensure_api_media_type(:reactions, options)
53
51
  get "#{Repository.path repo}/issues/#{number}/reactions", options
54
52
  end
55
53
 
@@ -67,7 +65,7 @@ module Octokit
67
65
  #
68
66
  # @return [<Sawyer::Resource>] Hash representing the reaction.
69
67
  def create_issue_reaction(repo, number, reaction, options = {})
70
- options = ensure_api_media_type(:reactions, options.merge(:content => reaction))
68
+ options = options.merge(content: reaction)
71
69
  post "#{Repository.path repo}/issues/#{number}/reactions", options
72
70
  end
73
71
 
@@ -83,7 +81,6 @@ module Octokit
83
81
  #
84
82
  # @return [Array<Sawyer::Resource>] Array of Hashes representing the reactions.
85
83
  def issue_comment_reactions(repo, id, options = {})
86
- options = ensure_api_media_type(:reactions, options)
87
84
  get "#{Repository.path repo}/issues/comments/#{id}/reactions", options
88
85
  end
89
86
 
@@ -101,7 +98,7 @@ module Octokit
101
98
  #
102
99
  # @return [<Sawyer::Resource>] Hashes representing the reaction.
103
100
  def create_issue_comment_reaction(repo, id, reaction, options = {})
104
- options = ensure_api_media_type(:reactions, options.merge(:content => reaction))
101
+ options = options.merge(content: reaction)
105
102
  post "#{Repository.path repo}/issues/comments/#{id}/reactions", options
106
103
  end
107
104
 
@@ -117,7 +114,6 @@ module Octokit
117
114
  #
118
115
  # @return [Array<Sawyer::Resource>] Array of Hashes representing the reactions.
119
116
  def pull_request_review_comment_reactions(repo, id, options = {})
120
- options = ensure_api_media_type(:reactions, options)
121
117
  get "#{Repository.path repo}/pulls/comments/#{id}/reactions", options
122
118
  end
123
119
 
@@ -135,7 +131,7 @@ module Octokit
135
131
  #
136
132
  # @return [<Sawyer::Resource>] Hash representing the reaction.
137
133
  def create_pull_request_review_comment_reaction(repo, id, reaction, options = {})
138
- options = ensure_api_media_type(:reactions, options.merge(:content => reaction))
134
+ options = options.merge(content: reaction)
139
135
  post "#{Repository.path repo}/pulls/comments/#{id}/reactions", options
140
136
  end
141
137
 
@@ -150,7 +146,6 @@ module Octokit
150
146
  #
151
147
  # @return [Boolean] Return true if reaction was deleted, false otherwise.
152
148
  def delete_reaction(id, options = {})
153
- options = ensure_api_media_type(:reactions, options)
154
149
  boolean_from_response :delete, "reactions/#{id}", options
155
150
  end
156
151
  end
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for References for Git Data API
5
6
  #
6
7
  # @see https://developer.github.com/v3/git/refs/
7
8
  module Refs
8
-
9
9
  # List all refs for a given user and repo
10
10
  #
11
11
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
@@ -19,9 +19,21 @@ module Octokit
19
19
  path += "/#{namespace}" unless namespace.nil?
20
20
  paginate path, options
21
21
  end
22
- alias :list_refs :refs
23
- alias :references :refs
24
- alias :list_references :refs
22
+ alias list_refs refs
23
+ alias references refs
24
+ alias list_references refs
25
+
26
+ # Fetch matching refs
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> or <tt>heads/rails-3</tt>
30
+ # @return [Array<Sawyer::Resource>] The reference matching the given repo and the ref id
31
+ # @see https://developer.github.com/v3/git/refs/#list-matching-references
32
+ # @example Fetch refs matching tags/v2 for sferik/rails_admin
33
+ # Octokit.ref("sferik/rails_admin","tags/v2")
34
+ def matching_refs(repo, ref, options = {})
35
+ paginate "#{Repository.path repo}/git/matching-refs/#{ref}", options
36
+ end
25
37
 
26
38
  # Fetch a given reference
27
39
  #
@@ -34,7 +46,7 @@ module Octokit
34
46
  def ref(repo, ref, options = {})
35
47
  get "#{Repository.path repo}/git/refs/#{ref}", options
36
48
  end
37
- alias :reference :ref
49
+ alias reference ref
38
50
 
39
51
  # Create a reference
40
52
  #
@@ -46,44 +58,46 @@ module Octokit
46
58
  # @example Create refs/heads/master for octocat/Hello-World with sha 827efc6d56897b048c772eb4087f854f46256132
47
59
  # Octokit.create_ref("octocat/Hello-World", "heads/master", "827efc6d56897b048c772eb4087f854f46256132")
48
60
  def create_ref(repo, ref, sha, options = {})
49
- ref = "refs/#{ref}" unless ref =~ %r{refs/}
61
+ ref = "refs/#{ref}" unless ref =~ %r{\Arefs/}
50
62
  parameters = {
51
- :ref => ref,
52
- :sha => sha
63
+ ref: ref,
64
+ sha: sha
53
65
  }
54
66
  post "#{Repository.path repo}/git/refs", options.merge(parameters)
55
67
  end
56
- alias :create_reference :create_ref
68
+ alias create_reference create_ref
57
69
 
58
70
  # Update a reference
59
71
  #
60
72
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
61
73
  # @param ref [String] The ref, e.g. <tt>tags/v0.0.3</tt>
62
74
  # @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.
75
+ # @param force [Boolean] A flag indicating whether to force the update or to make sure the update is a fast-forward update.
64
76
  # @return [Array<Sawyer::Resource>] The list of references updated
65
77
  # @see https://developer.github.com/v3/git/refs/#update-a-reference
66
78
  # @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
67
79
  # Octokit.update_ref("octocat/Hello-World", "heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
68
- def update_ref(repo, ref, sha, force = true, options = {})
80
+ def update_ref(repo, ref, sha, force = false, options = {})
69
81
  parameters = {
70
- :sha => sha,
71
- :force => force
82
+ sha: sha,
83
+ force: force
72
84
  }
73
85
  patch "#{Repository.path repo}/git/refs/#{ref}", options.merge(parameters)
74
86
  end
75
- alias :update_reference :update_ref
87
+ alias update_reference update_ref
76
88
 
77
89
  # Update a branch
78
90
  #
79
91
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
80
92
  # @param branch [String] The ref, e.g. <tt>feature/new-shiny</tt>
81
93
  # @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.
94
+ # @param force [Boolean] A flag indicating whether to force the update or to make sure the update is a fast-forward update.
83
95
  # @return [Array<Sawyer::Resource>] The list of references updated
84
96
  # @see https://developer.github.com/v3/git/refs/#update-a-reference
85
97
  # @example Force update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
86
- # Octokit.update_ref("octocat/Hello-World","sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
98
+ # Octokit.update_branch("octocat/Hello-World", "sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd")
99
+ # @example Fast-forward update heads/sc/featureA for octocat/Hello-World with sha aa218f56b14c9653891f9e74264a383fa43fefbd
100
+ # Octokit.update_branch("octocat/Hello-World", "sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd", false)
87
101
  def update_branch(repo, branch, sha, force = true, options = {})
88
102
  update_ref repo, "heads/#{branch}", sha, force, options
89
103
  end
@@ -111,8 +125,7 @@ module Octokit
111
125
  def delete_ref(repo, ref, options = {})
112
126
  boolean_from_response :delete, "#{Repository.path repo}/git/refs/#{ref}", options
113
127
  end
114
- alias :delete_reference :delete_ref
115
-
128
+ alias delete_reference delete_ref
116
129
  end
117
130
  end
118
131
  end
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for the Releases API
5
6
  #
6
7
  # @see https://developer.github.com/v3/repos/releases/
7
8
  module Releases
8
-
9
9
  # List releases for a repository
10
10
  #
11
11
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
@@ -14,7 +14,7 @@ module Octokit
14
14
  def releases(repo, options = {})
15
15
  paginate "#{Repository.path repo}/releases", options
16
16
  end
17
- alias :list_releases :releases
17
+ alias list_releases releases
18
18
 
19
19
  # Create a release
20
20
  #
@@ -28,7 +28,7 @@ module Octokit
28
28
  # @return [Sawyer::Resource] The release
29
29
  # @see https://developer.github.com/v3/repos/releases/#create-a-release
30
30
  def create_release(repo, tag_name, options = {})
31
- opts = options.merge(:tag_name => tag_name)
31
+ opts = options.merge(tag_name: tag_name)
32
32
  post "#{Repository.path repo}/releases", opts
33
33
  end
34
34
 
@@ -44,6 +44,7 @@ module Octokit
44
44
  # Update a release
45
45
  #
46
46
  # @param url [String] URL for the release as returned from .releases
47
+ # @option options [String] :tag_name Git tag from which to create release
47
48
  # @option options [String] :target_commitish Specifies the commitish value that determines where the Git tag is created from.
48
49
  # @option options [String] :name Name for the release
49
50
  # @option options [String] :body Content for release notes
@@ -54,7 +55,7 @@ module Octokit
54
55
  def update_release(url, options = {})
55
56
  patch url, options
56
57
  end
57
- alias :edit_release :update_release
58
+ alias edit_release update_release
58
59
 
59
60
  # Delete a release
60
61
  #
@@ -83,17 +84,18 @@ module Octokit
83
84
  # @return [Sawyer::Resource] The release asset
84
85
  # @see https://developer.github.com/v3/repos/releases/#upload-a-release-asset
85
86
  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
+ file = path_or_file.respond_to?(:read) ? path_or_file : File.new(path_or_file, 'rb')
87
88
  options[:content_type] ||= content_type_from_file(file)
88
- raise Octokit::MissingContentType.new if options[:content_type].nil?
89
+ raise Octokit::MissingContentType if options[:content_type].nil?
90
+
89
91
  unless name = options[:name]
90
92
  name = File.basename(file.path)
91
93
  end
92
- upload_url = release(release_url).rels[:upload].href_template.expand(:name => name)
94
+ upload_url = release(release_url).rels[:upload].href_template.expand(name: name)
93
95
 
94
96
  request :post, upload_url, file.read, parse_query_and_convenience_headers(options)
95
97
  ensure
96
- file.close if file
98
+ file&.close
97
99
  end
98
100
 
99
101
  # Get a single release asset
@@ -116,7 +118,7 @@ module Octokit
116
118
  def update_release_asset(asset_url, options = {})
117
119
  patch(asset_url, options)
118
120
  end
119
- alias :edit_release_asset :update_release_asset
121
+ alias edit_release_asset update_release_asset
120
122
 
121
123
  # Delete a release asset
122
124
  #
@@ -154,10 +156,9 @@ module Octokit
154
156
  mime_type.content_type
155
157
  end
156
158
  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
+ msg = 'Please pass content_type or install mime-types gem to guess content type from file'
160
+ raise Octokit::MissingContentType, msg
159
161
  end
160
-
161
162
  end
162
163
  end
163
164
  end