github_api 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/LICENSE.txt +20 -0
  2. data/README.rdoc +228 -0
  3. data/Rakefile +52 -0
  4. data/features/github_api.feature +50 -0
  5. data/features/options.feature +4 -0
  6. data/features/pagination.feature +4 -0
  7. data/features/step_definitions/github_api_steps.rb +11 -0
  8. data/features/support/env.rb +13 -0
  9. data/lib/github_api.rb +73 -0
  10. data/lib/github_api/api.rb +175 -0
  11. data/lib/github_api/api/utils.rb +9 -0
  12. data/lib/github_api/authorization.rb +73 -0
  13. data/lib/github_api/authorizations.rb +119 -0
  14. data/lib/github_api/cache_control.rb +19 -0
  15. data/lib/github_api/client.rb +55 -0
  16. data/lib/github_api/compatibility.rb +23 -0
  17. data/lib/github_api/configuration.rb +96 -0
  18. data/lib/github_api/connection.rb +75 -0
  19. data/lib/github_api/core_ext/array.rb +14 -0
  20. data/lib/github_api/core_ext/hash.rb +42 -0
  21. data/lib/github_api/error.rb +35 -0
  22. data/lib/github_api/events.rb +202 -0
  23. data/lib/github_api/gists.rb +200 -0
  24. data/lib/github_api/gists/comments.rb +86 -0
  25. data/lib/github_api/git_data.rb +26 -0
  26. data/lib/github_api/git_data/blobs.rb +51 -0
  27. data/lib/github_api/git_data/commits.rb +78 -0
  28. data/lib/github_api/git_data/references.rb +113 -0
  29. data/lib/github_api/git_data/tags.rb +78 -0
  30. data/lib/github_api/git_data/trees.rb +89 -0
  31. data/lib/github_api/issues.rb +215 -0
  32. data/lib/github_api/issues/comments.rb +123 -0
  33. data/lib/github_api/issues/events.rb +54 -0
  34. data/lib/github_api/issues/labels.rb +191 -0
  35. data/lib/github_api/issues/milestones.rb +140 -0
  36. data/lib/github_api/mime_type.rb +55 -0
  37. data/lib/github_api/orgs.rb +95 -0
  38. data/lib/github_api/orgs/members.rb +120 -0
  39. data/lib/github_api/orgs/teams.rb +245 -0
  40. data/lib/github_api/pull_requests.rb +224 -0
  41. data/lib/github_api/pull_requests/comments.rb +144 -0
  42. data/lib/github_api/repos.rb +286 -0
  43. data/lib/github_api/repos/collaborators.rb +81 -0
  44. data/lib/github_api/repos/commits.rb +180 -0
  45. data/lib/github_api/repos/downloads.rb +155 -0
  46. data/lib/github_api/repos/forks.rb +48 -0
  47. data/lib/github_api/repos/hooks.rb +174 -0
  48. data/lib/github_api/repos/keys.rb +104 -0
  49. data/lib/github_api/repos/pub_sub_hubbub.rb +102 -0
  50. data/lib/github_api/repos/watching.rb +94 -0
  51. data/lib/github_api/request.rb +84 -0
  52. data/lib/github_api/request/basic_auth.rb +31 -0
  53. data/lib/github_api/request/caching.rb +33 -0
  54. data/lib/github_api/request/oauth2.rb +33 -0
  55. data/lib/github_api/response.rb +28 -0
  56. data/lib/github_api/response/helpers.rb +14 -0
  57. data/lib/github_api/response/jsonize.rb +26 -0
  58. data/lib/github_api/response/mashify.rb +24 -0
  59. data/lib/github_api/response/raise_error.rb +33 -0
  60. data/lib/github_api/result.rb +42 -0
  61. data/lib/github_api/users.rb +84 -0
  62. data/lib/github_api/users/emails.rb +49 -0
  63. data/lib/github_api/users/followers.rb +98 -0
  64. data/lib/github_api/users/keys.rb +84 -0
  65. data/lib/github_api/version.rb +12 -0
  66. data/spec/README.rdoc +22 -0
  67. data/spec/coverage_adapter.rb +15 -0
  68. data/spec/fixtures/auths/authorization.json +14 -0
  69. data/spec/fixtures/auths/authorizations.json +16 -0
  70. data/spec/fixtures/events/events.json +29 -0
  71. data/spec/fixtures/issues/comment.json +13 -0
  72. data/spec/fixtures/issues/comments.json +15 -0
  73. data/spec/fixtures/issues/event.json +13 -0
  74. data/spec/fixtures/issues/events.json +15 -0
  75. data/spec/fixtures/issues/issue.json +56 -0
  76. data/spec/fixtures/issues/issues.json +58 -0
  77. data/spec/fixtures/issues/milestone.json +18 -0
  78. data/spec/fixtures/issues/milestones.json +20 -0
  79. data/spec/fixtures/orgs/members.json +9 -0
  80. data/spec/fixtures/orgs/org.json +18 -0
  81. data/spec/fixtures/orgs/orgs.json +8 -0
  82. data/spec/fixtures/orgs/team.json +8 -0
  83. data/spec/fixtures/orgs/team_repos.json +29 -0
  84. data/spec/fixtures/orgs/teams.json +7 -0
  85. data/spec/fixtures/repos/branches.json +9 -0
  86. data/spec/fixtures/repos/collaborators.json +8 -0
  87. data/spec/fixtures/repos/commit.json +53 -0
  88. data/spec/fixtures/repos/commit_comment.json +16 -0
  89. data/spec/fixtures/repos/commit_comments.json +18 -0
  90. data/spec/fixtures/repos/commits.json +27 -0
  91. data/spec/fixtures/repos/contributors.json +8 -0
  92. data/spec/fixtures/repos/download.json +10 -0
  93. data/spec/fixtures/repos/download_s3.json +21 -0
  94. data/spec/fixtures/repos/downloads.json +12 -0
  95. data/spec/fixtures/repos/fork.json +27 -0
  96. data/spec/fixtures/repos/forks.json +29 -0
  97. data/spec/fixtures/repos/hook.json +15 -0
  98. data/spec/fixtures/repos/hooks.json +10 -0
  99. data/spec/fixtures/repos/key.json +6 -0
  100. data/spec/fixtures/repos/keys.json +8 -0
  101. data/spec/fixtures/repos/languages.json +4 -0
  102. data/spec/fixtures/repos/repo.json +90 -0
  103. data/spec/fixtures/repos/repo_comments.json +18 -0
  104. data/spec/fixtures/repos/repos.json +29 -0
  105. data/spec/fixtures/repos/tags.json +11 -0
  106. data/spec/fixtures/repos/teams.json +7 -0
  107. data/spec/fixtures/repos/watched.json +29 -0
  108. data/spec/fixtures/repos/watchers.json +8 -0
  109. data/spec/fixtures/users/user.json +32 -0
  110. data/spec/github/api_spec.rb +25 -0
  111. data/spec/github/authorization_spec.rb +176 -0
  112. data/spec/github/authorizations_spec.rb +242 -0
  113. data/spec/github/client_spec.rb +50 -0
  114. data/spec/github/core_ext/hash_spec.rb +44 -0
  115. data/spec/github/events_spec.rb +491 -0
  116. data/spec/github/gists/comments_spec.rb +5 -0
  117. data/spec/github/gists_spec.rb +5 -0
  118. data/spec/github/git_data/blobs_spec.rb +5 -0
  119. data/spec/github/git_data/commits_spec.rb +5 -0
  120. data/spec/github/git_data/references_spec.rb +5 -0
  121. data/spec/github/git_data/tags_spec.rb +5 -0
  122. data/spec/github/git_data/trees_spec.rb +5 -0
  123. data/spec/github/git_data_spec.rb +5 -0
  124. data/spec/github/issues/comments_spec.rb +254 -0
  125. data/spec/github/issues/events_spec.rb +153 -0
  126. data/spec/github/issues/labels_spec.rb +5 -0
  127. data/spec/github/issues/milestones_spec.rb +260 -0
  128. data/spec/github/issues_spec.rb +287 -0
  129. data/spec/github/mime_type_spec.rb +70 -0
  130. data/spec/github/orgs/members_spec.rb +275 -0
  131. data/spec/github/orgs/teams_spec.rb +563 -0
  132. data/spec/github/orgs_spec.rb +160 -0
  133. data/spec/github/repos/collaborators_spec.rb +169 -0
  134. data/spec/github/repos/commits_spec.rb +424 -0
  135. data/spec/github/repos/downloads_spec.rb +247 -0
  136. data/spec/github/repos/forks_spec.rb +108 -0
  137. data/spec/github/repos/hooks_spec.rb +333 -0
  138. data/spec/github/repos/keys_spec.rb +217 -0
  139. data/spec/github/repos/pub_sub_hubbub_spec.rb +83 -0
  140. data/spec/github/repos/watching_spec.rb +222 -0
  141. data/spec/github/repos_spec.rb +571 -0
  142. data/spec/github/result_spec.rb +43 -0
  143. data/spec/github/users_spec.rb +140 -0
  144. data/spec/github_spec.rb +109 -0
  145. data/spec/spec_helper.rb +86 -0
  146. data/spec/support/base.rb +13 -0
  147. metadata +149 -4
