github_api2 1.0.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.
Files changed (127) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +770 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +741 -0
  5. data/lib/github_api2/api/actions.rb +60 -0
  6. data/lib/github_api2/api/arguments.rb +253 -0
  7. data/lib/github_api2/api/config/property.rb +30 -0
  8. data/lib/github_api2/api/config/property_set.rb +120 -0
  9. data/lib/github_api2/api/config.rb +105 -0
  10. data/lib/github_api2/api/factory.rb +33 -0
  11. data/lib/github_api2/api.rb +398 -0
  12. data/lib/github_api2/authorization.rb +75 -0
  13. data/lib/github_api2/client/activity/events.rb +233 -0
  14. data/lib/github_api2/client/activity/feeds.rb +50 -0
  15. data/lib/github_api2/client/activity/notifications.rb +181 -0
  16. data/lib/github_api2/client/activity/starring.rb +130 -0
  17. data/lib/github_api2/client/activity/watching.rb +176 -0
  18. data/lib/github_api2/client/activity.rb +31 -0
  19. data/lib/github_api2/client/authorizations/app.rb +98 -0
  20. data/lib/github_api2/client/authorizations.rb +142 -0
  21. data/lib/github_api2/client/emojis.rb +19 -0
  22. data/lib/github_api2/client/gists/comments.rb +100 -0
  23. data/lib/github_api2/client/gists.rb +289 -0
  24. data/lib/github_api2/client/git_data/blobs.rb +51 -0
  25. data/lib/github_api2/client/git_data/commits.rb +101 -0
  26. data/lib/github_api2/client/git_data/references.rb +150 -0
  27. data/lib/github_api2/client/git_data/tags.rb +95 -0
  28. data/lib/github_api2/client/git_data/trees.rb +113 -0
  29. data/lib/github_api2/client/git_data.rb +31 -0
  30. data/lib/github_api2/client/gitignore.rb +57 -0
  31. data/lib/github_api2/client/issues/assignees.rb +77 -0
  32. data/lib/github_api2/client/issues/comments.rb +146 -0
  33. data/lib/github_api2/client/issues/events.rb +50 -0
  34. data/lib/github_api2/client/issues/labels.rb +189 -0
  35. data/lib/github_api2/client/issues/milestones.rb +146 -0
  36. data/lib/github_api2/client/issues.rb +248 -0
  37. data/lib/github_api2/client/markdown.rb +62 -0
  38. data/lib/github_api2/client/meta.rb +19 -0
  39. data/lib/github_api2/client/orgs/hooks.rb +182 -0
  40. data/lib/github_api2/client/orgs/members.rb +142 -0
  41. data/lib/github_api2/client/orgs/memberships.rb +131 -0
  42. data/lib/github_api2/client/orgs/projects.rb +57 -0
  43. data/lib/github_api2/client/orgs/teams.rb +407 -0
  44. data/lib/github_api2/client/orgs.rb +127 -0
  45. data/lib/github_api2/client/projects/cards.rb +158 -0
  46. data/lib/github_api2/client/projects/columns.rb +146 -0
  47. data/lib/github_api2/client/projects.rb +83 -0
  48. data/lib/github_api2/client/pull_requests/comments.rb +140 -0
  49. data/lib/github_api2/client/pull_requests/reviews.rb +158 -0
  50. data/lib/github_api2/client/pull_requests.rb +195 -0
  51. data/lib/github_api2/client/repos/branches/protections.rb +75 -0
  52. data/lib/github_api2/client/repos/branches.rb +48 -0
  53. data/lib/github_api2/client/repos/collaborators.rb +84 -0
  54. data/lib/github_api2/client/repos/comments.rb +125 -0
  55. data/lib/github_api2/client/repos/commits.rb +80 -0
  56. data/lib/github_api2/client/repos/contents.rb +263 -0
  57. data/lib/github_api2/client/repos/deployments.rb +138 -0
  58. data/lib/github_api2/client/repos/downloads.rb +62 -0
  59. data/lib/github_api2/client/repos/forks.rb +50 -0
  60. data/lib/github_api2/client/repos/hooks.rb +214 -0
  61. data/lib/github_api2/client/repos/invitations.rb +41 -0
  62. data/lib/github_api2/client/repos/keys.rb +104 -0
  63. data/lib/github_api2/client/repos/merging.rb +47 -0
  64. data/lib/github_api2/client/repos/pages.rb +48 -0
  65. data/lib/github_api2/client/repos/projects.rb +62 -0
  66. data/lib/github_api2/client/repos/pub_sub_hubbub.rb +133 -0
  67. data/lib/github_api2/client/repos/releases/assets.rb +136 -0
  68. data/lib/github_api2/client/repos/releases/tags.rb +24 -0
  69. data/lib/github_api2/client/repos/releases.rb +189 -0
  70. data/lib/github_api2/client/repos/statistics.rb +89 -0
  71. data/lib/github_api2/client/repos/statuses.rb +91 -0
  72. data/lib/github_api2/client/repos.rb +473 -0
  73. data/lib/github_api2/client/say.rb +25 -0
  74. data/lib/github_api2/client/scopes.rb +46 -0
  75. data/lib/github_api2/client/search/legacy.rb +111 -0
  76. data/lib/github_api2/client/search.rb +133 -0
  77. data/lib/github_api2/client/users/emails.rb +65 -0
  78. data/lib/github_api2/client/users/followers.rb +115 -0
  79. data/lib/github_api2/client/users/keys.rb +104 -0
  80. data/lib/github_api2/client/users.rb +117 -0
  81. data/lib/github_api2/client.rb +77 -0
  82. data/lib/github_api2/configuration.rb +70 -0
  83. data/lib/github_api2/connection.rb +82 -0
  84. data/lib/github_api2/constants.rb +61 -0
  85. data/lib/github_api2/core_ext/array.rb +25 -0
  86. data/lib/github_api2/core_ext/hash.rb +91 -0
  87. data/lib/github_api2/deprecation.rb +39 -0
  88. data/lib/github_api2/error/client_error.rb +89 -0
  89. data/lib/github_api2/error/service_error.rb +223 -0
  90. data/lib/github_api2/error.rb +32 -0
  91. data/lib/github_api2/ext/faraday.rb +40 -0
  92. data/lib/github_api2/mash.rb +7 -0
  93. data/lib/github_api2/middleware.rb +37 -0
  94. data/lib/github_api2/mime_type.rb +33 -0
  95. data/lib/github_api2/normalizer.rb +23 -0
  96. data/lib/github_api2/null_encoder.rb +25 -0
  97. data/lib/github_api2/page_iterator.rb +138 -0
  98. data/lib/github_api2/page_links.rb +63 -0
  99. data/lib/github_api2/paged_request.rb +42 -0
  100. data/lib/github_api2/pagination.rb +115 -0
  101. data/lib/github_api2/parameter_filter.rb +35 -0
  102. data/lib/github_api2/params_hash.rb +115 -0
  103. data/lib/github_api2/rate_limit.rb +25 -0
  104. data/lib/github_api2/request/basic_auth.rb +36 -0
  105. data/lib/github_api2/request/jsonize.rb +54 -0
  106. data/lib/github_api2/request/oauth2.rb +45 -0
  107. data/lib/github_api2/request/verbs.rb +63 -0
  108. data/lib/github_api2/request.rb +84 -0
  109. data/lib/github_api2/response/atom_parser.rb +22 -0
  110. data/lib/github_api2/response/follow_redirects.rb +140 -0
  111. data/lib/github_api2/response/header.rb +87 -0
  112. data/lib/github_api2/response/jsonize.rb +28 -0
  113. data/lib/github_api2/response/mashify.rb +24 -0
  114. data/lib/github_api2/response/raise_error.rb +22 -0
  115. data/lib/github_api2/response/xmlize.rb +28 -0
  116. data/lib/github_api2/response.rb +48 -0
  117. data/lib/github_api2/response_wrapper.rb +161 -0
  118. data/lib/github_api2/ssl_certs/cacerts.pem +2183 -0
  119. data/lib/github_api2/utils/url.rb +63 -0
  120. data/lib/github_api2/validations/format.rb +26 -0
  121. data/lib/github_api2/validations/presence.rb +32 -0
  122. data/lib/github_api2/validations/required.rb +21 -0
  123. data/lib/github_api2/validations/token.rb +41 -0
  124. data/lib/github_api2/validations.rb +22 -0
  125. data/lib/github_api2/version.rb +5 -0
  126. data/lib/github_api2.rb +92 -0
  127. metadata +363 -0
