Commit 8df699a336af347628f83274b1eb11255f353e9e
1 parent
543506f3
Exists in
master
and in
4 other branches
API: project events
Showing
5 changed files
with
115 additions
and
1 deletions
Show diff stats
app/models/event.rb
doc/api/projects.md
... | ... | @@ -77,6 +77,7 @@ Parameters: |
77 | 77 | { |
78 | 78 | "id": 5, |
79 | 79 | "name": "gitlab", |
80 | + "name_with_namespace": "GitLab / gitlabhq", | |
80 | 81 | "description": null, |
81 | 82 | "default_branch": "api", |
82 | 83 | "owner": { |
... | ... | @@ -99,6 +100,74 @@ Parameters: |
99 | 100 | } |
100 | 101 | ``` |
101 | 102 | |
103 | +### Get project events | |
104 | + | |
105 | +Get a project events for specific project. | |
106 | +Sorted from newest to latest | |
107 | + | |
108 | +``` | |
109 | +GET /projects/:id/events | |
110 | +``` | |
111 | + | |
112 | +Parameters: | |
113 | + | |
114 | ++ `id` (required) - The ID or NAME of a project | |
115 | + | |
116 | +```json | |
117 | + | |
118 | +[{ | |
119 | + "title": null, | |
120 | + "project_id": 15, | |
121 | + "action_name": "closed", | |
122 | + "target_id": 830, | |
123 | + "target_type": "Issue", | |
124 | + "author_id": 1, | |
125 | + "data": null, | |
126 | + "target_title": "Public project search field" | |
127 | +}, { | |
128 | + "title": null, | |
129 | + "project_id": 15, | |
130 | + "action_name": "opened", | |
131 | + "target_id": null, | |
132 | + "target_type": null, | |
133 | + "author_id": 1, | |
134 | + "data": { | |
135 | + "before": "50d4420237a9de7be1304607147aec22e4a14af7", | |
136 | + "after": "c5feabde2d8cd023215af4d2ceeb7a64839fc428", | |
137 | + "ref": "refs/heads/master", | |
138 | + "user_id": 1, | |
139 | + "user_name": "Dmitriy Zaporozhets", | |
140 | + "repository": { | |
141 | + "name": "gitlabhq", | |
142 | + "url": "git@dev.gitlab.org:gitlab/gitlabhq.git", | |
143 | + "description": "GitLab: self hosted Git management software. \r\nDistributed under the MIT License.", | |
144 | + "homepage": "https://dev.gitlab.org/gitlab/gitlabhq" | |
145 | + }, | |
146 | + "commits": [{ | |
147 | + "id": "c5feabde2d8cd023215af4d2ceeb7a64839fc428", | |
148 | + "message": "Add simple search to projects in public area", | |
149 | + "timestamp": "2013-05-13T18:18:08+00:00", | |
150 | + "url": "https://dev.gitlab.org/gitlab/gitlabhq/commit/c5feabde2d8cd023215af4d2ceeb7a64839fc428", | |
151 | + "author": { | |
152 | + "name": "Dmitriy Zaporozhets", | |
153 | + "email": "dmitriy.zaporozhets@gmail.com" | |
154 | + } | |
155 | + }], | |
156 | + "total_commits_count": 1 | |
157 | + }, | |
158 | + "target_title": null | |
159 | +}, { | |
160 | + "title": null, | |
161 | + "project_id": 15, | |
162 | + "action_name": "closed", | |
163 | + "target_id": 840, | |
164 | + "target_type": "Issue", | |
165 | + "author_id": 1, | |
166 | + "data": null, | |
167 | + "target_title": "Finish & merge Code search PR" | |
168 | +}] | |
169 | +``` | |
170 | + | |
102 | 171 | |
103 | 172 | ### Create project |
104 | 173 | ... | ... |
lib/api/entities.rb
... | ... | @@ -120,5 +120,11 @@ module API |
120 | 120 | expose :note |
121 | 121 | expose :author, using: Entities::UserBasic |
122 | 122 | end |
123 | + | |
124 | + class Event < Grape::Entity | |
125 | + expose :title, :project_id, :action_name | |
126 | + expose :target_id, :target_type, :author_id | |
127 | + expose :data, :target_title | |
128 | + end | |
123 | 129 | end |
124 | 130 | end | ... | ... |
lib/api/projects.rb
... | ... | @@ -41,6 +41,20 @@ module API |
41 | 41 | present user_project, with: Entities::Project |
42 | 42 | end |
43 | 43 | |
44 | + # Get a single project events | |
45 | + # | |
46 | + # Parameters: | |
47 | + # id (required) - The ID of a project | |
48 | + # Example Request: | |
49 | + # GET /projects/:id | |
50 | + get ":id/events" do | |
51 | + limit = (params[:per_page] || 20).to_i | |
52 | + offset = (params[:page] || 0).to_i * limit | |
53 | + events = user_project.events.recent.limit(limit).offset(offset) | |
54 | + | |
55 | + present events, with: Entities::Event | |
56 | + end | |
57 | + | |
44 | 58 | # Create new project |
45 | 59 | # |
46 | 60 | # Parameters: | ... | ... |
spec/requests/api/projects_spec.rb
... | ... | @@ -173,6 +173,29 @@ describe API::API do |
173 | 173 | end |
174 | 174 | end |
175 | 175 | |
176 | + describe "GET /projects/:id/events" do | |
177 | + it "should return a project events" do | |
178 | + get api("/projects/#{project.id}/events", user) | |
179 | + response.status.should == 200 | |
180 | + json_event = json_response.first | |
181 | + | |
182 | + json_event['action_name'].should == 'joined' | |
183 | + json_event['project_id'].to_i.should == project.id | |
184 | + end | |
185 | + | |
186 | + it "should return a 404 error if not found" do | |
187 | + get api("/projects/42/events", user) | |
188 | + response.status.should == 404 | |
189 | + json_response['message'].should == '404 Not Found' | |
190 | + end | |
191 | + | |
192 | + it "should return a 404 error if user is not a member" do | |
193 | + other_user = create(:user) | |
194 | + get api("/projects/#{project.id}/events", other_user) | |
195 | + response.status.should == 404 | |
196 | + end | |
197 | + end | |
198 | + | |
176 | 199 | describe "GET /projects/:id/members" do |
177 | 200 | it "should return project team members" do |
178 | 201 | get api("/projects/#{project.id}/members", user) | ... | ... |