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
@@ -0,0 +1,227 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Methods for the Reviews API
6
+ #
7
+ # @see https://developer.github.com/v3/pulls/reviews/
8
+ module Reviews
9
+ # List reviews on a pull request
10
+ #
11
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
12
+ # @param number [Integer] Number ID of the pull request
13
+ # @see https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request
14
+ #
15
+ # @example
16
+ # @client.pull_request_reviews('octokit/octokit.rb', 2)
17
+ #
18
+ # @return [Array<Sawyer::Resource>] Array of Hashes representing the reviews
19
+ def pull_request_reviews(repo, number, options = {})
20
+ paginate "#{Repository.path repo}/pulls/#{number}/reviews", options
21
+ end
22
+
23
+ # Get a single review
24
+ #
25
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
26
+ # @param number [Integer] Number ID of the pull request
27
+ # @param review [Integer] The id of the review
28
+ # @see https://developer.github.com/v3/pulls/reviews/#get-a-single-review
29
+ #
30
+ # @example
31
+ # @client.pull_request_review('octokit/octokit.rb', 825, 6505518)
32
+ #
33
+ # @return [Sawyer::Resource] Hash representing the review
34
+ def pull_request_review(repo, number, review, options = {})
35
+ get "#{Repository.path repo}/pulls/#{number}/reviews/#{review}", options
36
+ end
37
+
38
+ # Delete a pending review
39
+ #
40
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
41
+ # @param number [Integer] Number ID of the pull request
42
+ # @param review [Integer] The id of the review
43
+ # @see https://developer.github.com/v3/pulls/reviews/#delete-a-pending-review
44
+ #
45
+ # @example
46
+ # @client.delete_pull_request_review('octokit/octokit.rb', 825, 6505518)
47
+ #
48
+ # @return [Sawyer::Resource] Hash representing the deleted review
49
+ def delete_pull_request_review(repo, number, review, options = {})
50
+ delete "#{Repository.path repo}/pulls/#{number}/reviews/#{review}", options
51
+ end
52
+
53
+ # Get comments for a single review
54
+ #
55
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
56
+ # @param number [Integer] Number ID of the pull request
57
+ # @param review [Integer] The id of the review
58
+ # @see https://developer.github.com/v3/pulls/reviews/#get-comments-for-a-single-review
59
+ #
60
+ # @example
61
+ # @client.pull_request_review_comments('octokit/octokit.rb', 825, 6505518)
62
+ #
63
+ # @return [Array<Sawyer::Resource>] Array of Hashes representing the review comments
64
+ def pull_request_review_comments(repo, number, review, options = {})
65
+ paginate "#{Repository.path repo}/pulls/#{number}/reviews/#{review}/comments", options
66
+ end
67
+
68
+ # Create a pull request review
69
+ #
70
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
71
+ # @param number [Integer] Number ID of the pull request
72
+ # @param options [Hash] Method options
73
+ # @option options [String] :event The review action (event) to perform;
74
+ # can be one of APPROVE, REQUEST_CHANGES, or COMMENT.
75
+ # If left blank, the review is left PENDING.
76
+ # @option options [String] :body The body text of the pull request review
77
+ # @option options [Array<Hash>] :comments Comments part of the review
78
+ # @option comments [String] :path The path to the file being commented on
79
+ # @option comments [Integer] :position The position in the file to be commented on
80
+ # @option comments [String] :body Body of the comment
81
+ # @see https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review
82
+ #
83
+ # @example
84
+ # comments = [
85
+ # { path: '.travis.yml', position: 10, body: 'ruby-head is under development that is not stable.' },
86
+ # { path: '.travis.yml', position: 32, body: 'ruby-head is also required in thervm section.' },
87
+ # ]
88
+ # options = { event: 'REQUEST_CHANGES', comments: comments }
89
+ # @client.create_pull_request_review('octokit/octokit.rb', 844, options)
90
+ #
91
+ # @return [Sawyer::Resource>] Hash respresenting the review
92
+ def create_pull_request_review(repo, number, options = {})
93
+ post "#{Repository.path repo}/pulls/#{number}/reviews", options
94
+ end
95
+
96
+ # Submit a pull request review
97
+ #
98
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
99
+ # @param number [Integer] Number ID of the pull request
100
+ # @param review [Integer] The id of the review
101
+ # @param event [String] The review action (event) to perform; can be one of
102
+ # APPROVE, REQUEST_CHANGES, or COMMENT.
103
+ # @param options [Hash] Method options
104
+ # @option options [String] :body The body text of the pull request review
105
+ # @see https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review
106
+ #
107
+ # @example
108
+ # @client.submit_pull_request_review('octokit/octokit.rb', 825, 6505518,
109
+ # 'APPROVE', body: 'LGTM!')
110
+ #
111
+ # @return [Sawyer::Resource] Hash respresenting the review
112
+ def submit_pull_request_review(repo, number, review, event, options = {})
113
+ options = options.merge(event: event)
114
+ post "#{Repository.path repo}/pulls/#{number}/reviews/#{review}/events", options
115
+ end
116
+
117
+ # Dismiss a pull request review
118
+ #
119
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
120
+ # @param number [Integer] Number ID of the pull request
121
+ # @param review [Integer] The id of the review
122
+ # @param message [String] The message for the pull request review dismissal
123
+ # @see https://developer.github.com/v3/pulls/reviews/#dismiss-a-pull-request-review
124
+ #
125
+ # @example
126
+ # @client.dismiss_pull_request_review('octokit/octokit.rb', 825, 6505518, 'The message.')
127
+ #
128
+ # @return [Sawyer::Resource] Hash representing the dismissed review
129
+ def dismiss_pull_request_review(repo, number, review, message, options = {})
130
+ options = options.merge(message: message)
131
+ put "#{Repository.path repo}/pulls/#{number}/reviews/#{review}/dismissals", options
132
+ end
133
+
134
+ # List review requests
135
+ #
136
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
137
+ # @param number [Integer] Number ID of the pull request
138
+ # @see https://developer.github.com/v3/pulls/review_requests/#list-review-requests
139
+ #
140
+ # @example
141
+ # @client.pull_request_review_requests('octokit/octokit.rb', 2)
142
+ #
143
+ # @return [Array<Sawyer::Resource>] Array of Hashes representing the review requests
144
+ def pull_request_review_requests(repo, number, options = {})
145
+ paginate "#{Repository.path repo}/pulls/#{number}/requested_reviewers", options
146
+ end
147
+
148
+ # Create a review request
149
+ #
150
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
151
+ # @param number [Integer] Number ID of the pull request
152
+ # @param reviewers [Hash] :reviewers [Array<String>] An array of user logins
153
+ # @param options [Hash] :team_reviewers [Array<String>] An array of team slugs
154
+ # @see https://developer.github.com/v3/pulls/review_requests/#create-a-review-request
155
+ #
156
+ # @example
157
+ # @client.request_pull_request_review('octokit/octokit.rb', 2, reviewers: ['soudy'])
158
+ #
159
+ # @return [Sawyer::Resource>] Hash respresenting the pull request
160
+ def request_pull_request_review(repo, number, reviewers = {}, options = {})
161
+ # TODO(5.0): remove deprecated behavior
162
+ if reviewers.is_a?(Array)
163
+ octokit_warn(
164
+ 'Deprecated: Octokit::Client#request_pull_request_review ' \
165
+ "no longer takes a separate :reviewers argument.\n" \
166
+ 'Please update your call to pass :reviewers and :team_reviewers as part of the options hash.'
167
+ )
168
+ options = options.merge(reviewers: reviewers)
169
+ else
170
+ options = options.merge(reviewers)
171
+ end
172
+
173
+ post "#{Repository.path repo}/pulls/#{number}/requested_reviewers", options
174
+ end
175
+
176
+ # Delete a review request
177
+ #
178
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
179
+ # @param id [Integer] The id of the pull request
180
+ # @param reviewers [Hash] :reviewers [Array] An array of user logins
181
+ # @param options [Hash] :team_reviewers [Array] An array of team slugs
182
+ #
183
+ # @see https://developer.github.com/v3/pulls/review_requests/#delete-a-review-request
184
+ #
185
+ # @example
186
+ # options = {
187
+ # "reviewers" => [ "octocat", "hubot", "other_user" ],
188
+ # "team_reviewers" => [ "justice-league" ]
189
+ # }
190
+ # @client.delete_pull_request_review_request('octokit/octokit.rb', 2, options)
191
+ #
192
+ # @return [Sawyer::Resource>] Hash representing the pull request
193
+ def delete_pull_request_review_request(repo, id, reviewers = {}, options = {})
194
+ # TODO(5.0): remove deprecated behavior
195
+ if !reviewers.empty? && !options.empty?
196
+ octokit_warn(
197
+ 'Deprecated: Octokit::Client#delete_pull_request_review_request ' \
198
+ "no longer takes a separate :reviewers argument.\n" \
199
+ 'Please update your call to pass :reviewers and :team_reviewers as part of the options hash.'
200
+ )
201
+ end
202
+ # For backwards compatibility, this endpoint can be called with a separate reviewers hash.
203
+ # If not called with a separate hash, then 'reviewers' is, in fact, 'options'.
204
+ options = options.merge(reviewers)
205
+ delete "#{Repository.path repo}/pulls/#{id}/requested_reviewers", options
206
+ end
207
+
208
+ # Update a review request comment
209
+ #
210
+ # @param repo [Integer, String, Hash, Repository] A GitHub repository
211
+ # @param number [Integer] Number ID of the pull request
212
+ # @param review [Integer] The id of the review
213
+ # @param body [String] body text of the pull request review.
214
+ # @param options [Hash] Method options
215
+ # @see https://developer.github.com/v3/pulls/reviews/#update-a-pull-request-review
216
+ #
217
+ # @example
218
+ # @client.update_pull_request_review('octokit/octokit.rb', 825, 6505518, 'This is close to perfect! Please address the suggested inline change. And add more about this.')
219
+ #
220
+ # @return [Sawyer::Resource] Hash representing the review comment
221
+ def update_pull_request_review(repo, number, review, body, options = {})
222
+ options[:body] = body
223
+ put "#{Repository.path repo}/pulls/#{number}/reviews/#{review}", options
224
+ end
225
+ end
226
+ end
227
+ end
@@ -1,19 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for the unpublished Octocat API
5
6
  module Say
