octokit 4.2.0 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +14 -13
- data/LICENSE.md +1 -1
- data/README.md +275 -127
- data/Rakefile +20 -14
- data/lib/ext/sawyer/relation.rb +12 -0
- data/lib/octokit/arguments.rb +3 -3
- data/lib/octokit/authentication.rb +20 -14
- data/lib/octokit/client/actions_artifacts.rb +71 -0
- data/lib/octokit/client/actions_secrets.rb +161 -0
- data/lib/octokit/client/actions_workflow_jobs.rb +65 -0
- data/lib/octokit/client/actions_workflow_runs.rb +125 -0
- data/lib/octokit/client/actions_workflows.rb +68 -0
- data/lib/octokit/client/apps.rb +259 -0
- data/lib/octokit/client/checks.rb +200 -0
- data/lib/octokit/client/code_scanning.rb +190 -0
- data/lib/octokit/client/codespaces_secrets.rb +108 -0
- data/lib/octokit/client/commit_branches.rb +20 -0
- data/lib/octokit/client/commit_comments.rb +8 -8
- data/lib/octokit/client/commit_pulls.rb +20 -0
- data/lib/octokit/client/commits.rb +32 -35
- data/lib/octokit/client/community_profile.rb +21 -0
- data/lib/octokit/client/contents.rb +24 -21
- data/lib/octokit/client/dependabot_secrets.rb +108 -0
- data/lib/octokit/client/deployments.rb +29 -7
- data/lib/octokit/client/downloads.rb +5 -6
- data/lib/octokit/client/emojis.rb +3 -3
- data/lib/octokit/client/environments.rb +58 -0
- data/lib/octokit/client/events.rb +4 -4
- data/lib/octokit/client/feeds.rb +4 -5
- data/lib/octokit/client/gists.rb +36 -8
- data/lib/octokit/client/gitignore.rb +3 -3
- data/lib/octokit/client/hooks.rb +34 -30
- data/lib/octokit/client/issues.rb +97 -14
- data/lib/octokit/client/labels.rb +17 -17
- data/lib/octokit/client/legacy_search.rb +3 -3
- data/lib/octokit/client/licenses.rb +5 -8
- data/lib/octokit/client/markdown.rb +3 -3
- data/lib/octokit/client/marketplace.rb +56 -0
- data/lib/octokit/client/meta.rb +4 -5
- data/lib/octokit/client/milestones.rb +14 -14
- data/lib/octokit/client/notifications.rb +7 -11
- data/lib/octokit/client/oauth_applications.rb +116 -0
- data/lib/octokit/client/objects.rb +14 -14
- data/lib/octokit/client/organizations.rb +256 -73
- data/lib/octokit/client/pages.rb +26 -3
- data/lib/octokit/client/projects.rb +294 -0
- data/lib/octokit/client/pull_requests.rb +74 -51
- data/lib/octokit/client/rate_limit.rb +11 -13
- data/lib/octokit/client/reactions.rb +204 -0
- data/lib/octokit/client/refs.rb +34 -20
- data/lib/octokit/client/releases.rb +16 -13
- data/lib/octokit/client/repositories.rb +276 -60
- data/lib/octokit/client/repository_invitations.rb +96 -0
- data/lib/octokit/client/reviews.rb +227 -0
- data/lib/octokit/client/say.rb +4 -5
- data/lib/octokit/client/search.rb +46 -17
- data/lib/octokit/client/service_status.rb +19 -9
- data/lib/octokit/client/source_import.rb +156 -0
- data/lib/octokit/client/stats.rb +39 -17
- data/lib/octokit/client/statuses.rb +6 -6
- data/lib/octokit/client/tokens.rb +31 -0
- data/lib/octokit/client/traffic.rb +64 -0
- data/lib/octokit/client/users.rb +133 -25
- data/lib/octokit/client.rb +85 -19
- data/lib/octokit/configurable.rb +60 -32
- data/lib/octokit/connection.rb +45 -21
- data/lib/octokit/default.rb +82 -35
- data/lib/octokit/enterprise_admin_client/admin_stats.rb +14 -15
- data/lib/octokit/enterprise_admin_client/license.rb +4 -5
- data/lib/octokit/enterprise_admin_client/orgs.rb +7 -6
- data/lib/octokit/enterprise_admin_client/search_indexing.rb +8 -9
- data/lib/octokit/enterprise_admin_client/users.rb +19 -18
- data/lib/octokit/enterprise_admin_client.rb +11 -3
- data/lib/octokit/enterprise_management_console_client/management_console.rb +52 -34
- data/lib/octokit/enterprise_management_console_client.rb +9 -3
- data/lib/octokit/error.rb +144 -26
- data/lib/octokit/gist.rb +4 -5
- data/lib/octokit/manage_ghes_client/manage_ghes.rb +178 -0
- data/lib/octokit/manage_ghes_client.rb +64 -0
- data/lib/octokit/middleware/follow_redirects.rb +18 -14
- data/lib/octokit/organization.rb +3 -1
- data/lib/octokit/rate_limit.rb +11 -9
- data/lib/octokit/repo_arguments.rb +3 -4
- data/lib/octokit/repository.rb +35 -23
- data/lib/octokit/response/base_middleware.rb +10 -0
- data/lib/octokit/response/feed_parser.rb +5 -9
- data/lib/octokit/response/raise_error.rb +4 -6
- data/lib/octokit/user.rb +4 -2
- data/lib/octokit/version.rb +3 -1
- data/lib/octokit/warnable.rb +4 -5
- data/lib/octokit.rb +30 -8
- data/octokit.gemspec +12 -10
- metadata +47 -24
- data/lib/octokit/client/authorizations.rb +0 -256
- data/lib/octokit/client/pub_sub_hubbub.rb +0 -111
- data/lib/octokit/preview.rb +0 -28
@@ -0,0 +1,156 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Octokit
|
4
|
+
class Client
|
5
|
+
# Methods for the Source Import API
|
6
|
+
#
|
7
|
+
# @see https://developer.github.com/v3/migration/source_imports
|
8
|
+
module SourceImport
|
9
|
+
# Start a source import to a GitHub repository using GitHub Importer.
|
10
|
+
#
|
11
|
+
# @overload start_source_import(repo, vcs, vcs_url, options = {})
|
12
|
+
# @deprecated
|
13
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
14
|
+
# @param vcs [String] The originating VCS type. Can be one of "subversion", "git", "mercurial", or "tfvc".
|
15
|
+
# @param vcs_url [String] The URL of the originating repository.
|
16
|
+
# @param options [Hash]
|
17
|
+
# @option options [String] :vcs_username If authentication is required, the username to provide to vcs_url.
|
18
|
+
# @option options [String] :vcs_password If authentication is required, the password to provide to vcs_url.
|
19
|
+
# @option options [String] :tfvc_project For a tfvc import, the name of the project that is being imported.
|
20
|
+
# @overload start_source_import(repo, vcs_url, options = {})
|
21
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
22
|
+
# @param vcs_url [String] The URL of the originating repository.
|
23
|
+
# @param options [Hash]
|
24
|
+
# @param options [String] :vcs The originating VCS type. Can be one of "subversion", "git", "mercurial", or "tfvc".
|
25
|
+
# @option options [String] :vcs_username If authentication is required, the username to provide to vcs_url.
|
26
|
+
# @option options [String] :vcs_password If authentication is required, the password to provide to vcs_url.
|
27
|
+
# @option options [String] :tfvc_project For a tfvc import, the name of the project that is being imported.
|
28
|
+
# @return [Sawyer::Resource] Hash representing the repository import
|
29
|
+
# @see https://developer.github.com/v3/migration/source_imports/#start-an-import
|
30
|
+
#
|
31
|
+
# @example
|
32
|
+
# @client.start_source_import("octokit/octokit.rb", "http://svn.mycompany.com/svn/myproject", {
|
33
|
+
# :vcs => "subversion",
|
34
|
+
# :vcs_username" => "octocat",
|
35
|
+
# :vcs_password => "secret"
|
36
|
+
# })
|
37
|
+
def start_source_import(*args)
|
38
|
+
arguments = Octokit::RepoArguments.new(args)
|
39
|
+
vcs_url = arguments.pop
|
40
|
+
vcs = arguments.pop
|
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)
|
44
|
+
end
|
45
|
+
options = arguments.options.merge(vcs_url: vcs_url)
|
46
|
+
put "#{Repository.path arguments.repo}/import", options
|
47
|
+
end
|
48
|
+
|
49
|
+
# View the progress of an import.
|
50
|
+
#
|
51
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
52
|
+
# @return [Sawyer::Resource] Hash representing the progress of the import
|
53
|
+
# @see https://developer.github.com/v3/migration/source_imports/#get-import-progress
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# @client.source_import_progress("octokit/octokit.rb")
|
57
|
+
def source_import_progress(repo, options = {})
|
58
|
+
get "#{Repository.path repo}/import", options
|
59
|
+
end
|
60
|
+
|
61
|
+
# Update source import with authentication or project choice
|
62
|
+
# Restart source import if no options are passed
|
63
|
+
#
|
64
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
65
|
+
# @return [Sawyer::Resource] Hash representing the repository import
|
66
|
+
# @see https://developer.github.com/v3/migration/source_imports/#update-existing-import
|
67
|
+
# @option options [String] :vcs_username If authentication is required, the username to provide to vcs_url.
|
68
|
+
# @option options [String] :vcs_password If authentication is required, the password to provide to vcs_url.
|
69
|
+
# @option options [String] To update project choice, please refer to the project_choice array from the progress return hash for the exact attributes.
|
70
|
+
# https://developer.github.com/v3/migration/source_imports/#update-existing-import
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# @client.update_source_import("octokit/octokit.rb", {
|
74
|
+
# :vcs_username" => "octocat",
|
75
|
+
# :vcs_password => "secret"
|
76
|
+
# })
|
77
|
+
def update_source_import(repo, options = {})
|
78
|
+
patch "#{Repository.path repo}/import", options
|
79
|
+
end
|
80
|
+
|
81
|
+
# List source import commit authors
|
82
|
+
#
|
83
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
84
|
+
# @param options [Hash]
|
85
|
+
# @option options [String] :since Only authors found after this id are returned.
|
86
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing commit_authors.
|
87
|
+
# @see https://developer.github.com/v3/migration/source_imports/#get-commit-authors
|
88
|
+
#
|
89
|
+
# @example
|
90
|
+
# @client.source_import_commit_authors("octokit/octokit.rb")
|
91
|
+
def source_import_commit_authors(repo, options = {})
|
92
|
+
get "#{Repository.path repo}/import/authors", options
|
93
|
+
end
|
94
|
+
|
95
|
+
# Update an author's identity for the import.
|
96
|
+
#
|
97
|
+
# @param author_url [String] The source import API url for the commit author
|
98
|
+
# @param values [Hash] The updated author attributes
|
99
|
+
# @option values [String] :email The new Git author email.
|
100
|
+
# @option values [String] :name The new Git author name.
|
101
|
+
# @return [Sawyer::Resource] Hash representing the updated commit author
|
102
|
+
# @see https://developer.github.com/v3/migration/source_imports/#map-a-commit-author
|
103
|
+
#
|
104
|
+
# @example
|
105
|
+
# author_url = "https://api.github.com/repos/octokit/octokit.rb/import/authors/1"
|
106
|
+
# @client.map_source_import_commit_author(author_url, {
|
107
|
+
# :email => "hubot@github.com",
|
108
|
+
# :name => "Hubot the Robot"
|
109
|
+
# })
|
110
|
+
def map_source_import_commit_author(author_url, values, options = {})
|
111
|
+
options = options.merge(values)
|
112
|
+
patch author_url, options
|
113
|
+
end
|
114
|
+
|
115
|
+
# Stop an import for a repository.
|
116
|
+
#
|
117
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
118
|
+
# @return [Boolean] True if the import has been cancelled, false otherwise.
|
119
|
+
# @see https://developer.github.com/v3/migration/source_imports/#cancel-an-import
|
120
|
+
#
|
121
|
+
# @example
|
122
|
+
# @client.cancel_source_import("octokit/octokit.rb")
|
123
|
+
def cancel_source_import(repo, options = {})
|
124
|
+
boolean_from_response :delete, "#{Repository.path repo}/import", options
|
125
|
+
end
|
126
|
+
|
127
|
+
# List source import large files
|
128
|
+
#
|
129
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
130
|
+
# @param options [Hash]
|
131
|
+
# @option options [Integer] :page Page of paginated results
|
132
|
+
# @return [Array<Sawyer::Resource>] Array of hashes representing files over 100MB.
|
133
|
+
# @see https://developer.github.com/v3/migration/source_imports/#get-large-files
|
134
|
+
#
|
135
|
+
# @example
|
136
|
+
# @client.source_import_large_files("octokit/octokit.rb")
|
137
|
+
def source_import_large_files(repo, options = {})
|
138
|
+
get "#{Repository.path repo}/import/large_files", options
|
139
|
+
end
|
140
|
+
|
141
|
+
# Set preference for using Git LFS to import files over 100MB
|
142
|
+
#
|
143
|
+
# @param repo [Integer, String, Hash, Repository] A GitHub repository.
|
144
|
+
# @param use_lfs [String] Preference for using Git LFS to import large files. Can be one of "opt_in" or "opt_out"
|
145
|
+
# @return [Sawyer::Resource] Hash representing the repository import
|
146
|
+
# @see https://developer.github.com/v3/migration/source_imports/#set-git-lfs-preference
|
147
|
+
#
|
148
|
+
# @example
|
149
|
+
# @client.opt_in_source_import_lfs("octokit/octokit.rb", "opt_in")
|
150
|
+
def set_source_import_lfs_preference(repo, use_lfs, options = {})
|
151
|
+
options = options.merge(use_lfs: use_lfs)
|
152
|
+
patch "#{Repository.path repo}/import/lfs", options
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
data/lib/octokit/client/stats.rb
CHANGED
@@ -1,73 +1,83 @@
|
|
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
|
12
|
+
# @option retry_timeout [Number] How long Octokit should keep trying to get stats (in seconds)
|
13
|
+
# @option retry_wait [Number] How long Octokit should wait between retries.
|
12
14
|
# @return [Array<Sawyer::Resource>] Array of contributor stats
|
13
|
-
# @see https://developer.github.com/v3/repos/statistics/#contributors
|
15
|
+
# @see https://developer.github.com/v3/repos/statistics/#get-contributors-list-with-additions-deletions-and-commit-counts
|
14
16
|
# @example Get contributor stats for octokit
|
15
17
|
# @client.contributors_stats('octokit/octokit.rb')
|
16
18
|
def contributors_stats(repo, options = {})
|
17
|
-
get_stats(repo,
|
19
|
+
get_stats(repo, 'contributors', options)
|
18
20
|
end
|
19
|
-
alias
|
21
|
+
alias contributor_stats contributors_stats
|
20
22
|
|
21
23
|
# Get the last year of commit activity data
|
22
24
|
#
|
23
25
|
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
26
|
+
# @option retry_timeout [Number] How long Octokit should keep trying to get stats (in seconds)
|
27
|
+
# @option retry_wait [Number] How long Octokit should wait between retries.
|
24
28
|
# @return [Array<Sawyer::Resource>] The last year of commit activity grouped by
|
25
29
|
# week. The days array is a group of commits per day, starting on Sunday.
|
26
|
-
# @see https://developer.github.com/v3/repos/statistics/#commit-activity
|
30
|
+
# @see https://developer.github.com/v3/repos/statistics/#get-the-last-year-of-commit-activity-data
|
27
31
|
# @example Get commit activity for octokit
|
28
32
|
# @client.commit_activity_stats('octokit/octokit.rb')
|
29
33
|
def commit_activity_stats(repo, options = {})
|
30
|
-
get_stats(repo,
|
34
|
+
get_stats(repo, 'commit_activity', options)
|
31
35
|
end
|
32
36
|
|
33
37
|
# Get the number of additions and deletions per week
|
34
38
|
#
|
35
39
|
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
40
|
+
# @option retry_timeout [Number] How long Octokit should keep trying to get stats (in seconds)
|
41
|
+
# @option retry_wait [Number] How long Octokit should wait between retries.
|
36
42
|
# @return [Array<Sawyer::Resource>] Weekly aggregate of the number of additions
|
37
43
|
# and deletions pushed to a repository.
|
38
|
-
# @see https://developer.github.com/v3/repos/statistics/#
|
44
|
+
# @see https://developer.github.com/v3/repos/statistics/#get-the-number-of-additions-and-deletions-per-week
|
39
45
|
# @example Get code frequency stats for octokit
|
40
46
|
# @client.code_frequency_stats('octokit/octokit.rb')
|
41
47
|
def code_frequency_stats(repo, options = {})
|
42
|
-
get_stats(repo,
|
48
|
+
get_stats(repo, 'code_frequency', options)
|
43
49
|
end
|
44
50
|
|
45
51
|
# Get the weekly commit count for the repo owner and everyone else
|
46
52
|
#
|
47
53
|
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
54
|
+
# @option retry_timeout [Number] How long Octokit should keep trying to get stats (in seconds)
|
55
|
+
# @option retry_wait [Number] How long Octokit should wait between retries.
|
48
56
|
# @return [Sawyer::Resource] Total commit counts for the owner and total commit
|
49
57
|
# counts in all. all is everyone combined, including the owner in the last
|
50
58
|
# 52 weeks. If you’d like to get the commit counts for non-owners, you can
|
51
59
|
# subtract all from owner.
|
52
|
-
# @see https://developer.github.com/v3/repos/statistics/#
|
60
|
+
# @see https://developer.github.com/v3/repos/statistics/#get-the-weekly-commit-count-for-the-repository-owner-and-everyone-else
|
53
61
|
# @example Get weekly commit counts for octokit
|
54
62
|
# @client.participation_stats("octokit/octokit.rb")
|
55
63
|
def participation_stats(repo, options = {})
|
56
|
-
get_stats(repo,
|
64
|
+
get_stats(repo, 'participation', options)
|
57
65
|
end
|
58
66
|
|
59
67
|
# Get the number of commits per hour in each day
|
60
68
|
#
|
61
69
|
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
70
|
+
# @option retry_timeout [Number] How long Octokit should keep trying to get stats (in seconds)
|
71
|
+
# @option retry_wait [Number] How long Octokit should wait between retries.
|
62
72
|
# @return [Array<Array>] Arrays containing the day number, hour number, and
|
63
73
|
# number of commits
|
64
|
-
# @see https://developer.github.com/v3/repos/statistics/#
|
74
|
+
# @see https://developer.github.com/v3/repos/statistics/#get-the-number-of-commits-per-hour-in-each-day
|
65
75
|
# @example Get octokit punch card
|
66
76
|
# @octokit.punch_card_stats
|
67
77
|
def punch_card_stats(repo, options = {})
|
68
|
-
get_stats(repo,
|
78
|
+
get_stats(repo, 'punch_card', options)
|
69
79
|
end
|
70
|
-
alias
|
80
|
+
alias punch_card punch_card_stats
|
71
81
|
|
72
82
|
private
|
73
83
|
|
@@ -75,11 +85,23 @@ module Octokit
|
|
75
85
|
#
|
76
86
|
# @param repo [Integer, String, Hash, Repository] A GitHub repository
|
77
87
|
# @param metric [String] The metrics you are looking for
|
78
|
-
# @return [Array<Sawyer::Resource>]
|
88
|
+
# @return [Array<Sawyer::Resource> or nil] Stats in metric-specific format, or nil if not yet calculated.
|
89
|
+
# @see https://developer.github.com/v3/repos/statistics/
|
79
90
|
def get_stats(repo, metric, options = {})
|
80
|
-
|
91
|
+
options = options.dup
|
92
|
+
if retry_timeout = options.delete(:retry_timeout)
|
93
|
+
retry_wait = options.delete(:retry_wait) || 0.5
|
94
|
+
timeout = Time.now + retry_timeout
|
95
|
+
end
|
96
|
+
loop do
|
97
|
+
data = get("#{Repository.path repo}/stats/#{metric}", options)
|
98
|
+
return data if last_response.status == 200
|
99
|
+
return [] if last_response.status == 204
|
100
|
+
return nil unless retry_timeout
|
101
|
+
return nil if Time.now >= timeout
|
81
102
|
|
82
|
-
|
103
|
+
sleep retry_wait if retry_wait
|
104
|
+
end
|
83
105
|
end
|
84
106
|
end
|
85
107
|
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
|
-
|
16
|
+
paginate "#{Repository.path repo}/statuses/#{sha}", options
|
17
17
|
end
|
18
|
-
alias
|
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
|
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
|
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
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Octokit
|
4
|
+
class Client
|
5
|
+
# Methods for the Traffic API
|
6
|
+
#
|
7
|
+
# @see https://developer.github.com/v3/repos/traffic/
|
8
|
+
module Traffic
|
9
|
+
# Get the top 10 referrers over the last 14 days
|
10
|
+
#
|
11
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
12
|
+
# @return [Array<Sawyer::Resource>] List of referrers and stats
|
13
|
+
# @see https://developer.github.com/v3/repos/traffic/#list-referrers
|
14
|
+
# @example
|
15
|
+
# @client.top_referrers('octokit/octokit.rb')
|
16
|
+
def top_referrers(repo, options = {})
|
17
|
+
get "#{Repository.path repo}/traffic/popular/referrers", options
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get the top 10 popular contents over the last 14 days
|
21
|
+
#
|
22
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub repository
|
23
|
+
# @return [Array<Sawyer::Resource>] List of popular contents
|
24
|
+
# @see https://developer.github.com/v3/repos/traffic/#list-paths
|
25
|
+
# @example
|
26
|
+
# @client.top_paths('octokit/octokit.rb')
|
27
|
+
def top_paths(repo, options = {})
|
28
|
+
get "#{Repository.path repo}/traffic/popular/paths", options
|
29
|
+
end
|
30
|
+
|
31
|
+
# Get the total number of views and breakdown per day or week for the
|
32
|
+
# last 14 days
|
33
|
+
#
|
34
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub Repository
|
35
|
+
# @option options [String] :per ('day') Views per. <tt>day</tt> or
|
36
|
+
# <tt>week</tt>
|
37
|
+
# @return [Sawyer::Resource] Breakdown of view stats
|
38
|
+
# @see https://developer.github.com/v3/repos/traffic/#views
|
39
|
+
# @example Views per day
|
40
|
+
# @client.views('octokit/octokit.rb')
|
41
|
+
# @example Views per week
|
42
|
+
# @client.views('octokit/octokit.rb', per: 'week')
|
43
|
+
def views(repo, options = {})
|
44
|
+
get "#{Repository.path repo}/traffic/views", options
|
45
|
+
end
|
46
|
+
|
47
|
+
# Get the total number of clones and breakdown per day or week for the
|
48
|
+
# last 14 days
|
49
|
+
#
|
50
|
+
# @param repo [Integer, String, Repository, Hash] A GitHub Repository
|
51
|
+
# @option options [String] :per ('day') Views per. <tt>day</tt> or
|
52
|
+
# <tt>week</tt>
|
53
|
+
# @return [Sawyer::Resource] Breakdown of clone stats
|
54
|
+
# @see https://developer.github.com/v3/repos/traffic/#clones
|
55
|
+
# @example Clones per day
|
56
|
+
# @client.clones('octokit/octokit.rb')
|
57
|
+
# @example Clones per week
|
58
|
+
# @client.clones('octokit/octokit.rb', per: 'week')
|
59
|
+
def clones(repo, options = {})
|
60
|
+
get "#{Repository.path repo}/traffic/clones", options
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|