Skip to content

Commit

Permalink
Merge branch 'extend-events-api'
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaporozhets committed Dec 4, 2015
2 parents 1f5a6eb + 3227a5e commit 4de7f32
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ v 8.3.0 (unreleased)
- Fire update hook from GitLab
- Don't show project fork event as "imported"
- Add API endpoint to fetch merge request commits list
- Expose events API with comment information and author info

v 8.2.2
- Fix 404 in redirection after removing a project (Stan Hu)
Expand Down
15 changes: 12 additions & 3 deletions doc/api/notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ Parameters:
"created_at": "2013-10-02T09:22:45Z",
"system": true,
"upvote": false,
"downvote": false
"downvote": false,
"noteable_id": 377,
"noteable_type": "Issue"
},
{
"id": 305,
Expand All @@ -52,7 +54,9 @@ Parameters:
"created_at": "2013-10-02T09:56:03Z",
"system": true,
"upvote": false,
"downvote": false
"downvote": false,
"noteable_id": 121,
"noteable_type": "Issue"
}
]
```
Expand Down Expand Up @@ -219,7 +223,12 @@ Parameters:
"state": "active",
"created_at": "2013-09-30T13:46:01Z"
},
"created_at": "2013-10-02T08:57:14Z"
"created_at": "2013-10-02T08:57:14Z",
"system": false,
"upvote": false,
"downvote": false,
"noteable_id": 2,
"noteable_type": "MergeRequest"
}
```

Expand Down
71 changes: 67 additions & 4 deletions doc/api/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,17 @@ Parameters:
"target_id": 830,
"target_type": "Issue",
"author_id": 1,
"author_username": "john",
"data": null,
"target_title": "Public project search field"
"target_title": "Public project search field",
"author": {
"name": "Dmitriy Zaporozhets",
"username": "root",
"id": 1,
"state": "active",
"avatar_url": "http://localhost:3000/uploads/user/avatar/1/fox_avatar.png",
"web_url": "http://localhost:3000/u/root"
},
"author_username": "root"
},
{
"title": null,
Expand All @@ -256,6 +264,14 @@ Parameters:
"target_id": null,
"target_type": null,
"author_id": 1,
"author": {
"name": "Dmitriy Zaporozhets",
"username": "root",
"id": 1,
"state": "active",
"avatar_url": "http://localhost:3000/uploads/user/avatar/1/fox_avatar.png",
"web_url": "http://localhost:3000/u/root"
},
"author_username": "john",
"data": {
"before": "50d4420237a9de7be1304607147aec22e4a14af7",
Expand Down Expand Up @@ -292,9 +308,56 @@ Parameters:
"target_id": 840,
"target_type": "Issue",
"author_id": 1,
"author_username": "john",
"data": null,
"target_title": "Finish & merge Code search PR"
"target_title": "Finish & merge Code search PR",
"author": {
"name": "Dmitriy Zaporozhets",
"username": "root",
"id": 1,
"state": "active",
"avatar_url": "http://localhost:3000/uploads/user/avatar/1/fox_avatar.png",
"web_url": "http://localhost:3000/u/root"
},
"author_username": "root"
},
{
"title": null,
"project_id": 15,
"action_name": "commented on",
"target_id": 1312,
"target_type": "Note",
"author_id": 1,
"data": null,
"target_title": null,
"created_at": "2015-12-04T10:33:58.089Z",
"note": {
"id": 1312,
"body": "What an awesome day!",
"attachment": null,
"author": {
"name": "Dmitriy Zaporozhets",
"username": "root",
"id": 1,
"state": "active",
"avatar_url": "http://localhost:3000/uploads/user/avatar/1/fox_avatar.png",
"web_url": "http://localhost:3000/u/root"
},
"created_at": "2015-12-04T10:33:56.698Z",
"system": false,
"upvote": false,
"downvote": false,
"noteable_id": 377,
"noteable_type": "Issue"
},
"author": {
"name": "Dmitriy Zaporozhets",
"username": "root",
"id": 1,
"state": "active",
"avatar_url": "http://localhost:3000/uploads/user/avatar/1/fox_avatar.png",
"web_url": "http://localhost:3000/u/root"
},
"author_username": "root"
}
]
```
Expand Down
3 changes: 3 additions & 0 deletions lib/api/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class Note < Grape::Entity
expose :author, using: Entities::UserBasic
expose :created_at
expose :system?, as: :system
expose :noteable_id, :noteable_type
# upvote? and downvote? are deprecated, always return false
expose :upvote?, as: :upvote
expose :downvote?, as: :downvote
Expand Down Expand Up @@ -224,6 +225,8 @@ class Event < Grape::Entity
expose :target_id, :target_type, :author_id
expose :data, :target_title
expose :created_at
expose :note, using: Entities::Note, if: ->(event, options) { event.note? }
expose :author, using: Entities::UserBasic, if: ->(event, options) { event.author }

expose :author_username do |event, options|
if event.author
Expand Down
30 changes: 23 additions & 7 deletions spec/requests/api/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,30 @@
describe 'GET /projects/:id/events' do
before { project_member2 }

it 'should return a project events' do
get api("/projects/#{project.id}/events", user)
expect(response.status).to eq(200)
json_event = json_response.first
context 'valid request' do
before do
note = create(:note_on_issue, note: 'What an awesome day!', project: project)
EventCreateService.new.leave_note(note, note.author)
get api("/projects/#{project.id}/events", user)
end

it { expect(response.status).to eq(200) }

context 'joined event' do
let(:json_event) { json_response[1] }

expect(json_event['action_name']).to eq('joined')
expect(json_event['project_id'].to_i).to eq(project.id)
expect(json_event['author_username']).to eq(user3.username)
it { expect(json_event['action_name']).to eq('joined') }
it { expect(json_event['project_id'].to_i).to eq(project.id) }
it { expect(json_event['author_username']).to eq(user3.username) }
it { expect(json_event['author']['name']).to eq(user3.name) }
end

context 'comment event' do
let(:json_event) { json_response.first }

it { expect(json_event['action_name']).to eq('commented on') }
it { expect(json_event['note']['body']).to eq('What an awesome day!') }
end
end

it 'should return a 404 error if not found' do
Expand Down

0 comments on commit 4de7f32

Please sign in to comment.