6
-
7
7
  # Return a nifty ASCII Octocat with GitHub wisdom
8
8
  # or your own
9
9
  #
10
10
  # @return [String]
11
11
  def say(text = nil, options = {})
12
12
  options[:s] = text if text
13
- get "octocat", options
13
+ get 'octocat', options
14
14
  end
15
- alias :octocat :say
16
-
15
+ alias octocat say
17
16
  end
18
17
  end
19
18
  end
@@ -1,23 +1,37 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for the Search API
5
6
  #
6
7
  # @see https://developer.github.com/v3/search/
7
8
  module Search
8
-
9
9
  # Search code
10
10
  #
11
11
  # @param query [String] Search term and qualifiers
12
12
  # @param options [Hash] Sort and pagination options
13
13
  # @option options [String] :sort Sort field
14
14
  # @option options [String] :order Sort order (asc or desc)
15
- # @option options [Fixnum] :page Page of paginated results
16
- # @option options [Fixnum] :per_page Number of items per page
15
+ # @option options [Integer] :page Page of paginated results
16
+ # @option options [Integer] :per_page Number of items per page
17
17
  # @return [Sawyer::Resource] Search results object
18
18
  # @see https://developer.github.com/v3/search/#search-code
19
19
  def search_code(query, options = {})
20
- search "search/code", query, options
20
+ search 'search/code', query, options
21
+ end
22
+
23
+ # Search commits
24
+ #
25
+ # @param query [String] Search terms and qualifiers
26
+ # @param options [Hash] Sort and pagination options
27
+ # @option options [String] :sort Sort field
28
+ # @option options [String] :order Sort order (asc or desc)
29
+ # @option options [Integer] :page Page of paginated results
30
+ # @option options [Integer] :per_page Number of items per page
31
+ # @return [Sawyer::Resource] Search results object
32
+ # @see https://developer.github.com/v3/search/#search-commits
33
+ def search_commits(query, options = {})
34
+ search 'search/commits', query, options
21
35
  end
