Commit 3227a5ea authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Extent Event and Note API

* add note to Events API
* add author section to Events API
* add noteable_id and noteable_type to Notes API
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 0ccd7de7
...@@ -7,6 +7,7 @@ v 8.3.0 (unreleased) ...@@ -7,6 +7,7 @@ v 8.3.0 (unreleased)
- Add ignore whitespace change option to commit view - Add ignore whitespace change option to commit view
- Fire update hook from GitLab - Fire update hook from GitLab
- Don't show project fork event as "imported" - Don't show project fork event as "imported"
- Expose events API with comment information and author info
v 8.2.2 v 8.2.2
- Fix 404 in redirection after removing a project (Stan Hu) - Fix 404 in redirection after removing a project (Stan Hu)
......
...@@ -35,7 +35,9 @@ Parameters: ...@@ -35,7 +35,9 @@ Parameters:
"created_at": "2013-10-02T09:22:45Z", "created_at": "2013-10-02T09:22:45Z",
"system": true, "system": true,
"upvote": false, "upvote": false,
"downvote": false "downvote": false,
"noteable_id": 377,
"noteable_type": "Issue"
}, },
{ {
"id": 305, "id": 305,
...@@ -52,7 +54,9 @@ Parameters: ...@@ -52,7 +54,9 @@ Parameters:
"created_at": "2013-10-02T09:56:03Z", "created_at": "2013-10-02T09:56:03Z",
"system": true, "system": true,
"upvote": false, "upvote": false,
"downvote": false "downvote": false,
"noteable_id": 121,
"noteable_type": "Issue"
} }
] ]
``` ```
...@@ -219,7 +223,12 @@ Parameters: ...@@ -219,7 +223,12 @@ Parameters:
"state": "active", "state": "active",
"created_at": "2013-09-30T13:46:01Z" "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"
} }
``` ```
......
...@@ -245,9 +245,17 @@ Parameters: ...@@ -245,9 +245,17 @@ Parameters:
"target_id": 830, "target_id": 830,
"target_type": "Issue", "target_type": "Issue",
"author_id": 1, "author_id": 1,
"author_username": "john",
"data": null, "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, "title": null,
...@@ -256,6 +264,14 @@ Parameters: ...@@ -256,6 +264,14 @@ Parameters:
"target_id": null, "target_id": null,
"target_type": null, "target_type": null,
"author_id": 1, "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", "author_username": "john",
"data": { "data": {
"before": "50d4420237a9de7be1304607147aec22e4a14af7", "before": "50d4420237a9de7be1304607147aec22e4a14af7",
...@@ -292,9 +308,56 @@ Parameters: ...@@ -292,9 +308,56 @@ Parameters:
"target_id": 840, "target_id": 840,
"target_type": "Issue", "target_type": "Issue",
"author_id": 1, "author_id": 1,
"author_username": "john",
"data": null, "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"
} }
] ]
``` ```
......
...@@ -194,6 +194,7 @@ module API ...@@ -194,6 +194,7 @@ module API
expose :author, using: Entities::UserBasic expose :author, using: Entities::UserBasic
expose :created_at expose :created_at
expose :system?, as: :system expose :system?, as: :system
expose :noteable_id, :noteable_type
# upvote? and downvote? are deprecated, always return false # upvote? and downvote? are deprecated, always return false
expose :upvote?, as: :upvote expose :upvote?, as: :upvote
expose :downvote?, as: :downvote expose :downvote?, as: :downvote
...@@ -224,6 +225,8 @@ module API ...@@ -224,6 +225,8 @@ module API
expose :target_id, :target_type, :author_id expose :target_id, :target_type, :author_id
expose :data, :target_title expose :data, :target_title
expose :created_at 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| expose :author_username do |event, options|
if event.author if event.author
......
...@@ -389,14 +389,30 @@ describe API::API, api: true do ...@@ -389,14 +389,30 @@ describe API::API, api: true do
describe 'GET /projects/:id/events' do describe 'GET /projects/:id/events' do
before { project_member2 } before { project_member2 }
it 'should return a project events' do 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) get api("/projects/#{project.id}/events", user)
expect(response.status).to eq(200) end
json_event = json_response.first
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') it { expect(json_event['action_name']).to eq('joined') }
expect(json_event['project_id'].to_i).to eq(project.id) it { expect(json_event['project_id'].to_i).to eq(project.id) }
expect(json_event['author_username']).to eq(user3.username) 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 end
it 'should return a 404 error if not found' do it 'should return a 404 error if not found' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment