From 00a49eb0adcef1731db47e6074d3b6d19473e449 Mon Sep 17 00:00:00 2001 From: Piotr Skorupa Date: Fri, 4 Apr 2025 08:11:51 +0200 Subject: [PATCH 1/3] Fix 500 in Todo API when wiki page todo exists Changelog: fixed --- doc/api/todos.md | 2 +- lib/api/entities/wiki_page/meta.rb | 11 +++++++++++ spec/requests/api/todos_spec.rb | 30 +++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 lib/api/entities/wiki_page/meta.rb diff --git a/doc/api/todos.md b/doc/api/todos.md index 5d9d0380fc1f11..971ad2708bbc5f 100644 --- a/doc/api/todos.md +++ b/doc/api/todos.md @@ -33,7 +33,7 @@ Parameters: | `project_id` | integer | no | The ID of a project | | `group_id` | integer | no | The ID of a group | | `state` | string | no | The state of the to-do item. Can be either `pending` or `done` | -| `type` | string | no | The type of to-do item. Can be either `Issue`, `MergeRequest`, `Commit`, `Epic`, `DesignManagement::Design`, `AlertManagement::Alert`, `Project`, `Namespace` or `Vulnerability` | +| `type` | string | no | The type of to-do item. Can be either `Issue`, `MergeRequest`, `Commit`, `Epic`, `DesignManagement::Design`, `AlertManagement::Alert`, `Project`, `Namespace`, `Vulnerability` or `WikiPage::Meta` | ```shell curl --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/todos" diff --git a/lib/api/entities/wiki_page/meta.rb b/lib/api/entities/wiki_page/meta.rb new file mode 100644 index 00000000000000..80235f3c99f2a2 --- /dev/null +++ b/lib/api/entities/wiki_page/meta.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module API + module Entities + class WikiPage::Meta < Grape::Entity + expose :id, documentation: { type: 'integer', example: 2 } + expose :canonical_slug, as: :slug, documentation: { type: 'string', example: 'home' } + expose :title, documentation: { type: 'string', example: 'Page title' } + end + end +end diff --git a/spec/requests/api/todos_spec.rb b/spec/requests/api/todos_spec.rb index 3bc1feaced9cc7..cb08a147a81cb3 100644 --- a/spec/requests/api/todos_spec.rb +++ b/spec/requests/api/todos_spec.rb @@ -20,6 +20,8 @@ let_it_be(:group_request_todo) { create(:todo, author: author_1, user: john_doe, project: nil, group: group_2, target: group_2, action: Todo::MEMBER_ACCESS_REQUESTED) } let_it_be(:alert_todo) { create(:todo, project: project_1, author: john_doe, user: john_doe, target: alert) } let_it_be(:merge_request_todo) { create(:todo, project: project_1, author: author_2, user: john_doe, target: merge_request) } + let_it_be(:wiki_page_meta) { create(:wiki_page_meta, :for_wiki_page, container: project_1) } + let_it_be(:wiki_page_todo) { create(:todo, project: project_1, author: author_2, user: john_doe, target: wiki_page_meta, action: Todo::MENTIONED) } let_it_be(:pending_1) { create(:todo, :mentioned, project: project_1, author: author_1, user: john_doe, target: issue) } let_it_be(:pending_2) { create(:todo, project: project_2, author: author_2, user: john_doe, target: create(:issue, project: project_2)) } let_it_be(:pending_3) { create(:on_commit_todo, project: project_1, author: author_2, user: john_doe) } @@ -69,7 +71,7 @@ expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.length).to eq(8) + expect(json_response.length).to eq(9) expect(json_response[0]).to include( 'id' => pending_5.id, @@ -108,9 +110,19 @@ ) ) - # Only issues get a merge request count at the moment - expect(json_response[4].dig('target', 'merge_requests_count')).to be_nil expect(json_response[4]).to include( + 'target_type' => 'WikiPage::Meta', + 'action_name' => 'mentioned', + 'target' => hash_including( + 'id' => wiki_page_meta.id, + 'title' => wiki_page_meta.title, + 'slug' => wiki_page_meta.canonical_slug + ) + ) + + # Only issues get a merge request count at the moment + expect(json_response[5].dig('target', 'merge_requests_count')).to be_nil + expect(json_response[5]).to include( 'target_type' => 'MergeRequest', 'target' => hash_including( 'upvotes' => 1, @@ -118,7 +130,7 @@ ) ) - expect(json_response[5]).to include( + expect(json_response[6]).to include( 'target_type' => 'AlertManagement::Alert', 'target' => hash_including( 'iid' => alert.iid, @@ -126,7 +138,7 @@ ) ) - expect(json_response[6]).to include( + expect(json_response[7]).to include( 'target_type' => 'Namespace', 'action_name' => 'member_access_requested', 'target' => hash_including( @@ -137,7 +149,7 @@ 'target_url' => Gitlab::Routing.url_helpers.group_group_members_url(group_2, tab: 'access_requests') ) - expect(json_response[7]).to include( + expect(json_response[8]).to include( 'target_type' => 'Project', 'action_name' => 'member_access_requested', 'target' => hash_including( @@ -158,7 +170,7 @@ get api('/todos', john_doe) - expect(json_response.count).to eq(8) + expect(json_response.count).to eq(9) expect(json_response.map { |t| t['id'] }).not_to include(no_access_todo.id, pending_4.id) end end @@ -170,7 +182,7 @@ expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.length).to eq(3) + expect(json_response.length).to eq(4) end end @@ -216,7 +228,7 @@ expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.length).to eq(5) + expect(json_response.length).to eq(6) end end -- GitLab From 3c865d048b0d13632711904be3aafa641abe7080 Mon Sep 17 00:00:00 2001 From: Piotr Skorupa Date: Fri, 4 Apr 2025 19:39:05 +0200 Subject: [PATCH 2/3] Update spec for mentioned todo action filter --- .rubocop_todo/rspec/multiple_memoized_helpers.yml | 1 + spec/requests/api/todos_spec.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.rubocop_todo/rspec/multiple_memoized_helpers.yml b/.rubocop_todo/rspec/multiple_memoized_helpers.yml index 3bbe5778d2fd39..e6072e5ec50d26 100644 --- a/.rubocop_todo/rspec/multiple_memoized_helpers.yml +++ b/.rubocop_todo/rspec/multiple_memoized_helpers.yml @@ -25,6 +25,7 @@ RSpec/MultipleMemoizedHelpers: - 'spec/requests/api/issues/issues_spec.rb' - 'spec/requests/api/issues/put_projects_issues_spec.rb' - 'spec/requests/api/maven_packages_spec.rb' + - 'spec/requests/api/todos_spec.rb' - 'spec/requests/api/users_spec.rb' - 'spec/services/boards/issues/list_service_spec.rb' - 'spec/services/labels/promote_service_spec.rb' diff --git a/spec/requests/api/todos_spec.rb b/spec/requests/api/todos_spec.rb index cb08a147a81cb3..e4439557ef746e 100644 --- a/spec/requests/api/todos_spec.rb +++ b/spec/requests/api/todos_spec.rb @@ -239,7 +239,7 @@ expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.length).to eq(2) + expect(json_response.length).to eq(3) end end end -- GitLab From fb30a907fea121d798fe49bdb67f918a186c3cc2 Mon Sep 17 00:00:00 2001 From: Piotr Skorupa Date: Tue, 8 Apr 2025 22:12:40 +0200 Subject: [PATCH 3/3] Change WikiPage::Meta entity to nested classes --- lib/api/entities/wiki_page/meta.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/api/entities/wiki_page/meta.rb b/lib/api/entities/wiki_page/meta.rb index 80235f3c99f2a2..6f82eca3350a8f 100644 --- a/lib/api/entities/wiki_page/meta.rb +++ b/lib/api/entities/wiki_page/meta.rb @@ -2,10 +2,12 @@ module API module Entities - class WikiPage::Meta < Grape::Entity - expose :id, documentation: { type: 'integer', example: 2 } - expose :canonical_slug, as: :slug, documentation: { type: 'string', example: 'home' } - expose :title, documentation: { type: 'string', example: 'Page title' } + class WikiPage + class Meta < Grape::Entity + expose :id, documentation: { type: 'integer', example: 2 } + expose :canonical_slug, as: :slug, documentation: { type: 'string', example: 'home' } + expose :title, documentation: { type: 'string', example: 'Page title' } + end end end end -- GitLab