22
36
 
23
37
  # Search issues
@@ -26,12 +40,13 @@ module Octokit
26
40
  # @param options [Hash] Sort and pagination options
27
41
  # @option options [String] :sort Sort field
28
42
  # @option options [String] :order Sort order (asc or desc)
29
- # @option options [Fixnum] :page Page of paginated results
30
- # @option options [Fixnum] :per_page Number of items per page
43
+ # @option options [Integer] :page Page of paginated results
44
+ # @option options [Integer] :per_page Number of items per page
31
45
  # @return [Sawyer::Resource] Search results object
32
- # @see https://developer.github.com/v3/search/#search-issues
46
+ # @see https://developer.github.com/v3/search/#search-issues-and-pull-requests
47
+ # @see https://docs.github.com/en/rest/search#limitations-on-query-length
33
48
  def search_issues(query, options = {})
34
- search "search/issues", query, options
49
+ search 'search/issues', query, options
35
50
  end
36
51
 
37
52
  # Search repositories
@@ -40,14 +55,28 @@ module Octokit
40
55
  # @param options [Hash] Sort and pagination options
41
56
  # @option options [String] :sort Sort field
42
57
  # @option options [String] :order Sort order (asc or desc)
43
- # @option options [Fixnum] :page Page of paginated results
44
- # @option options [Fixnum] :per_page Number of items per page
58
+ # @option options [Integer] :page Page of paginated results
59
+ # @option options [Integer] :per_page Number of items per page
45
60
  # @return [Sawyer::Resource] Search results object