@@ -0,0 +1,120 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Orgs
5
+ module Members
6
+
7
+ # List members
8
+ #
9
+ # List all users who are members of an organization. A member is a user
10
+ # that belongs to at least 1 team in the organization.
11
+ # If the authenticated user is also a member of this organization then
12
+ # both concealed and public members will be returned.
13
+ # Otherwise only public members are returned.
14
+ #
15
+ # = Examples
16
+ # @github = Github.new
17
+ # @github.orgs.members 'org-name'
18
+ # @github.orgs.members 'org-name' { |memb| ... }
19
+ #
20
+ def members(org_name, params={})
21
+ _validate_presence_of org_name
22
+ _normalize_params_keys(params)
23
+ response = get("/orgs/#{org_name}/members", params)
24
+ return response unless block_given?
25
+ response.each { |el| yield el }
26
+ end
27
+ alias :list_members :members
28
+
29
+ # Check if user is a member of an organization
30
+ #
31
+ # = Examples
32
+ # @github = Github.new
33
+ # @github.orgs.member? 'org-name', 'member-name'
34
+ #
35
+ def member?(org_name, member_name, params={})
36
+ _validate_presence_of org_name, member_name
37
+ _normalize_params_keys(params)
38
+ get("/orgs/#{org_name}/members/#{member_name}", params)
39
+ true
40
+ rescue Github::ResourceNotFound
41
+ false
42
+ end
43
+ alias :is_member? :member?
44
+
45
+ # Remove a member
46
+ # Removing a user from this list will remove them from all teams and
47
+ # they will no longer have any access to the organization’s repositories.
48
+ #
49
+ # = Examples
50
+ # @github = Github.new
51
+ # @github.orgs.delete_member 'org-name', 'member-name'
52
+ #
53
+ def delete_member(org_name, member_name, params={})
54
+ _validate_presence_of org_name, member_name
55
+ _normalize_params_keys(params)
56
+ delete("/orgs/#{org_name}/members/#{member_name}", params)
57
+ end
58
+ alias :remove_member :delete_member
59
+
60
+ # List public members
61
+ # Members of an organization can choose to have their membership publicized or not.
62
+ # = Examples
63
+ # @github = Github.new
64
+ # @github.orgs.public_members 'org-name'
65
+ # @github.orgs.public_members 'org-name' { |memb| ... }
66
+ #
67
+ def public_members(org_name, params={})
68
+ _validate_presence_of org_name
69
+ _normalize_params_keys(params)
70
+ response = get("/orgs/#{org_name}/public_members", params)
71
+ return response unless block_given?
72
+ response.each { |el| yield el }
73
+ end
74
+ alias :list_public_members :public_members
75
+
76
+ # Get if a user is a public member of an organization
77
+ #
78
+ # = Examples
79
+ # @github = Github.new
80
+ # @github.orgs.public_member? 'org-name', 'member-name'
81
+ #
82
+ def public_member?(org_name, member_name, params={})
83
+ _validate_presence_of org_name, member_name
84
+ _normalize_params_keys(params)
85
+ get("/orgs/#{org_name}/public_members/#{member_name}", params)
86
+ true
87
+ rescue Github::ResourceNotFound
88
+ false
89
+ end
90
+
91
+ # Publicize a user’s membership
92
+ #
93
+ # = Examples
94
+ # @github = Github.new :oauth_token => '...'
95
+ # @github.orgs.publicize 'org-name', 'member-name'
96
+ #
97
+ def publicize(org_name, member_name, params={})
98
+ _validate_presence_of org_name, member_name
99
+ _normalize_params_keys(params)
100
+ put("/orgs/#{org_name}/public_members/#{member_name}", params)
101
+ end
102
+ alias :make_public :publicize
103
+ alias :publicize_membership :publicize
104
+
105
+ # Conceal a user’s membership
106
+ #
107
+ # = Examples
108
+ # @github = Github.new :oauth_token => '...'
109
+ # @github.orgs.conceal 'org-name', 'member-name'
110
+ #
111
+ def conceal(org_name, member_name, params={})
112
+ _validate_presence_of org_name, member_name
113
+ _normalize_params_keys(params)
114
+ delete("/orgs/#{org_name}/public_members/#{member_name}", params)
115
+ end
116
+ alias :conceal_membership :conceal
117
+
118
+ end # Members
119
+ end # Orgs
120
+ end # Github
@@ -0,0 +1,245 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class Orgs
5
+ # All actions against teams require at a minimum an authenticated user
6
+ # who is a member of the owner’s team in the :org being managed.
7
+ # Api calls that require explicit permissions are noted.
8
+ module Teams
9
+
10
+ VALID_TEAM_PARAM_NAMES = %w[ name repo_names permission ].freeze
11
+ VALID_TEAM_PARAM_VALUES = {
12
+ 'permission' => %w[ pull push admin ].freeze
13
+ }
14
+
15
+ # List teams
16
+ #
17
+ # = Examples
18
+ # @github = Github.new :oauth_token => '...'
19
+ # @github.orgs.teams 'org-name'
20
+ #
21
+ def teams(org_name, params={})
22
+ _validate_presence_of org_name
23
+ _normalize_params_keys(params)
24
+
25
+ response = get("/orgs/#{org_name}/teams", params)
26
+ return response unless block_given?
27
+ response.each { |el| yield el }
28
+ end
29
+ alias :list_teams :teams
30
+
31
+ # Get a team
32
+ #
33
+ # = Examples
34
+ # @github = Github.new :oauth_token => '...'
35
+ # @github.orgs.team 'team-name'
36
+ #
37
+ def team(team_name, params={})
38
+ _validate_presence_of team_name
39
+ _normalize_params_keys(params)
40
+
41
+ get("/teams/#{team_name}", params)
42
+ end
43
+ alias :get_team :team
44
+
45
+ # Create a team
46
+ #
47
+ # In order to create a team, the authenticated user must be an owner of<tt>:org</tt>.
48
+ # = Inputs
49
+ # <tt>:name</tt> - Required string
50
+ # <tt>:repo_names</tt> - Optional array of strings
51
+ # <tt>:permission</tt> - Optional string
52
+ # * <tt>pull</tt> - team members can pull, but not push or administor this repositories. Default
53
+ # * <tt>push</tt> - team members can pull and push, but not administor this repositores.
54
+ # * <tt>admin</tt> - team members can pull, push and administor these repositories.
55
+ #
56
+ # = Examples
57
+ # @github = Github.new :oauth_token => '...'
58
+ # @github.orgs.create_team 'org-name',
59
+ # "name" => "new team",
60
+ # "permission" => "push",
61
+ # "repo_names" => [
62
+ # "github/dotfiles"
63
+ # ]
64
+ #
65
+ def create_team(org_name, params={})
66
+ _validate_presence_of org_name
67
+ _normalize_params_keys(params)
68
+ _filter_params_keys(VALID_TEAM_PARAM_NAMES, params)
69
+ _validate_params_values(VALID_TEAM_PARAM_VALUES, params)
70
+
71
+ raise ArgumentError, "Required params are: :name" unless _validate_inputs(%w[ name ], params)
72
+
73
+ post("/orgs/#{org_name}/teams", params)
74
+ end
75
+
76
+ # Edit a team
77
+ # In order to edit a team, the authenticated user must be an owner of the org that the team is associated with.
78
+ #
79
+ # = Inputs
80
+ # <tt>:name</tt> - Required string
81
+ # <tt>:permission</tt> - Optional string
82
+ # * <tt>pull</tt> - team members can pull, but not push or administor this repositories. Default
83
+ # * <tt>push</tt> - team members can pull and push, but not administor this repositores.
84
+ # * <tt>admin</tt> - team members can pull, push and administor these repositories.
85
+ #
86
+ # = Examples
87
+ # @github = Github.new :oauth_token => '...'
88
+ # @github.orgs.edit_team 'team-name',
89
+ # "name" => "new team name",
90
+ # "permission" => "push"
91
+ #
92
+ def edit_team(team_name, params={})
93
+ _validate_presence_of team_name
94
+ _normalize_params_keys(params)
95
+ _filter_params_keys(VALID_TEAM_PARAM_NAMES, params)
96
+ _validate_params_values(VALID_TEAM_PARAM_VALUES, params)
97
+
98
+ raise ArgumentError, "Required params are: :name" unless _validate_inputs(%w[ name ], params)
99
+
100
+ patch("/teams/#{team_name}", params)
101
+ end
102
+
103
+ # Delete a team
104
+ # In order to delete a team, the authenticated user must be an owner of the org that the team is associated with
105
+ #
106
+ # = Examples
107
+ # @github = Github.new :oauth_token => '...'
108
+ # @github.orgs.delete_team 'team-name'
109
+ #
110
+ def delete_team(team_name, params={})
111
+ _validate_presence_of team_name
112
+ _normalize_params_keys(params)
113
+ delete("/teams/#{team_name}", params)
114
+ end
115
+
116
+ # List team members
117
+ # In order to list members in a team, the authenticated user must be a member of the team.
118
+ #
119
+ # = Examples
120
+ # @github = Github.new :oauth_token => '...'
121
+ # @github.orgs.team_members 'team-name'
122
+ # @github.orgs.team_members 'team-name' { |member| ... }
123
+ #
124
+ def team_members(team_name, params={})
125
+ _validate_presence_of team_name
126
+ _normalize_params_keys(params)
127
+
128
+ response = get("/teams/#{team_name}/members", params)
129
+ return response unless block_given?
130
+ response.each { |el| yield el }
131
+ end
132
+ alias :list_team_members :team_members
133
+
134
+ # Check if a user is a member of a team
135
+ #
136
+ # = Examples
137
+ # @github = Github.new :oauth_token => '...'
138
+ # @github.orgs.team_member? 'team-name', 'user-name'
139
+ #
140
+ def team_member?(team_name, member_name, params={})
141
+ _validate_presence_of team_name, member_name
142
+ _normalize_params_keys(params)
143
+ get("/teams/#{team_name}/members/#{member_name}", params)
144
+ true
145
+ rescue Github::ResourceNotFound
146
+ false
147
+ end
148
+
149
+ # Add a team member
150
+ # In order to add a user to a team, the authenticated user must have ‘admin’ permissions to the team or be an owner of the org that the team is associated with.
151
+ #
152
+ # = Examples
153
+ # @github = Github.new :oauth_token => '...'
154
+ # @github.orgs.add_team_member 'team-name', 'user-name'
155
+ #
156
+ def add_team_member(team_name, member_name, params={})
157
+ _validate_presence_of team_name, member_name
158
+ _normalize_params_keys(params)
159
+ put("/teams/#{team_name}/members/#{member_name}", params)
160
+ end
161
+ alias :add_member :add_team_member
162
+
163
+ # Remove a team member
164
+ # In order to remove a user from a team, the authenticated user must
165
+ # have ‘admin’ permissions to the team or be an owner of the org that
166
+ # the team is associated with.
167
+ # note: This does not delete the user, it just remove them from the team.
168
+ #
169
+ # = Examples
170
+ # @github = Github.new :oauth_token => '...'
171
+ # @github.orgs.remove_team_member 'team-name', 'member-name'
172
+ #
173
+ def remove_team_member(team_name, member_name, params={})
174
+ _validate_presence_of team_name, member_name
175
+ _normalize_params_keys(params)
176
+ delete("/teams/#{team_name}/members/#{member_name}", params)
177
+ end
178
+ alias :remove_member :remove_team_member
179
+
180
+ # List team repositories
181
+ #
182
+ # = Examples
183
+ # @github = Github.new :oauth_token => '...'
184
+ # @github.orgs.team_repos 'team-name'
185
+ #
186
+ def team_repos(team_name, params={})
187
+ _validate_presence_of team_name
188
+ _normalize_params_keys(params)
189
+
190
+ response = get("/teams/#{team_name}/repos", params)
191
+ return response unless block_given?
192
+ response.each { |el| yield el }
193
+ end
194
+ alias :team_repositories :team_repos
195
+
196
+ # Check if a repository belongs to a team
197
+ #
198
+ # = Examples
199
+ # @github = Github.new :oauth_token => '...'
200
+ # @github.orgs.team_repo? 'team-name', 'user-name', 'repo-name'
201
+ #
202
+ def team_repo?(team_name, user_name, repo_name, params={})
203
+ _validate_presence_of team_name, user_name, repo_name
204
+ _normalize_params_keys(params)
205
+ get("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
206
+ true
207
+ rescue Github::ResourceNotFound
208
+ false
209
+ end
210
+ alias :team_repository? :team_repo?
211
+
212
+ # Add a team repository
213
+ # In order to add a repo to a team, the authenticated user must be
214
+ # an owner of the org that the team is associated with.
215
+ #
216
+ # = Examples
217
+ # @github = Github.new :oauth_token => '...'
218
+ # @github.orgs.add_team_repo 'team-name', 'user-name', 'repo-name'
219
+ #
220
+ def add_team_repo(team_name, user_name, repo_name, params={})
221
+ _validate_presence_of team_name, user_name, repo_name
222
+ _normalize_params_keys(params)
223
+ put("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
224
+ end
225
+ alias :add_team_repository :add_team_repo
226
+
227
+ # Remove a team repository
228
+ # In order to add a repo to a team, the authenticated user must be
229
+ # an owner of the org that the team is associated with.
230
+ # note: This does not delete the repo, it just removes it from the team.
231
+ #
232
+ # = Examples
233
+ # @github = Github.new :oauth_token => '...'
234
+ # @github.orgs.remove_team_repo 'team-name', 'user-name', 'repo-name'
235
+ #
236
+ def remove_team_repo(team_name, user_name, repo_name, params={})
237
+ _validate_presence_of team_name, user_name, repo_name
238
+ _normalize_params_keys(params)
239
+ delete("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
240
+ end
241
+ alias :remove_team_repository :remove_team_repo
242
+
243
+ end # Teams
244
+ end # Orgs
245
+ end # Github
@@ -0,0 +1,224 @@
1
+ # encoding: utf-8
2
+
3
+ module Github
4
+ class PullRequests < API
5
+ extend AutoloadHelper
6
+
7
+ autoload_all 'github_api/pull_requests',
8
+ :Comments => 'comments'
9
+
10
+ include Github::PullRequests::Comments
11
+
12
+ VALID_REQUEST_PARAM_NAMES = %w[
13
+ title
14
+ body
15
+ base
16
+ head
17
+ state
18
+ issue
19
+ commit_message
20
+ mime_type
21
+ resource
22
+ ].freeze
23
+
24
+ VALID_REQUEST_PARAM_VALUES = {
25
+ 'state' => %w[ open closed ]
26
+ }
27
+
28
+ # Creates new Gists API
29
+ def initialize(options = {})
30
+ super(options)
31
+ end
32
+
33
+ # List pull requests
34
+ #
35
+ # = Examples
36
+ # @github = Github.new :user => 'user-name', :repo => 'repo-name'
37
+ # @github.pull_requests.pull_requests
38
+ # @github.pull_requests.pull_requests { |req| ... }
39
+ #
40
+ # @pull_reqs = Github::PullRequests.new
41
+ # @pull_reqs.pull_requests 'user-name', 'repo-name'
42
+ #
43
+ def pull_requests(user_name=nil, repo_name=nil, params={})
44
+ _update_user_repo_params(user_name, repo_name)
45
+ _validate_user_repo_params(user, repo) unless (user? && repo?)
46
+
47
+ _normalize_params_keys(params)
48
+ _filter_params_keys(VALID_REQUEST_PARAM_NAMES, params)
49
+ _merge_mime_type(:pull_request, params)
50
+ _validate_params_values(VALID_REQUEST_PARAM_VALUES, params)
51
+
52
+ response = get("/repos/#{user}/#{repo}/pulls", params)
53
+ return response unless block_given?
54
+ response.each { |el| yield el }
55
+ end
56
+
57
+ # Get a single pull request
58
+ #
59
+ # = Examples
60
+ # @github = Github.new
61
+ # @github.pull_requests.pull_request 'user-name', 'repo-name', 'request-id'
62
+ #
63
+ # @pull_reqs = Github::PullRequests.new
64
+ # @pull_reqs.pull_request 'user-name', 'repo-name', 'request-id'
65
+ #
66
+ def pull_request(user_name, repo_name, request_id, params={})
67
+ _update_user_repo_params(user_name, repo_name)
68
+ _validate_user_repo_params(user, repo) unless user? && repo?
69
+ _validate_presence_of request_id
70
+
71
+ _normalize_params_keys(params)
72
+ _merge_mime_type(:pull_request, params)
73
+
74
+ get("/repos/#{user}/#{repo}/pulls/#{request_id}", params)
75
+ end
76
+
77
+ # Create a pull request
78
+ #
79
+ # = Inputs
80
+ # * <tt>:title</tt> - Required string
81
+ # * <tt>:body</tt> - Optional string
82
+ # * <tt>:base</tt> - Required string - The branch you want your changes pulled into.
83
+ # * <tt>:head</tt> - Required string - The branch where your changes are implemented.
84
+ # note: head and base can be either a sha or a branch name.
85
+ # Typically you would namespace head with a user like this: username:branch.
86
+ # = Alternative Input
87
+ # You can also create a Pull Request from an existing Issue by passing
88
+ # an Issue number instead of <tt>title</tt> and <tt>body</tt>.
89
+ # * <tt>issue</tt> - Required number - Issue number in this repository to turn into a Pull Request.
90
+ #
91
+ # = Examples
92
+ # @github = Github.new :oauth_token => '...'
93
+ # @github.pull_requests.create_request 'user-name', 'repo-name',
94
+ # "title" => "Amazing new feature",
95
+ # "body" => "Please pull this in!",
96
+ # "head" => "octocat:new-feature",
97
+ # "base" => "master"
98
+ #
99
+ # alternatively
100
+ #
101
+ # @github.pull_requests.create_request 'user-name', 'repo-name',
102
+ # "issue" => "5",
103
+ # "head" => "octocat:new-feature",
104
+ # "base" => "master"
105
+ #
106
+ def create_request(user_name=nil, repo_name=nil, params={})
107
+ _update_user_repo_params(user_name, repo_name)
108
+ _validate_user_repo_params(user, repo) unless user? && repo?
109
+
110
+ _normalize_params_keys(params)
111
+ _merge_mime_type(:pull_request, params)
112
+ _filter_params_keys(VALID_REQUEST_PARAM_NAMES, params)
113
+
114
+ post("/repos/#{user}/#{repo}/pulls", params)
115
+ end
116
+
117
+ # Update a pull request
118
+ #
119
+ # = Inputs
120
+ # * <tt>:title</tt> - Optional string
121
+ # * <tt>:body</tt> - Optional string
122
+ # * <tt>:state</tt> - Optional string - State of this Pull Request. Valid values are <tt>open</tt> and <tt>closed</tt>.
123
+ #
124
+ # = Examples
125
+ # @github = Github.new :oauth_token => '...'
126
+ # @github.pull_requests.update_request 'user-name', 'repo-name', 'request-id'
127
+ # "title" => "Amazing new title",
128
+ # "body" => "Update body",
129
+ # "state" => "open",
130
+ #
131
+ def update_request(user_name, repo_name, request_id, params={})
132
+ _update_user_repo_params(user_name, repo_name)
133
+ _validate_user_repo_params(user, repo) unless user? && repo?
134
+ _validate_presence_of request_id
135
+
136
+ _normalize_params_keys(params)
137
+ _filter_params_keys(VALID_REQUEST_PARAM_NAMES, params)
138
+ _merge_mime_type(:pull_request, params)
139
+ _validate_params_values(VALID_REQUEST_PARAM_VALUES, params)
140
+
141
+ patch("/repos/#{user}/#{repo}/pulls/#{request_id}", params)
142
+ end
143
+
144
+ # List commits on a pull request
145
+ #
146
+ # = Examples
147
+ # @github = Github.new
148
+ # @github.pull_requests.request_commits 'user-name', 'repo-name', 'request-id'
149
+ #
150
+ def request_commits(user_name, repo_name, request_id, params={})
151
+ _update_user_repo_params(user_name, repo_name)
152
+ _validate_user_repo_params(user, repo) unless user? && repo?
153
+ _validate_presence_of request_id
154
+
155
+ _normalize_params_keys(params)
156
+ _merge_mime_type(:pull_request, params)
157
+
158
+ response = get("/repos/#{user}/#{repo}/pulls/#{request_id}/commits", params)
159
+ return response unless block_given?
160
+ response.each { |el| yield el }
161
+ end
162
+
163
+ # List pull requests files
164
+ #
165
+ # = Examples
166
+ # @github = Github.new
167
+ # @github.pull_requests.request_files 'user-name', 'repo-name', 'request-id'
168
+ #
169
+ def request_files(user_name, repo_name, request_id, params={})
170
+ _update_user_repo_params(user_name, repo_name)
171
+ _validate_user_repo_params(user, repo) unless user? && repo?
172
+ _validate_presence_of request_id
173
+
174
+ _normalize_params_keys(params)
175
+ _merge_mime_type(:pull_request, params)
176
+
177
+ response = get("/repos/#{user}/#{repo}/pulls/#{request_id}/files", params)
178
+ return response unless block_given?
179
+ response.each { |el| yield el }
180
+ end
181
+
182
+ # Check if pull request has been merged
183
+ #
184
+ # = Examples
185
+ # @github = Github.new
186
+ # @github.pull_requests.merged? 'user-name', 'repo-name', 'request-id'
187
+ #
188
+ def merged?(user_name, repo_name, request_id, params={})
189
+ _update_user_repo_params(user_name, repo_name)
190
+ _validate_user_repo_params(user, repo) unless user? && repo?
191
+ _validate_presence_of request_id
192
+
193
+ _normalize_params_keys(params)
194
+ _merge_mime_type(:pull_request, params)
195
+
196
+ get("/repos/#{user}/#{repo}/pulls/#{request_id}/merge", params)
197
+ true
198
+ rescue Github::ResourceNotFound
199
+ false
200
+ end
201
+
202
+ # Merge a pull request(Merge Button)
203
+ #
204
+ # = Inputs
205
+ # <tt>:commit_message</tt> - Optional string - The message that will be used for the merge commit
206
+ #
207
+ # = Examples
208
+ # @github = Github.new
209
+ # @github.pull_requests.request_files 'user-name', 'repo-name', 'request-id'
210
+ #
211
+ def merge(user_name, repo_name, request_id, params={})
212
+ _update_user_repo_params(user_name, repo_name)
213
+ _validate_user_repo_params(user, repo) unless user? && repo?
214
+ _validate_presence_of request_id
215
+
216
+ _normalize_params_keys(params)
217
+ _merge_mime_type(:pull_request, params)
218
+ _filter_params_keys(VALID_REQUEST_PARAM_NAMES, params)
219
+
220
+ put("/repos/#{user}/#{repo}/pulls/#{request_id}/merge", params)
221
+ end
222
+
223
+ end # PullRequests
224
+ end # Github