Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/api/events.md2
-rw-r--r--lib/api/events.rb4
-rw-r--r--spec/requests/api/events_spec.rb9
3 files changed, 12 insertions, 3 deletions
diff --git a/doc/api/events.md b/doc/api/events.md
index ef57287264d..e7829c9f479 100644
--- a/doc/api/events.md
+++ b/doc/api/events.md
@@ -129,7 +129,7 @@ Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
-| `id` | integer | yes | The ID of the user |
+| `id` | integer | yes | The ID or Username of the user |
| `action` | string | no | Include only events of a particular [action type][action-types] |
| `target_type` | string | no | Include only events of a particular [target type][target-types] |
| `before` | date | no | Include only events created before a particular date. Please see [here for the supported format][date-formatting] |
diff --git a/lib/api/events.rb b/lib/api/events.rb
index ed5df268ae3..dabdf579119 100644
--- a/lib/api/events.rb
+++ b/lib/api/events.rb
@@ -42,7 +42,7 @@ module API
end
params do
- requires :id, type: Integer, desc: 'The ID of the user'
+ requires :id, type: String, desc: 'The ID or Username of the user'
end
resource :users do
desc 'Get the contribution events of a specified user' do
@@ -55,7 +55,7 @@ module API
use :sort_params
end
get ':id/events' do
- user = User.find_by(id: params[:id])
+ user = find_user(params[:id])
not_found!('User') unless user
events = EventsFinder.new(params.merge(source: user, current_user: current_user)).execute.preload(:author, :target)
diff --git a/spec/requests/api/events_spec.rb b/spec/requests/api/events_spec.rb
index 51e72c39a30..a19870a95e8 100644
--- a/spec/requests/api/events_spec.rb
+++ b/spec/requests/api/events_spec.rb
@@ -41,6 +41,15 @@ describe API::Events, api: true do
end
context "as a user that can see the event's project" do
+ it 'accepts a username' do
+ get api("/users/#{user.username}/events", user)
+
+ expect(response).to have_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(json_response).to be_an Array
+ expect(json_response.size).to eq(1)
+ end
+
it 'returns the events' do
get api("/users/#{user.id}/events", user)