46
61
  # @see https://developer.github.com/v3/search/#search-repositories
47
62
  def search_repositories(query, options = {})
48
- search "search/repositories", query, options
63
+ search 'search/repositories', query, options
64
+ end
65
+ alias search_repos search_repositories
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
49
79
  end
50
- alias :search_repos :search_repositories
51
80
 
52
81
  # Search users
53
82
  #
@@ -55,18 +84,18 @@ module Octokit
55
84
  # @param options [Hash] Sort and pagination options
56
85
  # @option options [String] :sort Sort field
57
86
  # @option options [String] :order Sort order (asc or desc)
58
- # @option options [Fixnum] :page Page of paginated results
59
- # @option options [Fixnum] :per_page Number of items per page
87
+ # @option options [Integer] :page Page of paginated results
88
+ # @option options [Integer] :per_page Number of items per page
60
89
  # @return [Sawyer::Resource] Search results object
61
90
  # @see https://developer.github.com/v3/search/#search-users
62
91
  def search_users(query, options = {})
63
- search "search/users", query, options
92
+ search 'search/users', query, options
64
93
  end
65
94
 
66
95
  private
67
96
 
68
97
  def search(path, query, options = {})
69
- opts = options.merge(:q => query)
98
+ opts = options.merge(q: query)
70
99
  paginate(path, opts) do |data, last_response|
71
100
  data.items.concat last_response.data.items
72
101
  end
@@ -1,37 +1,47 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Octokit
2
4
  class Client
3
-
4
5
  # Methods for the GitHub Status API
5
6
  #
6
7
  # @see https://status.github.com/api
7
8
  module ServiceStatus
8
-
9
9
  # Root for status API
10
10
  # @private
11
- STATUS_ROOT = 'https://status.github.com/api.json'
11
+ SUMMARY_ROOT = 'https://www.githubstatus.com/api/v2/summary.json'
12
+ STATUS_ROOT = 'https://www.githubstatus.com/api/v2/status.json'
13
+ COMPONENTS_ROOT = 'https://www.githubstatus.com/api/v2/components.json'
14
+
15
+ # Returns a summary with the current status and the last status messages.
16
+ #
17
+ # @return [<Sawyer::Resource>] GitHub status summary
18
+ # @see https://www.githubstatus.com/api#summory
19
+ def github_status_summary
20
+ get(SUMMARY_ROOT)
21
+ end
12
22
 
