brat 0.1.1
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 +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +24 -0
- data/README.md +103 -0
- data/Rakefile +9 -0
- data/bin/brat +7 -0
- data/brat.gemspec +26 -0
- data/lib/brat.rb +37 -0
- data/lib/brat/api.rb +17 -0
- data/lib/brat/cli.rb +47 -0
- data/lib/brat/cli_helpers.rb +175 -0
- data/lib/brat/client.rb +18 -0
- data/lib/brat/client/branches.rb +79 -0
- data/lib/brat/client/groups.rb +88 -0
- data/lib/brat/client/issues.rb +92 -0
- data/lib/brat/client/merge_requests.rb +107 -0
- data/lib/brat/client/milestones.rb +57 -0
- data/lib/brat/client/notes.rb +106 -0
- data/lib/brat/client/projects.rb +298 -0
- data/lib/brat/client/repositories.rb +78 -0
- data/lib/brat/client/snippets.rb +86 -0
- data/lib/brat/client/system_hooks.rb +58 -0
- data/lib/brat/client/users.rb +123 -0
- data/lib/brat/configuration.rb +40 -0
- data/lib/brat/error.rb +42 -0
- data/lib/brat/help.rb +44 -0
- data/lib/brat/objectified_hash.rb +24 -0
- data/lib/brat/request.rb +101 -0
- data/lib/brat/shell.rb +49 -0
- data/lib/brat/version.rb +3 -0
- data/spec/brat/cli_spec.rb +80 -0
- data/spec/brat/client/branches_spec.rb +103 -0
- data/spec/brat/client/groups_spec.rb +111 -0
- data/spec/brat/client/issues_spec.rb +122 -0
- data/spec/brat/client/merge_requests_spec.rb +124 -0
- data/spec/brat/client/milestones_spec.rb +66 -0
- data/spec/brat/client/notes_spec.rb +156 -0
- data/spec/brat/client/projects_spec.rb +357 -0
- data/spec/brat/client/repositories_spec.rb +92 -0
- data/spec/brat/client/snippets_spec.rb +85 -0
- data/spec/brat/client/system_hooks_spec.rb +69 -0
- data/spec/brat/client/users_spec.rb +192 -0
- data/spec/brat/objectified_hash_spec.rb +23 -0
- data/spec/brat/request_spec.rb +48 -0
- data/spec/brat_spec.rb +65 -0
- data/spec/fixtures/branch.json +1 -0
- data/spec/fixtures/branches.json +1 -0
- data/spec/fixtures/comment_merge_request.json +1 -0
- data/spec/fixtures/create_branch.json +1 -0
- data/spec/fixtures/create_merge_request.json +1 -0
- data/spec/fixtures/error_already_exists.json +1 -0
- data/spec/fixtures/group.json +60 -0
- data/spec/fixtures/group_create.json +1 -0
- data/spec/fixtures/group_member.json +1 -0
- data/spec/fixtures/group_member_delete.json +1 -0
- data/spec/fixtures/group_members.json +1 -0
- data/spec/fixtures/groups.json +2 -0
- data/spec/fixtures/issue.json +1 -0
- data/spec/fixtures/issues.json +1 -0
- data/spec/fixtures/key.json +1 -0
- data/spec/fixtures/keys.json +1 -0
- data/spec/fixtures/merge_request.json +1 -0
- data/spec/fixtures/merge_request_comments.json +1 -0
- data/spec/fixtures/merge_requests.json +1 -0
- data/spec/fixtures/milestone.json +1 -0
- data/spec/fixtures/milestones.json +1 -0
- data/spec/fixtures/note.json +1 -0
- data/spec/fixtures/notes.json +1 -0
- data/spec/fixtures/project.json +1 -0
- data/spec/fixtures/project_commit.json +13 -0
- data/spec/fixtures/project_commit_diff.json +10 -0
- data/spec/fixtures/project_commits.json +1 -0
- data/spec/fixtures/project_delete_key.json +8 -0
- data/spec/fixtures/project_events.json +1 -0
- data/spec/fixtures/project_for_user.json +1 -0
- data/spec/fixtures/project_fork_link.json +1 -0
- data/spec/fixtures/project_hook.json +1 -0
- data/spec/fixtures/project_hooks.json +1 -0
- data/spec/fixtures/project_issues.json +1 -0
- data/spec/fixtures/project_key.json +6 -0
- data/spec/fixtures/project_keys.json +6 -0
- data/spec/fixtures/project_tags.json +1 -0
- data/spec/fixtures/projects.json +1 -0
- data/spec/fixtures/protect_branch.json +1 -0
- data/spec/fixtures/session.json +1 -0
- data/spec/fixtures/snippet.json +1 -0
- data/spec/fixtures/snippets.json +1 -0
- data/spec/fixtures/system_hook.json +1 -0
- data/spec/fixtures/system_hook_test.json +1 -0
- data/spec/fixtures/system_hooks.json +1 -0
- data/spec/fixtures/tag.json +1 -0
- data/spec/fixtures/team_member.json +1 -0
- data/spec/fixtures/team_members.json +1 -0
- data/spec/fixtures/unprotect_branch.json +1 -0
- data/spec/fixtures/update_merge_request.json +1 -0
- data/spec/fixtures/user.json +1 -0
- data/spec/fixtures/users.json +1 -0
- data/spec/spec_helper.rb +74 -0
- metadata +281 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
class Brat::Client
|
|
2
|
+
# Defines methods related to projects.
|
|
3
|
+
module Projects
|
|
4
|
+
# Gets a list of projects owned by the authenticated user.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# Brat.projects
|
|
8
|
+
#
|
|
9
|
+
# @param [Hash] options A customizable set of options.
|
|
10
|
+
# @option options [Integer] :page The page number.
|
|
11
|
+
# @option options [Integer] :per_page The number of results per page.
|
|
12
|
+
# @option options [String] :scope Scope of projects. 'owned' for list of projects owned by the authenticated user, 'all' to get all projects (admin only)
|
|
13
|
+
# @return [Array<Brat::ObjectifiedHash>]
|
|
14
|
+
def projects(options={})
|
|
15
|
+
if (options[:scope])
|
|
16
|
+
get("/projects/#{options[:scope]}", :query => options)
|
|
17
|
+
else
|
|
18
|
+
get("/projects", :query => options)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Gets information about a project.
|
|
23
|
+
#
|
|
24
|
+
# @example
|
|
25
|
+
# Brat.project(3)
|
|
26
|
+
# Brat.project('brat')
|
|
27
|
+
#
|
|
28
|
+
# @param [Integer, String] id The ID or name of a project.
|
|
29
|
+
# @return [Brat::ObjectifiedHash]
|
|
30
|
+
def project(id)
|
|
31
|
+
get("/projects/#{id}")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Gets a list of project events.
|
|
35
|
+
#
|
|
36
|
+
# @example
|
|
37
|
+
# Brat.project_events(42)
|
|
38
|
+
# Brat.project_events('brat')
|
|
39
|
+
#
|
|
40
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
41
|
+
# @param [Hash] options A customizable set of options.
|
|
42
|
+
# @option options [Integer] :page The page number.
|
|
43
|
+
# @option options [Integer] :per_page The number of results per page.
|
|
44
|
+
# @return [Array<Brat::ObjectifiedHash>]
|
|
45
|
+
def project_events(project, options={})
|
|
46
|
+
get("/projects/#{project}/events", :query => options)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Creates a new project.
|
|
50
|
+
#
|
|
51
|
+
# @example
|
|
52
|
+
# Brat.create_project('brat')
|
|
53
|
+
# Brat.create_project('viking', :description => 'Awesome project')
|
|
54
|
+
# Brat.create_project('Red', :wall_enabled => false)
|
|
55
|
+
#
|
|
56
|
+
# @param [String] name The name of a project.
|
|
57
|
+
# @param [Hash] options A customizable set of options.
|
|
58
|
+
# @option options [String] :description The description of a project.
|
|
59
|
+
# @option options [String] :default_branch The default branch of a project.
|
|
60
|
+
# @option options [Boolean] :wiki_enabled The wiki integration for a project (0 = false, 1 = true).
|
|
61
|
+
# @option options [Boolean] :wall_enabled The wall functionality for a project (0 = false, 1 = true).
|
|
62
|
+
# @option options [Boolean] :issues_enabled The issues integration for a project (0 = false, 1 = true).
|
|
63
|
+
# @option options [Boolean] :snippets_enabled The snippets integration for a project (0 = false, 1 = true).
|
|
64
|
+
# @option options [Boolean] :merge_requests_enabled The merge requests functionality for a project (0 = false, 1 = true).
|
|
65
|
+
# @option options [Boolean] :public The setting for making a project public (0 = false, 1 = true).
|
|
66
|
+
# @option options [Integer] :user_id The user/owner id of a project.
|
|
67
|
+
# @return [Brat::ObjectifiedHash] Information about created project.
|
|
68
|
+
def create_project(name, options={})
|
|
69
|
+
url = options[:user_id] ? "/projects/user/#{options[:user_id]}" : "/projects"
|
|
70
|
+
post(url, :body => {:name => name}.merge(options))
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Deletes a project.
|
|
74
|
+
#
|
|
75
|
+
# @example
|
|
76
|
+
# Brat.delete_project(4)
|
|
77
|
+
#
|
|
78
|
+
# @param [Integer, String] id The ID or name of a project.
|
|
79
|
+
# @return [Brat::ObjectifiedHash] Information about deleted project.
|
|
80
|
+
def delete_project(id)
|
|
81
|
+
delete("/projects/#{id}")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# Gets a list of project team members.
|
|
85
|
+
#
|
|
86
|
+
# @example
|
|
87
|
+
# Brat.team_members(42)
|
|
88
|
+
# Brat.team_members('brat')
|
|
89
|
+
#
|
|
90
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
91
|
+
# @param [Hash] options A customizable set of options.
|
|
92
|
+
# @option options [String] :query The search query.
|
|
93
|
+
# @option options [Integer] :page The page number.
|
|
94
|
+
# @option options [Integer] :per_page The number of results per page.
|
|
95
|
+
# @return [Array<Brat::ObjectifiedHash>]
|
|
96
|
+
def team_members(project, options={})
|
|
97
|
+
get("/projects/#{project}/members", :query => options)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Gets a project team member.
|
|
101
|
+
#
|
|
102
|
+
# @example
|
|
103
|
+
# Brat.team_member('brat', 2)
|
|
104
|
+
#
|
|
105
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
106
|
+
# @param [Integer] id The ID of a project team member.
|
|
107
|
+
# @return [Brat::ObjectifiedHash]
|
|
108
|
+
def team_member(project, id)
|
|
109
|
+
get("/projects/#{project}/members/#{id}")
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Adds a user to project team.
|
|
113
|
+
#
|
|
114
|
+
# @example
|
|
115
|
+
# Brat.add_team_member('brat', 2, 40)
|
|
116
|
+
#
|
|
117
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
118
|
+
# @param [Integer] id The ID of a user.
|
|
119
|
+
# @param [Integer] access_level The access level to project.
|
|
120
|
+
# @param [Hash] options A customizable set of options.
|
|
121
|
+
# @return [Brat::ObjectifiedHash] Information about added team member.
|
|
122
|
+
def add_team_member(project, id, access_level)
|
|
123
|
+
post("/projects/#{project}/members", :body => {:user_id => id, :access_level => access_level})
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Updates a team member's project access level.
|
|
127
|
+
#
|
|
128
|
+
# @example
|
|
129
|
+
# Brat.edit_team_member('brat', 3, 20)
|
|
130
|
+
#
|
|
131
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
132
|
+
# @param [Integer] id The ID of a user.
|
|
133
|
+
# @param [Integer] access_level The access level to project.
|
|
134
|
+
# @param [Hash] options A customizable set of options.
|
|
135
|
+
# @return [Array<Brat::ObjectifiedHash>] Information about updated team member.
|
|
136
|
+
def edit_team_member(project, id, access_level)
|
|
137
|
+
put("/projects/#{project}/members/#{id}", :body => {:access_level => access_level})
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Removes a user from project team.
|
|
141
|
+
#
|
|
142
|
+
# @example
|
|
143
|
+
# Brat.remove_team_member('brat', 2)
|
|
144
|
+
#
|
|
145
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
146
|
+
# @param [Integer] id The ID of a user.
|
|
147
|
+
# @param [Hash] options A customizable set of options.
|
|
148
|
+
# @return [Brat::ObjectifiedHash] Information about removed team member.
|
|
149
|
+
def remove_team_member(project, id)
|
|
150
|
+
delete("/projects/#{project}/members/#{id}")
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# Gets a list of project hooks.
|
|
154
|
+
#
|
|
155
|
+
# @example
|
|
156
|
+
# Brat.project_hooks(42)
|
|
157
|
+
# Brat.project_hooks('brat')
|
|
158
|
+
#
|
|
159
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
160
|
+
# @param [Hash] options A customizable set of options.
|
|
161
|
+
# @option options [Integer] :page The page number.
|
|
162
|
+
# @option options [Integer] :per_page The number of results per page.
|
|
163
|
+
# @return [Array<Brat::ObjectifiedHash>]
|
|
164
|
+
def project_hooks(project, options={})
|
|
165
|
+
get("/projects/#{project}/hooks", :query => options)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# Gets a project hook.
|
|
169
|
+
#
|
|
170
|
+
# @example
|
|
171
|
+
# Brat.project_hook(42, 5)
|
|
172
|
+
# Brat.project_hook('brat', 5)
|
|
173
|
+
#
|
|
174
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
175
|
+
# @param [Integer] id The ID of a hook.
|
|
176
|
+
# @return [Brat::ObjectifiedHash]
|
|
177
|
+
def project_hook(project, id)
|
|
178
|
+
get("/projects/#{project}/hooks/#{id}")
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# Adds a new hook to the project.
|
|
182
|
+
#
|
|
183
|
+
# @example
|
|
184
|
+
# Brat.add_project_hook(42, 'https://api.example.net/v1/webhooks/ci')
|
|
185
|
+
#
|
|
186
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
187
|
+
# @param [String] url The hook URL.
|
|
188
|
+
# @param [Hash] options Events list (`{push_events: true, merge_requests_events: false}`).
|
|
189
|
+
# @return [Brat::ObjectifiedHash] Information about added hook.
|
|
190
|
+
def add_project_hook(project, url, options = {})
|
|
191
|
+
available_events = [:push_events, :merge_requests_events, :issues_events]
|
|
192
|
+
passed_events = available_events.select { |event| options[event] }
|
|
193
|
+
events = Hash[passed_events.map { |event| [event, options[event]] }]
|
|
194
|
+
|
|
195
|
+
post("/projects/#{project}/hooks", :body => {:url => url}.merge(events))
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# Updates a project hook URL.
|
|
199
|
+
#
|
|
200
|
+
# @example
|
|
201
|
+
# Brat.edit_project_hook(42, 1, 'https://api.example.net/v1/webhooks/ci')
|
|
202
|
+
#
|
|
203
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
204
|
+
# @param [Integer] id The ID of the hook.
|
|
205
|
+
# @param [String] url The hook URL.
|
|
206
|
+
# @return [Brat::ObjectifiedHash] Information about updated hook.
|
|
207
|
+
def edit_project_hook(project, id, url)
|
|
208
|
+
put("/projects/#{project}/hooks/#{id}", :body => {:url => url})
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# Deletes a hook from project.
|
|
212
|
+
#
|
|
213
|
+
# @example
|
|
214
|
+
# Brat.delete_project_hook('brat', 4)
|
|
215
|
+
#
|
|
216
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
217
|
+
# @param [String] id The ID of the hook.
|
|
218
|
+
# @return [Brat::ObjectifiedHash] Information about deleted hook.
|
|
219
|
+
def delete_project_hook(project, id)
|
|
220
|
+
delete("/projects/#{project}/hooks/#{id}")
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
# Mark this project as forked from the other
|
|
224
|
+
#
|
|
225
|
+
# @example
|
|
226
|
+
# Brat.make_forked(42, 24)
|
|
227
|
+
#
|
|
228
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
229
|
+
# @param [Integer] id The ID of the project it is forked from.
|
|
230
|
+
# @return [Brat::ObjectifiedHash] Information about the forked project.
|
|
231
|
+
def make_forked_from(project, id)
|
|
232
|
+
post("/projects/#{project}/fork/#{id}")
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
# Remove a forked_from relationship for a project.
|
|
236
|
+
#
|
|
237
|
+
# @example
|
|
238
|
+
# Brat.remove_forked(42)
|
|
239
|
+
#
|
|
240
|
+
# @param [Integer, String] project The ID or name of a project.
|
|
241
|
+
# @param [Integer] project The ID of the project it is forked from
|
|
242
|
+
# @return [Brat::ObjectifiedHash] Information about the forked project.
|
|
243
|
+
def remove_forked(project)
|
|
244
|
+
delete("/projects/#{project}/fork")
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# Gets a project deploy keys.
|
|
248
|
+
#
|
|
249
|
+
# @example
|
|
250
|
+
# Brat.deploy_keys(42)
|
|
251
|
+
#
|
|
252
|
+
# @param [Integer] project The ID of a project.
|
|
253
|
+
# @param [Hash] options A customizable set of options.
|
|
254
|
+
# @option options [Integer] :page The page number.
|
|
255
|
+
# @option options [Integer] :per_page The number of results per page.
|
|
256
|
+
# @return [Array<Brat::ObjectifiedHash>]
|
|
257
|
+
def deploy_keys(project, options={})
|
|
258
|
+
get("/projects/#{project}/keys", :query => options)
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# Gets a single project deploy key.
|
|
262
|
+
#
|
|
263
|
+
# @example
|
|
264
|
+
# Brat.deploy_key(42, 1)
|
|
265
|
+
#
|
|
266
|
+
# @param [Integer, String] project The ID of a project.
|
|
267
|
+
# @param [Integer] id The ID of a deploy key.
|
|
268
|
+
# @return [Brat::ObjectifiedHash]
|
|
269
|
+
def deploy_key(project, id)
|
|
270
|
+
get("/projects/#{project}/keys/#{id}")
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
# Creates a new deploy key.
|
|
274
|
+
#
|
|
275
|
+
# @example
|
|
276
|
+
# Brat.create_deploy_key(42, 'My Key', 'Key contents')
|
|
277
|
+
#
|
|
278
|
+
# @param [Integer] project The ID of a project.
|
|
279
|
+
# @param [String] title The title of a deploy key.
|
|
280
|
+
# @param [String] key The content of a deploy key.
|
|
281
|
+
# @return [Brat::ObjectifiedHash] Information about created deploy key.
|
|
282
|
+
def create_deploy_key(project, title, key)
|
|
283
|
+
post("/projects/#{project}/keys", body: {title: title, key: key})
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
# Deletes a deploy key from project.
|
|
287
|
+
#
|
|
288
|
+
# @example
|
|
289
|
+
# Brat.delete_deploy_key(42, 1)
|
|
290
|
+
#
|
|
291
|
+
# @param [Integer] project The ID of a project.
|
|
292
|
+
# @param [Integer] id The ID of a deploy key.
|
|
293
|
+
# @return [Brat::ObjectifiedHash] Information about deleted deploy key.
|
|
294
|
+
def delete_deploy_key(project, id)
|
|
295
|
+
delete("/projects/#{project}/keys/#{id}")
|
|
296
|
+
end
|
|
297
|
+
end
|
|
298
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
class Brat::Client
|
|
2
|
+
# Defines methods related to repositories.
|
|
3
|
+
module Repositories
|
|
4
|
+
# Gets a list of project repository tags.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# Brat.tags(42)
|
|
8
|
+
#
|
|
9
|
+
# @param [Integer] project The ID of a project.
|
|
10
|
+
# @param [Hash] options A customizable set of options.
|
|
11
|
+
# @option options [Integer] :page The page number.
|
|
12
|
+
# @option options [Integer] :per_page The number of results per page.
|
|
13
|
+
# @return [Array<Brat::ObjectifiedHash>]
|
|
14
|
+
def tags(project, options={})
|
|
15
|
+
get("/projects/#{project}/repository/tags", :query => options)
|
|
16
|
+
end
|
|
17
|
+
alias_method :repo_tags, :tags
|
|
18
|
+
|
|
19
|
+
# Creates a new project repository tag.
|
|
20
|
+
#
|
|
21
|
+
# @example
|
|
22
|
+
# Brat.create_tag(42,'new_tag','master'))
|
|
23
|
+
#
|
|
24
|
+
# @param [Integer] project The ID of a project.
|
|
25
|
+
# @param [String] tag_name The name of the new tag.
|
|
26
|
+
# @param [String] ref The ref (commit sha, branch name, or another tag) the tag will point to.
|
|
27
|
+
# @return [Brat::ObjectifiedHash]
|
|
28
|
+
def create_tag(project, tag_name, ref)
|
|
29
|
+
post("/projects/#{project}/repository/tags", body: {tag_name: tag_name, ref: ref})
|
|
30
|
+
end
|
|
31
|
+
alias_method :repo_create_tag, :create_tag
|
|
32
|
+
|
|
33
|
+
# Gets a list of project commits.
|
|
34
|
+
#
|
|
35
|
+
# @example
|
|
36
|
+
# Brat.commits('viking')
|
|
37
|
+
# Brat.repo_commits('brat', :ref_name => 'api')
|
|
38
|
+
#
|
|
39
|
+
# @param [Integer] project The ID of a project.
|
|
40
|
+
# @param [Hash] options A customizable set of options.
|
|
41
|
+
# @option options [String] :ref_name The branch or tag name of a project repository.
|
|
42
|
+
# @option options [Integer] :page The page number.
|
|
43
|
+
# @option options [Integer] :per_page The number of results per page.
|
|
44
|
+
# @return [Array<Brat::ObjectifiedHash>]
|
|
45
|
+
def commits(project, options={})
|
|
46
|
+
get("/projects/#{project}/repository/commits", :query => options)
|
|
47
|
+
end
|
|
48
|
+
alias_method :repo_commits, :commits
|
|
49
|
+
|
|
50
|
+
# Gets a specific commit identified by the commit hash or name of a branch or tag.
|
|
51
|
+
#
|
|
52
|
+
# @example
|
|
53
|
+
# Brat.commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
|
|
54
|
+
# Brat.repo_commit(3, 'ed899a2f4b50b4370feeea94676502b42383c746')
|
|
55
|
+
#
|
|
56
|
+
# @param [Integer] project The ID of a project.
|
|
57
|
+
# @param [String] sha The commit hash or name of a repository branch or tag
|
|
58
|
+
# @return [Brat::ObjectifiedHash]
|
|
59
|
+
def commit(project, sha)
|
|
60
|
+
get("/projects/#{project}/repository/commits/#{sha}")
|
|
61
|
+
end
|
|
62
|
+
alias_method :repo_commit, :commit
|
|
63
|
+
|
|
64
|
+
# Get the diff of a commit in a project.
|
|
65
|
+
#
|
|
66
|
+
# @example
|
|
67
|
+
# Brat.commit_diff(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
|
|
68
|
+
# Brat.repo_commit_diff(3, 'ed899a2f4b50b4370feeea94676502b42383c746')
|
|
69
|
+
#
|
|
70
|
+
# @param [Integer] project The ID of a project.
|
|
71
|
+
# @param [String] sha The name of a repository branch or tag or if not given the default branch.
|
|
72
|
+
# @return [Brat::ObjectifiedHash]
|
|
73
|
+
def commit_diff(project, sha)
|
|
74
|
+
get("/projects/#{project}/repository/commits/#{sha}/diff")
|
|
75
|
+
end
|
|
76
|
+
alias_method :repo_commit_diff, :commit_diff
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
class Brat::Client
|
|
2
|
+
# Defines methods related to snippets.
|
|
3
|
+
module Snippets
|
|
4
|
+
# Gets a list of project's snippets.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# Brat.snippets(42)
|
|
8
|
+
#
|
|
9
|
+
# @param [Integer] project The ID of a project.
|
|
10
|
+
# @param [Hash] options A customizable set of options.
|
|
11
|
+
# @option options [Integer] :page The page number.
|
|
12
|
+
# @option options [Integer] :per_page The number of results per page.
|
|
13
|
+
# @return [Brat::ObjectifiedHash]
|
|
14
|
+
def snippets(project, options={})
|
|
15
|
+
get("/projects/#{project}/snippets", :query => options)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Gets information about a snippet.
|
|
19
|
+
#
|
|
20
|
+
# @example
|
|
21
|
+
# Brat.snippet(2, 14)
|
|
22
|
+
#
|
|
23
|
+
# @param [Integer] project The ID of a project.
|
|
24
|
+
# @param [Integer] id The ID of a snippet.
|
|
25
|
+
# @return [Brat::ObjectifiedHash]
|
|
26
|
+
def snippet(project, id)
|
|
27
|
+
get("/projects/#{project}/snippets/#{id}")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Creates a new snippet.
|
|
31
|
+
#
|
|
32
|
+
# @example
|
|
33
|
+
# Brat.create_snippet(42, {:title => 'REST', :file_name => 'api.rb', :code => 'some code'})
|
|
34
|
+
#
|
|
35
|
+
# @param [Integer] project The ID of a project.
|
|
36
|
+
# @param [Hash] options A customizable set of options.
|
|
37
|
+
# @option options [String] :title (required) The title of a snippet.
|
|
38
|
+
# @option options [String] :file_name (required) The name of a snippet file.
|
|
39
|
+
# @option options [String] :code (required) The content of a snippet.
|
|
40
|
+
# @option options [String] :lifetime (optional) The expiration date of a snippet.
|
|
41
|
+
# @return [Brat::ObjectifiedHash] Information about created snippet.
|
|
42
|
+
def create_snippet(project, options={})
|
|
43
|
+
check_attributes!(options, [:title, :file_name, :code])
|
|
44
|
+
post("/projects/#{project}/snippets", :body => options)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Updates a snippet.
|
|
48
|
+
#
|
|
49
|
+
# @example
|
|
50
|
+
# Brat.edit_snippet(42, 34, :file_name => 'README.txt')
|
|
51
|
+
#
|
|
52
|
+
# @param [Integer] project The ID of a project.
|
|
53
|
+
# @param [Integer] id The ID of a snippet.
|
|
54
|
+
# @param [Hash] options A customizable set of options.
|
|
55
|
+
# @option options [String] :title The title of a snippet.
|
|
56
|
+
# @option options [String] :file_name The name of a snippet file.
|
|
57
|
+
# @option options [String] :code The content of a snippet.
|
|
58
|
+
# @option options [String] :lifetime The expiration date of a snippet.
|
|
59
|
+
# @return [Brat::ObjectifiedHash] Information about updated snippet.
|
|
60
|
+
def edit_snippet(project, id, options={})
|
|
61
|
+
put("/projects/#{project}/snippets/#{id}", :body => options)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Deletes a snippet.
|
|
65
|
+
#
|
|
66
|
+
# @example
|
|
67
|
+
# Brat.delete_snippet(2, 14)
|
|
68
|
+
#
|
|
69
|
+
# @param [Integer] project The ID of a project.
|
|
70
|
+
# @param [Integer] id The ID of a snippet.
|
|
71
|
+
# @return [Brat::ObjectifiedHash] Information about deleted snippet.
|
|
72
|
+
def delete_snippet(project, id)
|
|
73
|
+
delete("/projects/#{project}/snippets/#{id}")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def check_attributes!(options, attrs)
|
|
79
|
+
attrs.each do |attr|
|
|
80
|
+
unless options.has_key?(attr) || options.has_key?(attr.to_s)
|
|
81
|
+
raise Brat::Error::MissingAttributes.new("Missing '#{attr}' parameter")
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|