@@ -0,0 +1,195 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../api'
4
+
5
+ module Github
6
+ class Client::PullRequests < API
7
+
8
+ require_all 'github_api2/client/pull_requests', 'comments', 'reviews'
9
+
10
+ # Access to PullRequests::Comments API
11
+ namespace :comments
12
+ # Access to PullRequests::Reviews API
13
+ namespace :reviews
14
+
15
+ # List pull requests
16
+ #
17
+ # @example
18
+ # github = Github.new user: 'user-name', repo: 'repo-name'
19
+ # github.pull_requests.list
20
+ # github.pull_requests.list { |req| ... }
21
+ #
22
+ # @example
23
+ # pulls = Github::PullRequests.new
24
+ # pulls.pull_requests.list 'user-name', 'repo-name'
25
+ #
26
+ # @api public
27
+ def list(*args)
28
+ arguments(args, required: [:user, :repo])
29
+
30
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/pulls",
31
+ arguments.params)
32
+ return response unless block_given?
33
+ response.each { |el| yield el }
34
+ end
35
+ alias_method :all, :list
36
+
37
+ # Get a single pull request
38
+ #
39
+ # = Examples
40
+ # github = Github.new
41
+ # github.pull_requests.get 'user-name', 'repo-name', 'number'
42
+ #
43
+ # pulls = Github::PullRequests.new
44
+ # pulls.get 'user-name', 'repo-name', 'number'
45
+ #
46
+ def get(*args)
47
+ arguments(args, required: [:user, :repo, :number])
48
+
49
+ get_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}", arguments.params)
50
+ end
51
+ alias_method :find, :get
52
+
53
+ # Create a pull request
54
+ #
55
+ # @param [Hash] params
56
+ # @option params [String] :title
57
+ # Required string
58
+ # @option params [String] :body
59
+ # Optional string
60
+ # @option params [String] :base
61
+ # Required string - The branch you want your changes pulled into.
62
+ # @option params [String] :head
63
+ # Required string - The branch where your changes are implemented.
64
+ #
65
+ # @note: head and base can be either a sha or a branch name.
66
+ # Typically you would namespace head with a user like this: username:branch.
67
+ #
68
+ # Alternative Input
69
+ # You can also create a Pull Request from an existing Issue by passing
70
+ # an Issue number instead of <tt>title</tt> and <tt>body</tt>.
71
+ # @option params [Numeric] :issue
72
+ # Required number - Issue number in this repository to turn into a Pull Request.
73
+ #
74
+ # @example
75
+ # github = Github.new oauth_token: '...'
76
+ # github.pull_requests.create 'user-name', 'repo-name',
77
+ # title: "Amazing new feature",
78
+ # body: "Please pull this in!",
79
+ # head: "octocat:new-feature",
80
+ # base: "master"
81
+ #
82
+ # @example
83
+ # github.pull_requests.create 'user-name', 'repo-name',
84
+ # issue: "5",
85
+ # head: "octocat:new-feature",
86
+ # base: "master"
87
+ #
88
+ # @api public
89
+ def create(*args)
90
+ arguments(args, required: [:user, :repo])
91
+
92
+ post_request("/repos/#{arguments.user}/#{arguments.repo}/pulls",
93
+ arguments.params)
94
+ end
95
+
96
+ # Update a pull request
97
+ #
98
+ # @param [Hash] params
99
+ # @option params [String] :title
100
+ # Optional string
101
+ # @optoin params [String] :body
102
+ # Optional string
103
+ # @option params [String] :state
104
+ # Optional string - State of this Pull Request.
105
+ # Valid values are open and closed.
106
+ #
107
+ # @example
108
+ # github = Github.new oauth_token: '...'
109
+ # github.pull_requests.update 'user-name', 'repo-name', 'number'
110
+ # title: "Amazing new title",
111
+ # body: "Update body",
112
+ # state: "open"
113
+ #
114
+ # @api public
115
+ def update(*args)
116
+ arguments(args, required: [:user, :repo, :number])
117
+
118
+ patch_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}", arguments.params)
119
+ end
120
+
121
+ # List commits on a pull request
122
+ #
123
+ # @example
124
+ # github = Github.new
125
+ # github.pull_requests.commits 'user-name', 'repo-name', 'number'
126
+ #
127
+ # @api public
128
+ def commits(*args)
129
+ arguments(args, required: [:user, :repo, :number])
130
+
131
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/commits", arguments.params)
132
+ return response unless block_given?
133
+ response.each { |el| yield el }
134
+ end
135
+
136
+ # List pull requests files
137
+ #
138
+ # @example
139
+ # github = Github.new
140
+ # github.pull_requests.files 'user-name', 'repo-name', 'number'
141
+ #
142
+ # @api public
143
+ def files(*args)
144
+ arguments(args, required: [:user, :repo, :number])
145
+
146
+ response = get_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/files", arguments.params)
147
+ return response unless block_given?
148
+ response.each { |el| yield el }
149
+ end
150
+
151
+ # Check if pull request has been merged
152
+ #
153
+ # @example
154
+ # github = Github.new
155
+ # github.pull_requests.merged? 'user-name', 'repo-name', 'number'
156
+ #
157
+ # @api public
158
+ def merged?(*args)
159
+ arguments(args, required: [:user, :repo, :number])
160
+
161
+ get_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/merge", arguments.params)
162
+ true
163
+ rescue Github::Error::NotFound
164
+ false
165
+ end
166
+
167
+ PREVIEW_MEDIA = 'application/vnd.github.polaris-preview+json'.freeze # :nodoc:
168
+
169
+ # Merge a pull request(Merge Button)
170
+ #
171
+ # @param [Hash] params
172
+ # @option params [String] :commit_title
173
+ # Optional string - The first line of the message that will be used for the merge commit
174
+ # @option params [String] :commit_message
175
+ # Optional string - The message that will be used for the merge commit
176
+ # @option params [String] :sha
177
+ # Optional string - The SHA that pull request head must match to allow merge
178
+ # @option params [String] :merge_method
179
+ # Optional string - Merge method to use.
180
+ # Valid values are merge, squash, and rebase. Default is merge.
181
+ #
182
+ # @example
183
+ # github = Github.new
184
+ # github.pull_requests.merge 'user-name', 'repo-name', 'number'
185
+ #
186
+ # @api public
187
+ def merge(*args)
188
+ arguments(args, required: [:user, :repo, :number])
189
+ params = arguments.params
190
+ params['accept'] ||= PREVIEW_MEDIA
191
+
192
+ put_request("/repos/#{arguments.user}/#{arguments.repo}/pulls/#{arguments.number}/merge", params)
193
+ end
194
+ end # PullRequests
195
+ 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 to 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,48 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative '../../api'
4
+
5
+ module Github
6
+ class Client::Repos::Branches < API
7
+ require_all 'github_api2/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,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