13
23
  # Returns the current system status
14
24
  #
15
25
  # @return [Sawyer::Resource] GitHub status
16
- # @see https://status.github.com/api#api-current-status
26
+ # @see https://www.githubstatus.com/api#status
17
27
  def github_status
18
- get(STATUS_ROOT).rels[:status].get.data
28
+ get(STATUS_ROOT)
19
29
  end
20
30
 
21
31
  # Returns the last human communication, status, and timestamp.
22
32
  #
23
33
  # @return [Sawyer::Resource] GitHub status last message
24
- # @see https://status.github.com/api#api-last-message
34
+ # @see https://www.githubstatus.com/api/#components
25
35
  def github_status_last_message
26
- get(STATUS_ROOT).rels[:last_message].get.data
36
+ get(COMPONENTS_ROOT).components.first
27
37
  end
28
38
 
29
39
  # Returns the most recent human communications with status and timestamp.
30
40
  #
31
41
  # @return [Array<Sawyer::Resource>] GitHub status messages
32
- # @see https://status.github.com/api#api-recent-messages
42
+ # @see https://www.githubstatus.com/api#components
33
43
  def github_status_messages
34
- get(STATUS_ROOT).rels[:messages].get.data
44
+ get(COMPONENTS_ROOT).components
35
45
  end
36
46
  end
37
47
  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 Source Import API
5
6
  #
6
7
  # @see https://developer.github.com/v3/migration/source_imports
7
8
  module SourceImport
8
-
9
9
  # Start a source import to a GitHub repository using GitHub Importer.
10
10
  #
11
11
  # @overload start_source_import(repo, vcs, vcs_url, options = {})
@@ -39,10 +39,10 @@ module Octokit
39
39
  vcs_url = arguments.pop
40
40
  vcs = arguments.pop
41
41
  if vcs
42
- octokit_warn "Octokit#start_source_import vcs parameter is now an option, please update your call before the next major Octokit version update."
43
- arguments.options.merge!(:vcs => vcs)
42
+ octokit_warn 'Octokit#start_source_import vcs parameter is now an option, please update your call before the next major Octokit version update.'
43
+ arguments.options.merge!(vcs: vcs)
44
44
  end
45
- options = ensure_api_media_type(:source_imports, arguments.options.merge(:vcs_url => vcs_url))
45
+ options = arguments.options.merge(vcs_url: vcs_url)
46
46
  put "#{Repository.path arguments.repo}/import", options
47
47
  end
48
48
 
@@ -55,7 +55,6 @@ module Octokit
55
55
  # @example
56
56
  # @client.source_import_progress("octokit/octokit.rb")
57
57
  def source_import_progress(repo, options = {})
58
- options = ensure_api_media_type(:source_imports, options)
59
58
  get "#{Repository.path repo}/import", options
60
59
  end
61
60
 
@@ -76,7 +75,6 @@ module Octokit
76
75
  # :vcs_password => "secret"
77
76
  # })
78
77
  def update_source_import(repo, options = {})
79
- options = ensure_api_media_type(:source_imports, options)
80
78
  patch "#{Repository.path repo}/import", options
81
79
  end
82
80
 
@@ -91,7 +89,6 @@ module Octokit
91
89
  # @example
92
90
  # @client.source_import_commit_authors("octokit/octokit.rb")
93
91
  def source_import_commit_authors(repo, options = {})
94
- options = ensure_api_media_type(:source_imports, options)
95
92
  get "#{Repository.path repo}/import/authors", options
96
93
  end
97
94
 
@@ -111,7 +108,7 @@ module Octokit
111
108
  # :name => "Hubot the Robot"
112
109
  # })
113
110
  def map_source_import_commit_author(author_url, values, options = {})
