lingfennan-github_api 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +20 -0
- data/README.md +741 -0
- data/lib/github_api.rb +93 -0
- data/lib/github_api/api.rb +398 -0
- data/lib/github_api/api/actions.rb +60 -0
- data/lib/github_api/api/arguments.rb +253 -0
- data/lib/github_api/api/config.rb +105 -0
- data/lib/github_api/api/config/property.rb +30 -0
- data/lib/github_api/api/config/property_set.rb +120 -0
- data/lib/github_api/api/factory.rb +33 -0
- data/lib/github_api/authorization.rb +75 -0
- data/lib/github_api/client.rb +77 -0
- data/lib/github_api/client/activity.rb +31 -0
- data/lib/github_api/client/activity/events.rb +233 -0
- data/lib/github_api/client/activity/feeds.rb +50 -0
- data/lib/github_api/client/activity/notifications.rb +181 -0
- data/lib/github_api/client/activity/starring.rb +130 -0
- data/lib/github_api/client/activity/watching.rb +176 -0
- data/lib/github_api/client/authorizations.rb +142 -0
- data/lib/github_api/client/authorizations/app.rb +98 -0
- data/lib/github_api/client/emojis.rb +19 -0
- data/lib/github_api/client/gists.rb +289 -0
- data/lib/github_api/client/gists/comments.rb +100 -0
- data/lib/github_api/client/git_data.rb +31 -0
- data/lib/github_api/client/git_data/blobs.rb +51 -0
- data/lib/github_api/client/git_data/commits.rb +101 -0
- data/lib/github_api/client/git_data/references.rb +150 -0
- data/lib/github_api/client/git_data/tags.rb +95 -0
- data/lib/github_api/client/git_data/trees.rb +113 -0
- data/lib/github_api/client/gitignore.rb +57 -0
- data/lib/github_api/client/issues.rb +248 -0
- data/lib/github_api/client/issues/assignees.rb +77 -0
- data/lib/github_api/client/issues/comments.rb +146 -0
- data/lib/github_api/client/issues/events.rb +50 -0
- data/lib/github_api/client/issues/labels.rb +189 -0
- data/lib/github_api/client/issues/milestones.rb +146 -0
- data/lib/github_api/client/markdown.rb +62 -0
- data/lib/github_api/client/meta.rb +19 -0
- data/lib/github_api/client/orgs.rb +127 -0
- data/lib/github_api/client/orgs/hooks.rb +182 -0
- data/lib/github_api/client/orgs/members.rb +142 -0
- data/lib/github_api/client/orgs/memberships.rb +131 -0
- data/lib/github_api/client/orgs/projects.rb +57 -0
- data/lib/github_api/client/orgs/teams.rb +407 -0
- data/lib/github_api/client/projects.rb +83 -0
- data/lib/github_api/client/projects/cards.rb +158 -0
- data/lib/github_api/client/projects/columns.rb +146 -0
- data/lib/github_api/client/pull_requests.rb +195 -0
- data/lib/github_api/client/pull_requests/comments.rb +140 -0
- data/lib/github_api/client/pull_requests/reviews.rb +158 -0
- data/lib/github_api/client/repos.rb +468 -0
- data/lib/github_api/client/repos/branches.rb +48 -0
- data/lib/github_api/client/repos/branches/protections.rb +75 -0
- data/lib/github_api/client/repos/collaborators.rb +84 -0
- data/lib/github_api/client/repos/comments.rb +125 -0
- data/lib/github_api/client/repos/commits.rb +80 -0
- data/lib/github_api/client/repos/contents.rb +246 -0
- data/lib/github_api/client/repos/deployments.rb +138 -0
- data/lib/github_api/client/repos/downloads.rb +62 -0
- data/lib/github_api/client/repos/forks.rb +48 -0
- data/lib/github_api/client/repos/hooks.rb +214 -0
- data/lib/github_api/client/repos/keys.rb +104 -0
- data/lib/github_api/client/repos/merging.rb +47 -0
- data/lib/github_api/client/repos/pages.rb +48 -0
- data/lib/github_api/client/repos/projects.rb +62 -0
- data/lib/github_api/client/repos/pub_sub_hubbub.rb +133 -0
- data/lib/github_api/client/repos/releases.rb +189 -0
- data/lib/github_api/client/repos/releases/assets.rb +136 -0
- data/lib/github_api/client/repos/releases/tags.rb +24 -0
- data/lib/github_api/client/repos/statistics.rb +89 -0
- data/lib/github_api/client/repos/statuses.rb +91 -0
- data/lib/github_api/client/say.rb +25 -0
- data/lib/github_api/client/scopes.rb +46 -0
- data/lib/github_api/client/search.rb +133 -0
- data/lib/github_api/client/search/legacy.rb +111 -0
- data/lib/github_api/client/users.rb +117 -0
- data/lib/github_api/client/users/emails.rb +65 -0
- data/lib/github_api/client/users/followers.rb +115 -0
- data/lib/github_api/client/users/keys.rb +104 -0
- data/lib/github_api/configuration.rb +70 -0
- data/lib/github_api/connection.rb +82 -0
- data/lib/github_api/constants.rb +61 -0
- data/lib/github_api/core_ext/array.rb +25 -0
- data/lib/github_api/core_ext/hash.rb +91 -0
- data/lib/github_api/core_ext/ordered_hash.rb +107 -0
- data/lib/github_api/deprecation.rb +39 -0
- data/lib/github_api/error.rb +32 -0
- data/lib/github_api/error/client_error.rb +89 -0
- data/lib/github_api/error/service_error.rb +223 -0
- data/lib/github_api/ext/faraday.rb +38 -0
- data/lib/github_api/mash.rb +7 -0
- data/lib/github_api/middleware.rb +37 -0
- data/lib/github_api/mime_type.rb +33 -0
- data/lib/github_api/normalizer.rb +23 -0
- data/lib/github_api/null_encoder.rb +25 -0
- data/lib/github_api/page_iterator.rb +138 -0
- data/lib/github_api/page_links.rb +63 -0
- data/lib/github_api/paged_request.rb +42 -0
- data/lib/github_api/pagination.rb +115 -0
- data/lib/github_api/parameter_filter.rb +35 -0
- data/lib/github_api/params_hash.rb +115 -0
- data/lib/github_api/rate_limit.rb +25 -0
- data/lib/github_api/request.rb +85 -0
- data/lib/github_api/request/basic_auth.rb +36 -0
- data/lib/github_api/request/jsonize.rb +54 -0
- data/lib/github_api/request/oauth2.rb +44 -0
- data/lib/github_api/request/verbs.rb +63 -0
- data/lib/github_api/response.rb +48 -0
- data/lib/github_api/response/atom_parser.rb +22 -0
- data/lib/github_api/response/follow_redirects.rb +140 -0
- data/lib/github_api/response/header.rb +87 -0
- data/lib/github_api/response/jsonize.rb +28 -0
- data/lib/github_api/response/mashify.rb +24 -0
- data/lib/github_api/response/raise_error.rb +22 -0
- data/lib/github_api/response/xmlize.rb +27 -0
- data/lib/github_api/response_wrapper.rb +161 -0
- data/lib/github_api/ssl_certs/cacerts.pem +2183 -0
- data/lib/github_api/utils/url.rb +63 -0
- data/lib/github_api/validations.rb +22 -0
- data/lib/github_api/validations/format.rb +26 -0
- data/lib/github_api/validations/presence.rb +32 -0
- data/lib/github_api/validations/required.rb +21 -0
- data/lib/github_api/validations/token.rb +41 -0
- data/lib/github_api/version.rb +5 -0
- metadata +338 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
class Client::Repos::Branches < API
|
7
|
+
require_all 'github_api/client/repos/branches', 'protections'
|
8
|
+
|
9
|
+
# Access to Repos::Branches::Protections API
|
10
|
+
namespace :protections
|
11
|
+
|
12
|
+
# List branches
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# github = Github.new
|
16
|
+
# github.repos.branches.list 'user-name', 'repo-name'
|
17
|
+
# github.repos(user: 'user-name', repo: 'repo-name').branches.list
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# repos = Github::Repos.new
|
21
|
+
# repos.branches.list 'user-name', 'repo-name'
|
22
|
+
#
|
23
|
+
# @api public
|
24
|
+
def list(*args)
|
25
|
+
arguments(args, required: [:user, :repo])
|
26
|
+
|
27
|
+
response = get_request("/repos/#{arguments.user}/#{arguments.repo}/branches", arguments.params)
|
28
|
+
return response unless block_given?
|
29
|
+
response.each { |el| yield el }
|
30
|
+
end
|
31
|
+
alias :all :list
|
32
|
+
|
33
|
+
# Get branch
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
# github = Github.new
|
37
|
+
# github.repos.branches.get 'user-name', 'repo-name', 'branch-name'
|
38
|
+
# github.repos.branches.get user: 'user-name', repo: 'repo-name', branch: 'branch-name'
|
39
|
+
# github.repos(user: 'user-name', repo: 'repo-name', branch: 'branch-name').branches.get
|
40
|
+
# @api public
|
41
|
+
def get(*args)
|
42
|
+
arguments(args, required: [:user, :repo, :branch])
|
43
|
+
|
44
|
+
get_request("/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}", arguments.params)
|
45
|
+
end
|
46
|
+
alias :find :get
|
47
|
+
end # Client::Repos::Branches
|
48
|
+
end # Github
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../../../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
# The Branch Protections API
|
7
|
+
class Client::Repos::Branches::Protections < API
|
8
|
+
VALID_PROTECTION_PARAM_NAMES = %w[
|
9
|
+
required_status_checks
|
10
|
+
required_pull_request_reviews
|
11
|
+
enforce_admins
|
12
|
+
restrictions
|
13
|
+
accept
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
# Get a single branch's protection
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# github = Github.new
|
20
|
+
# github.repos.branches.protections.get 'user', 'repo', 'branch'
|
21
|
+
#
|
22
|
+
# @api public
|
23
|
+
def get(*args)
|
24
|
+
arguments(args, required: [:user, :repo, :branch])
|
25
|
+
|
26
|
+
get_request("/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}/protection", arguments.params)
|
27
|
+
end
|
28
|
+
alias :find :get
|
29
|
+
|
30
|
+
# Edit a branch protection
|
31
|
+
#
|
32
|
+
# Users with push access to the repository can edit a branch protection.
|
33
|
+
#
|
34
|
+
# @param [Hash] params
|
35
|
+
# @input params [String] :required_status_checks
|
36
|
+
# Required.
|
37
|
+
# @input params [String] :enforce_admins
|
38
|
+
# Required.
|
39
|
+
# @input params [String] :restrictions
|
40
|
+
# Required.
|
41
|
+
# @input params [String] :required_pull_request_reviews
|
42
|
+
# Required.
|
43
|
+
# Look to the branch protection API t see how to use these
|
44
|
+
# https://developer.github.com/v3/repos/branches/#update-branch-protection
|
45
|
+
#
|
46
|
+
# @example
|
47
|
+
# github = Github.new
|
48
|
+
# github.repos.branches.protections.edit 'user', 'repo', 'branch',
|
49
|
+
# required_pull_request_reviews: {dismiss_stale_reviews: false}
|
50
|
+
#
|
51
|
+
# @api public
|
52
|
+
def edit(*args)
|
53
|
+
arguments(args, required: [:user, :repo, :branch]) do
|
54
|
+
permit VALID_PROTECTION_PARAM_NAMES
|
55
|
+
end
|
56
|
+
|
57
|
+
put_request("/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}/protection", arguments.params)
|
58
|
+
end
|
59
|
+
alias :update :edit
|
60
|
+
|
61
|
+
# Delete a branch protection
|
62
|
+
#
|
63
|
+
# @example
|
64
|
+
# github = Github.new
|
65
|
+
# github.repos.branches.protections.delete 'user', 'repo', 'branch'
|
66
|
+
#
|
67
|
+
# @api public
|
68
|
+
def delete(*args)
|
69
|
+
arguments(args, required: [:user, :repo, :branch])
|
70
|
+
|
71
|
+
delete_request("/repos/#{arguments.user}/#{arguments.repo}/branches/#{arguments.branch}/protection", arguments.params)
|
72
|
+
end
|
73
|
+
alias :remove :delete
|
74
|
+
end # Client::Repos::Branches::Protections
|
75
|
+
end # Github
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
class Client::Repos::Collaborators < API
|
7
|
+
# List collaborators
|
8
|
+
#
|
9
|
+
# When authenticating as an organization owner of an
|
10
|
+
# organization-owned repository, all organization owners are included
|
11
|
+
# in the list of collaborators. Otherwise, only users with access to the
|
12
|
+
# repository are returned in the collaborators list.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# github = Github.new
|
16
|
+
# github.repos.collaborators.list 'user-name', 'repo-name'
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# github.repos.collaborators.list 'user-name', 'repo-name' { |cbr| .. }
|
20
|
+
#
|
21
|
+
# @return [Array]
|
22
|
+
#
|
23
|
+
# @api public
|
24
|
+
def list(*args)
|
25
|
+
arguments(args, required: [:user, :repo])
|
26
|
+
|
27
|
+
response = get_request("/repos/#{arguments.user}/#{arguments.repo}/collaborators", arguments.params)
|
28
|
+
return response unless block_given?
|
29
|
+
response.each { |el| yield el }
|
30
|
+
end
|
31
|
+
alias :all :list
|
32
|
+
|
33
|
+
# Add collaborator
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
# github = Github.new
|
37
|
+
# github.repos.collaborators.add 'user', 'repo', 'username'
|
38
|
+
#
|
39
|
+
# @example
|
40
|
+
# collaborators = Github::Repos::Collaborators.new
|
41
|
+
# collaborators.add 'user', 'repo', 'username'
|
42
|
+
#
|
43
|
+
# @api public
|
44
|
+
def add(*args)
|
45
|
+
arguments(args, required: [:user, :repo, :username])
|
46
|
+
|
47
|
+
put_request("/repos/#{arguments.user}/#{arguments.repo}/collaborators/#{arguments.username}", arguments.params)
|
48
|
+
end
|
49
|
+
alias :<< :add
|
50
|
+
|
51
|
+
# Checks if user is a collaborator for a given repository
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# github = Github.new
|
55
|
+
# github.repos.collaborators.collaborator?('user', 'repo', 'username')
|
56
|
+
#
|
57
|
+
# @example
|
58
|
+
# github = Github.new user: 'user-name', repo: 'repo-name'
|
59
|
+
# github.collaborators.collaborator? username: 'collaborator'
|
60
|
+
#
|
61
|
+
# @api public
|
62
|
+
def collaborator?(*args)
|
63
|
+
arguments(args, required: [:user, :repo, :username])
|
64
|
+
|
65
|
+
get_request("/repos/#{arguments.user}/#{arguments.repo}/collaborators/#{arguments.username}", arguments.params)
|
66
|
+
true
|
67
|
+
rescue Github::Error::NotFound
|
68
|
+
false
|
69
|
+
end
|
70
|
+
|
71
|
+
# Removes collaborator
|
72
|
+
#
|
73
|
+
# @example
|
74
|
+
# github = Github.new
|
75
|
+
# github.repos.collaborators.remove 'user', 'repo', 'username'
|
76
|
+
#
|
77
|
+
# @api public
|
78
|
+
def remove(*args)
|
79
|
+
arguments(args, required: [:user, :repo, :username])
|
80
|
+
|
81
|
+
delete_request("/repos/#{arguments.user}/#{arguments.repo}/collaborators/#{arguments.username}", arguments.params)
|
82
|
+
end
|
83
|
+
end # Client::Repos::Collaborators
|
84
|
+
end # Github
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
class Client::Repos::Comments < API
|
7
|
+
|
8
|
+
REQUIRED_COMMENT_OPTIONS = %w[ body ].freeze
|
9
|
+
|
10
|
+
VALID_COMMENT_OPTIONS = %w[
|
11
|
+
body
|
12
|
+
line
|
13
|
+
path
|
14
|
+
position
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
# List commit comments for a repository
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# github = Github.new
|
21
|
+
# github.repos.comments.list 'user-name', 'repo-name'
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
# github.repos.comments.list 'user-name', 'repo-name' { |com| ... }
|
25
|
+
#
|
26
|
+
# List comments for a single commit
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# github.repos.comments.list 'user-name', 'repo-name',
|
30
|
+
# sha: '6dcb09b5b57875f334f61aebed695e2e4193db5e'
|
31
|
+
#
|
32
|
+
# @api public
|
33
|
+
def list(*args)
|
34
|
+
arguments(args, required: [:user, :repo])
|
35
|
+
params = arguments.params
|
36
|
+
user = arguments.user
|
37
|
+
repo = arguments.repo
|
38
|
+
|
39
|
+
response = if (sha = params.delete('sha'))
|
40
|
+
get_request("/repos/#{user}/#{repo}/commits/#{sha}/comments", params)
|
41
|
+
else
|
42
|
+
get_request("/repos/#{user}/#{repo}/comments", params)
|
43
|
+
end
|
44
|
+
return response unless block_given?
|
45
|
+
response.each { |el| yield el }
|
46
|
+
end
|
47
|
+
alias :all :list
|
48
|
+
|
49
|
+
# Gets a single commit comment
|
50
|
+
#
|
51
|
+
# @example
|
52
|
+
# github = Github.new
|
53
|
+
# github.repos.comments.get 'user-name', 'repo-name', 'id'
|
54
|
+
#
|
55
|
+
# @api public
|
56
|
+
def get(*args)
|
57
|
+
arguments(args, required: [:user, :repo, :id])
|
58
|
+
|
59
|
+
get_request("/repos/#{arguments.user}/#{arguments.repo}/comments/#{arguments.id}", arguments.params)
|
60
|
+
end
|
61
|
+
alias :find :get
|
62
|
+
|
63
|
+
# Creates a commit comment
|
64
|
+
#
|
65
|
+
# @param [Hash] params
|
66
|
+
# @option params [String] :body
|
67
|
+
# Required. The contents of the comment.
|
68
|
+
# @option params [String] :path
|
69
|
+
# Required. Relative path of the file to comment on.
|
70
|
+
# @option params [Number] :position
|
71
|
+
# Required number - Line index in the diff to comment on.
|
72
|
+
# @option params [Number] :line
|
73
|
+
# Required number - Line number in the file to comment on.
|
74
|
+
#
|
75
|
+
# @example
|
76
|
+
# github = Github.new
|
77
|
+
# github.repos.comments.create 'user-name', 'repo-name', 'sha-key',
|
78
|
+
# body: "Nice change",
|
79
|
+
# position: 4,
|
80
|
+
# line: 1,
|
81
|
+
# path: "file1.txt"
|
82
|
+
#
|
83
|
+
# @api public
|
84
|
+
def create(*args)
|
85
|
+
arguments(args, required: [:user, :repo, :sha]) do
|
86
|
+
assert_required REQUIRED_COMMENT_OPTIONS
|
87
|
+
end
|
88
|
+
|
89
|
+
post_request("/repos/#{arguments.user}/#{arguments.repo}/commits/#{arguments.sha}/comments", arguments.params)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Update a commit comment
|
93
|
+
#
|
94
|
+
# @param [Hash] params
|
95
|
+
# @option params [String] :body
|
96
|
+
# Required. The contents of the comment.
|
97
|
+
#
|
98
|
+
# @example
|
99
|
+
# github = Github.new
|
100
|
+
# github.repos.comments.update 'user-name', 'repo-name', 'id',
|
101
|
+
# body: "Nice change"
|
102
|
+
#
|
103
|
+
# @api public
|
104
|
+
def update(*args)
|
105
|
+
arguments(args, required: [:user, :repo, :id]) do
|
106
|
+
assert_required REQUIRED_COMMENT_OPTIONS
|
107
|
+
end
|
108
|
+
|
109
|
+
patch_request("/repos/#{arguments.user}/#{arguments.repo}/comments/#{arguments.id}", arguments.params)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Deletes a commit comment
|
113
|
+
#
|
114
|
+
# @example
|
115
|
+
# github = Github.new
|
116
|
+
# github.repos.comments.delete 'user-name', 'repo-name', 'id'
|
117
|
+
#
|
118
|
+
# @api public
|
119
|
+
def delete(*args)
|
120
|
+
arguments(args, required: [:user, :repo, :id])
|
121
|
+
|
122
|
+
delete_request("/repos/#{arguments.user}/#{arguments.repo}/comments/#{arguments.id}", arguments.params)
|
123
|
+
end
|
124
|
+
end # Client::Repos::Comments
|
125
|
+
end # Github
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
class Client::Repos::Commits < API
|
7
|
+
|
8
|
+
VALID_COMMITS_OPTIONS = %w[
|
9
|
+
sha
|
10
|
+
path
|
11
|
+
author
|
12
|
+
since
|
13
|
+
until
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
# List commits on a repository
|
17
|
+
#
|
18
|
+
# @param [Hash] params
|
19
|
+
# @option params [String] :sha
|
20
|
+
# Sha or branch to start listing commits from.
|
21
|
+
# @option params [String] :path
|
22
|
+
# Only commits containing this file path will be returned.
|
23
|
+
# @option params [String] :author
|
24
|
+
# GitHub login, name or email by which to filter by commit author.
|
25
|
+
# @option params [String] :since
|
26
|
+
# Only commits after this date will be returned. This is a timestamp
|
27
|
+
# in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
|
28
|
+
# @option params [String] :until
|
29
|
+
# Only commits before this date will be returned. This is a timestamp
|
30
|
+
# in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
|
31
|
+
#
|
32
|
+
# @example
|
33
|
+
# github = Github.new
|
34
|
+
# github.repos.commits.list 'user-name', 'repo-name', sha: '...'
|
35
|
+
# github.repos.commits.list 'user-name', 'repo-name', sha: '...' { |commit| ... }
|
36
|
+
#
|
37
|
+
# @api public
|
38
|
+
def list(*args)
|
39
|
+
arguments(args, required: [:user, :repo]) do
|
40
|
+
permit VALID_COMMITS_OPTIONS
|
41
|
+
end
|
42
|
+
|
43
|
+
response = get_request("/repos/#{arguments.user}/#{arguments.repo}/commits", arguments.params)
|
44
|
+
return response unless block_given?
|
45
|
+
response.each { |el| yield el }
|
46
|
+
end
|
47
|
+
alias :all :list
|
48
|
+
|
49
|
+
# Gets a single commit
|
50
|
+
#
|
51
|
+
# @example
|
52
|
+
# github = Github.new
|
53
|
+
# github.repos.commits.get 'user-name', 'repo-name', '6dcb09b5b57875f334f61aebed6'
|
54
|
+
#
|
55
|
+
# @api public
|
56
|
+
def get(*args)
|
57
|
+
arguments(args, required: [:user, :repo, :sha])
|
58
|
+
|
59
|
+
get_request("/repos/#{arguments.user}/#{arguments.repo}/commits/#{arguments.sha}", arguments.params)
|
60
|
+
end
|
61
|
+
alias :find :get
|
62
|
+
|
63
|
+
# Compares two commits
|
64
|
+
#
|
65
|
+
# @note Both :base and :head can be either branch names in :repo or
|
66
|
+
# branch names in other repositories in the same network as :repo.
|
67
|
+
# For the latter case, use the format user:branch:
|
68
|
+
#
|
69
|
+
# @example
|
70
|
+
# github = Github.new
|
71
|
+
# github.repos.commits.compare 'user-name', 'repo-name', 'v0.4.8', 'master'
|
72
|
+
#
|
73
|
+
# @api public
|
74
|
+
def compare(*args)
|
75
|
+
arguments(args, required: [:user, :repo, :base, :head])
|
76
|
+
|
77
|
+
get_request("/repos/#{arguments.user}/#{arguments.repo}/compare/#{arguments.base}...#{arguments.head}", arguments.params)
|
78
|
+
end
|
79
|
+
end # Client::Repos::Commits
|
80
|
+
end # Github
|
@@ -0,0 +1,246 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../../api'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
# These API methods let you retrieve the contents of files within a repository
|
7
|
+
# as Base64 encoded content.
|
8
|
+
class Client::Repos::Contents < API
|
9
|
+
|
10
|
+
REQUIRED_CONTENT_OPTIONS = %w[ path message content ]
|
11
|
+
|
12
|
+
# Get the README
|
13
|
+
#
|
14
|
+
# This method returns the preferred README for a repository.
|
15
|
+
#
|
16
|
+
# @param [Hash] params
|
17
|
+
# @option params [String] :ref
|
18
|
+
# The name of the commit/branch/tag.
|
19
|
+
# Default: the repository’s default branch (usually master)
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# github = Github.new
|
23
|
+
# github.repos.contents.readme 'user-name', 'repo-name'
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# content = Github::Client::Repos::Contents.new user: 'user-name', repo: 'repo-name'
|
27
|
+
# content.readme
|
28
|
+
#
|
29
|
+
# @api public
|
30
|
+
def readme(*args)
|
31
|
+
arguments(args, required: [:user, :repo])
|
32
|
+
|
33
|
+
get_request("/repos/#{arguments.user}/#{arguments.repo}/readme", arguments.params)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Get contents
|
37
|
+
#
|
38
|
+
# This method returns the contents of any file or directory in a repository.
|
39
|
+
#
|
40
|
+
# @param [Hash] params
|
41
|
+
# @option params [String] :path
|
42
|
+
# The content path.
|
43
|
+
# @option params [String] :ref
|
44
|
+
# The name of the commit/branch/tag.
|
45
|
+
# Default: the repository’s default branch (usually master)
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# github = Github.new
|
49
|
+
# github.repos.contents.get 'user-name', 'repo-name', 'path'
|
50
|
+
#
|
51
|
+
# @example
|
52
|
+
# github = Github.new user: 'user-name', repo: 'repo-name'
|
53
|
+
# github.repos.contents.get path: 'README.md'
|
54
|
+
#
|
55
|
+
# @api public
|
56
|
+
def get(*args)
|
57
|
+
arguments(args, required: [:user, :repo, :path])
|
58
|
+
|
59
|
+
get_request("/repos/#{arguments.user}/#{arguments.repo}/contents/#{arguments.path}", arguments.params)
|
60
|
+
end
|
61
|
+
alias :find :get
|
62
|
+
|
63
|
+
# Create a file
|
64
|
+
#
|
65
|
+
# This method creates a new file in a repository
|
66
|
+
#
|
67
|
+
# @param [Hash] params
|
68
|
+
# @option params [String] :path
|
69
|
+
# Requried string. The content path
|
70
|
+
# @option params [String]
|
71
|
+
# @option params [String] :message
|
72
|
+
# Requried string. The commit message.
|
73
|
+
# @option params [String] :content
|
74
|
+
# Requried string. The new file content, which will be Base64 encoded
|
75
|
+
# @option params [String] :branch
|
76
|
+
# The branch name. If not provided, uses the repository’s
|
77
|
+
# default branch (usually master)
|
78
|
+
#
|
79
|
+
# Optional Parameters
|
80
|
+
#
|
81
|
+
# The :author section is optional and is filled in with the
|
82
|
+
# :committer information if omitted. If the :committer
|
83
|
+
# information is omitted, the authenticated user’s information is used.
|
84
|
+
#
|
85
|
+
# You must provide values for both :name and :email, whether
|
86
|
+
# you choose to use :author or :committer. Otherwise, you’ll
|
87
|
+
# receive a 500 status code.
|
88
|
+
#
|
89
|
+
# Both the author and commiter parameters have the same keys:
|
90
|
+
#
|
91
|
+
# @option params [String] :name
|
92
|
+
# The name of the author (or commiter) of the commit
|
93
|
+
# @option params [String] :email
|
94
|
+
# The email of the author (or commiter) of the commit
|
95
|
+
#
|
96
|
+
# @example
|
97
|
+
# github = Github.new
|
98
|
+
# github.repos.contents.create 'user-name', 'repo-name', 'path',
|
99
|
+
# path: 'hello.rb',
|
100
|
+
# content: "puts 'hello ruby'",
|
101
|
+
# message: "my commit message"
|
102
|
+
#
|
103
|
+
# @api public
|
104
|
+
def create(*args)
|
105
|
+
arguments(args, required: [:user, :repo, :path]) do
|
106
|
+
assert_required REQUIRED_CONTENT_OPTIONS
|
107
|
+
end
|
108
|
+
params = arguments.params
|
109
|
+
params.strict_encode64('content')
|
110
|
+
|
111
|
+
put_request("/repos/#{arguments.user}/#{arguments.repo}/contents/#{arguments.path}", params)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Update a file
|
115
|
+
#
|
116
|
+
# This method updates a file in a repository
|
117
|
+
#
|
118
|
+
# @param [Hash] params
|
119
|
+
# @option params [String] :path
|
120
|
+
# Requried string. The content path
|
121
|
+
# @option params [String]
|
122
|
+
# @option params [String] :message
|
123
|
+
# Requried string. The commit message.
|
124
|
+
# @option params [String] :content
|
125
|
+
# Requried string. The new file content, which will be Base64 encoded
|
126
|
+
# @option params [String] :sha
|
127
|
+
# Required string. The blob SHA of the file being replaced.
|
128
|
+
# @option params [String] :branch
|
129
|
+
# The branch name. If not provided, uses the repository’s
|
130
|
+
# default branch (usually master)
|
131
|
+
#
|
132
|
+
# Optional Parameters
|
133
|
+
#
|
134
|
+
# The :author section is optional and is filled in with the
|
135
|
+
# :committer information if omitted. If the :committer
|
136
|
+
# information is omitted, the authenticated user’s information is used.
|
137
|
+
#
|
138
|
+
# You must provide values for both :name and :email, whether
|
139
|
+
# you choose to use :author or :committer. Otherwise, you’ll
|
140
|
+
# receive a 500 status code.
|
141
|
+
#
|
142
|
+
# Both the author and commiter parameters have the same keys:
|
143
|
+
#
|
144
|
+
# @option params [String] :name
|
145
|
+
# The name of the author (or commiter) of the commit
|
146
|
+
# @option params [String] :email
|
147
|
+
# The email of the author (or commiter) of the commit
|
148
|
+
#
|
149
|
+
# @example
|
150
|
+
# github = Github.new
|
151
|
+
# github.repos.contents.update 'user-name', 'repo-name', 'path',
|
152
|
+
# path: 'hello.rb',
|
153
|
+
# content: "puts 'hello ruby again'",
|
154
|
+
# message: "my commit message",
|
155
|
+
# sha: "25b0bef9e404bd2e3233de26b7ef8cbd86d0e913"
|
156
|
+
#
|
157
|
+
# @api public
|
158
|
+
def update(*args)
|
159
|
+
create(*args)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Delete a file
|
163
|
+
#
|
164
|
+
# This method deletes a file in a repository
|
165
|
+
#
|
166
|
+
# @param [Hash] params
|
167
|
+
# @option params [String] :path
|
168
|
+
# Requried string. The content path
|
169
|
+
# @option params [String]
|
170
|
+
# @option params [String] :message
|
171
|
+
# Requried string. The commit message.
|
172
|
+
# @option params [String] :sha
|
173
|
+
# Required string. The blob SHA of the file being replaced.
|
174
|
+
# @option params [String] :branch
|
175
|
+
# The branch name. If not provided, uses the repository’s
|
176
|
+
# default branch (usually master)
|
177
|
+
#
|
178
|
+
# Optional Parameters
|
179
|
+
#
|
180
|
+
# The :author section is optional and is filled in with the
|
181
|
+
# :committer information if omitted. If the :committer
|
182
|
+
# information is omitted, the authenticated user’s information is used.
|
183
|
+
#
|
184
|
+
# You must provide values for both :name and :email, whether
|
185
|
+
# you choose to use :author or :committer. Otherwise, you’ll
|
186
|
+
# receive a 500 status code.
|
187
|
+
#
|
188
|
+
# Both the author and commiter parameters have the same keys:
|
189
|
+
#
|
190
|
+
# @option params [String] :name
|
191
|
+
# The name of the author (or commiter) of the commit
|
192
|
+
# @option params [String] :email
|
193
|
+
# The email of the author (or commiter) of the commit
|
194
|
+
#
|
195
|
+
# @example
|
196
|
+
# github = Github.new
|
197
|
+
# github.repos.contents.delete 'user-name', 'repo-name', 'path',
|
198
|
+
# path: 'hello.rb',
|
199
|
+
# message: "delete hello.rb file",
|
200
|
+
# sha: "329688480d39049927147c162b9d2deaf885005f"
|
201
|
+
#
|
202
|
+
def delete(*args)
|
203
|
+
arguments(args, required: [:user, :repo, :path]) do
|
204
|
+
assert_required %w[ path message sha ]
|
205
|
+
end
|
206
|
+
|
207
|
+
delete_request("/repos/#{arguments.user}/#{arguments.repo}/contents/#{arguments.path}", arguments.params)
|
208
|
+
end
|
209
|
+
|
210
|
+
# Get archive link
|
211
|
+
#
|
212
|
+
# This method will return a 302 to a URL to download a tarball or zipball
|
213
|
+
# archive for a repository. Please make sure your HTTP framework is configured
|
214
|
+
# to follow redirects or you will need to use the Location header to make
|
215
|
+
# a second GET request.
|
216
|
+
#
|
217
|
+
# @note
|
218
|
+
# For private repositories, these links are temporary and expire quickly.
|
219
|
+
#
|
220
|
+
# @param [Hash] params
|
221
|
+
# @input params [String] :archive_format
|
222
|
+
# Required string. Either tarball or zipball. Default: tarball
|
223
|
+
# @input params [String] :ref
|
224
|
+
# Optional string. A valid Git reference.
|
225
|
+
# Default: the repository’s default branch (usually master)
|
226
|
+
#
|
227
|
+
# @example
|
228
|
+
# github = Github.new
|
229
|
+
# github.repos.contents.archive 'user-name', 'repo-name',
|
230
|
+
# archive_format: "tarball",
|
231
|
+
# ref: "master"
|
232
|
+
#
|
233
|
+
# @api public
|
234
|
+
def archive(*args)
|
235
|
+
arguments(args, required: [:user, :repo])
|
236
|
+
params = arguments.params
|
237
|
+
archive_format = params.delete('archive_format') || 'tarball'
|
238
|
+
ref = params.delete('ref') || 'master'
|
239
|
+
|
240
|
+
disable_redirects do
|
241
|
+
response = get_request("/repos/#{arguments.user}/#{arguments.repo}/#{archive_format}/#{ref}", params)
|
242
|
+
response.headers.location
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end # Client::Repos::Contents
|
246
|
+
end # Github
|