114
- options = ensure_api_media_type(:source_imports, options.merge(values))
111
+ options = options.merge(values)
115
112
  patch author_url, options
116
113
  end
117
114
 
@@ -124,7 +121,6 @@ module Octokit
124
121
  # @example
125
122
  # @client.cancel_source_import("octokit/octokit.rb")
126
123
  def cancel_source_import(repo, options = {})
127
- options = ensure_api_media_type(:source_imports, options)
128
124
  boolean_from_response :delete, "#{Repository.path repo}/import", options
129
125
  end
130
126
 
@@ -132,14 +128,13 @@ module Octokit
132
128
  #
133
129
  # @param repo [Integer, String, Hash, Repository] A GitHub repository.
134
130
  # @param options [Hash]
135
- # @option options [Fixnum] :page Page of paginated results
131
+ # @option options [Integer] :page Page of paginated results
136
132
  # @return [Array<Sawyer::Resource>] Array of hashes representing files over 100MB.
137
133
  # @see https://developer.github.com/v3/migration/source_imports/#get-large-files
138
134
  #
139
135
  # @example
140
136
  # @client.source_import_large_files("octokit/octokit.rb")
141
137
  def source_import_large_files(repo, options = {})
142
- options = ensure_api_media_type(:source_imports, options)
143
138
  get "#{Repository.path repo}/import/large_files", options
144
139
  end
145
140
 
@@ -153,7 +148,7 @@ module Octokit
153
148
  # @example
154
149
  # @client.opt_in_source_import_lfs("octokit/octokit.rb", "opt_in")
155
150
  def set_source_import_lfs_preference(repo, use_lfs, options = {})
156
- options = ensure_api_media_type(:source_imports, options.merge(:use_lfs => use_lfs))
151
+ options = options.merge(use_lfs: use_lfs)
157
152
  patch "#{Repository.path repo}/import/lfs", options
158
153
  end
159
154
  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 Repository Statistics API
5
6
  #
6
7
  # @see https://developer.github.com/v3/repos/statistics/
7
8
  module Stats
8
-
9
9
  # Get contributors list with additions, deletions, and commit counts
10
10
  #
11
11
  # @param repo [Integer, String, Hash, Repository] A GitHub repository
@@ -16,9 +16,9 @@ module Octokit
16
16
  # @example Get contributor stats for octokit
17
17
  # @client.contributors_stats('octokit/octokit.rb')
18
18
  def contributors_stats(repo, options = {})
19
- get_stats(repo, "contributors", options)
19
+ get_stats(repo, 'contributors', options)
20
20
  end
21
- alias :contributor_stats :contributors_stats
21
+ alias contributor_stats contributors_stats
22
22
 
23
23
  # Get the last year of commit activity data
24
24
  #
@@ -31,7 +31,7 @@ module Octokit
31
31
  # @example Get commit activity for octokit
32
32
  # @client.commit_activity_stats('octokit/octokit.rb')
33
33
  def commit_activity_stats(repo, options = {})
34
- get_stats(repo, "commit_activity", options)
34
+ get_stats(repo, 'commit_activity', options)
35
35
  end
36
36
 
37
37
  # Get the number of additions and deletions per week
@@ -45,7 +45,7 @@ module Octokit
45
45
  # @example Get code frequency stats for octokit
46
46
  # @client.code_frequency_stats('octokit/octokit.rb')
47
47
  def code_frequency_stats(repo, options = {})
48
- get_stats(repo, "code_frequency", options)
48
+ get_stats(repo, 'code_frequency', options)
49
49
  end
50
50
 
51
51
  # Get the weekly commit count for the repo owner and everyone else
@@ -61,7 +61,7 @@ module Octokit
61
61
  # @example Get weekly commit counts for octokit
62
62
  # @client.participation_stats("octokit/octokit.rb")
63
63
  def participation_stats(repo, options = {})
64
- get_stats(repo, "participation", options)
64
+ get_stats(repo, 'participation', options)
65
65
  end
66
66
 
67
67
  # Get the number of commits per hour in each day
@@ -75,9 +75,9 @@ module Octokit
75
75
  # @example Get octokit punch card
76
76
  # @octokit.punch_card_stats
77
77
  def punch_card_stats(repo, options = {})
78
- get_stats(repo, "punch_card", options)
78
+ get_stats(repo, 'punch_card', options)
79
79
  end
80
- alias :punch_card :punch_card_stats
80
+ alias punch_card punch_card_stats
81
81
 
82
82
  private
83
83
 
@@ -88,6 +88,7 @@ module Octokit
88
88
  # @return [Array<Sawyer::Resource> or nil] Stats in metric-specific format, or nil if not yet calculated.
89
89
  # @see https://developer.github.com/v3/repos/statistics/
90
90
  def get_stats(repo, metric, options = {})
91
+ options = options.dup
91
92
  if retry_timeout = options.delete(:retry_timeout)
92
93
  retry_wait = options.delete(:retry_wait) || 0.5
93
94
  timeout = Time.now + retry_timeout
@@ -95,8 +96,10 @@ module Octokit
95
96
  loop do
96
97
  data = get("#{Repository.path repo}/stats/#{metric}", options)
97
98
  return data if last_response.status == 200
99
+ return [] if last_response.status == 204
98
100
  return nil unless retry_timeout
99
101
  return nil if Time.now >= timeout
102
+
100
103
  sleep retry_wait if retry_wait
101
104
  end
102
105
  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 Commit Statuses API
5
6
  #
6
7
  # @see https://developer.github.com/v3/repos/statuses/
7
8
  module Statuses
8
-
9
9
  # List all statuses for a given commit
10
10
  #
11
11
  # @param repo [Integer, String, Repository, Hash] A GitHub repository
@@ -13,9 +13,9 @@ module Octokit
13
13
  # @return [Array<Sawyer::Resource>] A list of statuses
14
14
  # @see https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
15
15
  def statuses(repo, sha, options = {})
16
- get "#{Repository.path repo}/statuses/#{sha}", options
16
+ paginate "#{Repository.path repo}/statuses/#{sha}", options
17
17
  end
18
- alias :list_statuses :statuses
18
+ alias list_statuses statuses
19
19
 
20
20
  # Get the combined status for a ref
21
21
  #
@@ -26,7 +26,7 @@ module Octokit
26
26
  def combined_status(repo, ref, options = {})
27
27
  get "#{Repository.path repo}/commits/#{ref}/status", options
28
28
  end
29
- alias :status :combined_status
29
+ alias status combined_status
30
30
 
31
31
  # Create status for a commit
32
32
  #
@@ -39,7 +39,7 @@ module Octokit
39
39
  # @return [Sawyer::Resource] A status
40
40
  # @see https://developer.github.com/v3/repos/statuses/#create-a-status
41
41
  def create_status(repo, sha, state, options = {})
42
- options.merge!(:state => state)
42
+ options = options.merge(state: state)
43
43
  post "#{Repository.path repo}/statuses/#{sha}", options
44
44
  end
45
45
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Octokit
4
+ class Client
5
+ # Method to check scopes
6
+ #
7
+ # @see https://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api
8
+ module Tokens
9
+ # Check scopes for a token
10
+ #
11
+ # @param token [String] GitHub OAuth token
12
+ # @param options [Hash] Header params for request
13
+ # @return [Array<String>] OAuth scopes
14
+ # @see https://developer.github.com/v3/oauth/#scopes
15
+ def scopes(token = @access_token, options = {})
16
+ options = options.dup
17
+ raise ArgumentError, 'Access token required' if token.nil?
18
+
19
+ auth = { 'Authorization' => "token #{token}" }
20
+ headers = (options.delete(:headers) || {}).merge(auth)
21
+
22
+ agent.call(:get, 'user', headers: headers)
23
+ .headers['X-OAuth-Scopes']
24
+ .to_s
25
+ .split(',')
26
+ .map(&:strip)
27
+ .sort
28
+ end
29
+ end
30
+ end
31
+ end