diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-26 00:09:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-26 00:09:20 +0300 |
commit | 7625bc732c8b330989913fd933e6e94ecd4a1957 (patch) | |
tree | 6142552413072c5eeecbeaef2107d5c469a203bc /lib/api/discussions.rb | |
parent | 0351d9ed83635ce3258e2d09ba92b46a7cdcfa61 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api/discussions.rb')
-rw-r--r-- | lib/api/discussions.rb | 95 |
1 files changed, 51 insertions, 44 deletions
diff --git a/lib/api/discussions.rb b/lib/api/discussions.rb index f73e4b621ab..d3a25a076a0 100644 --- a/lib/api/discussions.rb +++ b/lib/api/discussions.rb @@ -18,17 +18,19 @@ module API Helpers::DiscussionsHelpers.feature_category_per_noteable_type.each do |noteable_type, feature_category| parent_type = noteable_type.parent_class.to_s.underscore noteables_str = noteable_type.to_s.underscore.pluralize + notable_name = noteable_type.to_s.underscore.humanize.downcase + notable_id_type = noteable_type == Commit ? String : Integer noteables_path = noteable_type == Commit ? "repository/#{noteables_str}" : noteables_str params do requires :id, type: String, desc: "The ID of a #{parent_type}" end resource parent_type.pluralize.to_sym, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do - desc "Get a list of #{noteable_type.to_s.downcase} discussions" do + desc "Get a list of #{notable_name} discussions" do success Entities::Discussion end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' + requires :noteable_id, type: notable_id_type, desc: "The ID of the #{notable_name}" use :pagination end @@ -41,12 +43,12 @@ module API present Discussion.build_collection(notes, noteable), with: Entities::Discussion end - desc "Get a single #{noteable_type.to_s.downcase} discussion" do + desc "Get a single #{notable_name} discussion" do success Entities::Discussion end params do requires :discussion_id, type: String, desc: 'The ID of a discussion' - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' + requires :noteable_id, type: notable_id_type, desc: "The ID of the #{notable_name}" end get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id", feature_category: feature_category do noteable = find_noteable(noteable_type, params[:noteable_id]) @@ -61,39 +63,44 @@ module API present discussion, with: Entities::Discussion end - desc "Create a new #{noteable_type.to_s.downcase} discussion" do + desc "Create a new #{notable_name} discussion" do success Entities::Discussion end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' + requires :noteable_id, type: notable_id_type, desc: "The ID of the #{notable_name}" requires :body, type: String, desc: 'The content of a note' optional :created_at, type: String, desc: 'The creation date of the note' - optional :position, type: Hash do - requires :base_sha, type: String, desc: 'Base commit SHA in the source branch' - requires :start_sha, type: String, desc: 'SHA referencing commit in target branch' - requires :head_sha, type: String, desc: 'SHA referencing HEAD of this merge request' - requires :position_type, type: String, desc: 'Type of the position reference', values: %w(text image) - optional :new_path, type: String, desc: 'File path after change' - optional :new_line, type: Integer, desc: 'Line number after change' - optional :old_path, type: String, desc: 'File path before change' - optional :old_line, type: Integer, desc: 'Line number before change' - optional :width, type: Integer, desc: 'Width of the image' - optional :height, type: Integer, desc: 'Height of the image' - optional :x, type: Integer, desc: 'X coordinate in the image' - optional :y, type: Integer, desc: 'Y coordinate in the image' - - optional :line_range, type: Hash, desc: 'Multi-line start and end' do - optional :start, type: Hash do - optional :line_code, type: String, desc: 'Start line code for multi-line note' - optional :type, type: String, desc: 'Start line type for multi-line note' - optional :old_line, type: String, desc: 'Start old_line line number' - optional :new_line, type: String, desc: 'Start new_line line number' - end - optional :end, type: Hash do - optional :line_code, type: String, desc: 'End line code for multi-line note' - optional :type, type: String, desc: 'End line type for multi-line note' - optional :old_line, type: String, desc: 'End old_line line number' - optional :new_line, type: String, desc: 'End new_line line number' + + if [Commit, MergeRequest].include?(noteable_type) + optional :position, type: Hash do + requires :base_sha, type: String, desc: 'Base commit SHA in the source branch' + requires :start_sha, type: String, desc: 'SHA referencing commit in target branch' + requires :head_sha, type: String, desc: 'SHA referencing HEAD of this merge request' + requires :position_type, type: String, desc: 'Type of the position reference', values: %w(text image) + optional :new_path, type: String, desc: 'File path after change' + optional :new_line, type: Integer, desc: 'Line number after change' + optional :old_path, type: String, desc: 'File path before change' + optional :old_line, type: Integer, desc: 'Line number before change' + optional :width, type: Integer, desc: 'Width of the image' + optional :height, type: Integer, desc: 'Height of the image' + optional :x, type: Integer, desc: 'X coordinate in the image' + optional :y, type: Integer, desc: 'Y coordinate in the image' + + if noteable_type == MergeRequest + optional :line_range, type: Hash, desc: 'Multi-line start and end' do + optional :start, type: Hash do + optional :line_code, type: String, desc: 'Start line code for multi-line note' + optional :type, type: String, desc: 'Start line type for multi-line note' + optional :old_line, type: String, desc: 'Start old_line line number' + optional :new_line, type: String, desc: 'Start new_line line number' + end + optional :end, type: Hash do + optional :line_code, type: String, desc: 'End line code for multi-line note' + optional :type, type: String, desc: 'End line type for multi-line note' + optional :old_line, type: String, desc: 'End old_line line number' + optional :new_line, type: String, desc: 'End new_line line number' + end + end end end end @@ -122,12 +129,12 @@ module API end end - desc "Get comments in a single #{noteable_type.to_s.downcase} discussion" do + desc "Get comments in a single #{notable_name} discussion" do success Entities::Discussion end params do requires :discussion_id, type: String, desc: 'The ID of a discussion' - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' + requires :noteable_id, type: notable_id_type, desc: "The ID of the #{notable_name}" end get ":id/#{noteables_path}/:noteable_id/discussions/:discussion_id/notes", feature_category: feature_category do noteable = find_noteable(noteable_type, params[:noteable_id]) @@ -140,11 +147,11 @@ module API present notes, with: Entities::Note end - desc "Add a comment to a #{noteable_type.to_s.downcase} discussion" do + desc "Add a comment to a #{notable_name} discussion" do success Entities::Note end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' + requires :noteable_id, type: notable_id_type, desc: "The ID of the #{notable_name}" requires :discussion_id, type: String, desc: 'The ID of a discussion' requires :body, type: String, desc: 'The content of a note' optional :created_at, type: String, desc: 'The creation date of the note' @@ -175,11 +182,11 @@ module API end end - desc "Get a comment in a #{noteable_type.to_s.downcase} discussion" do + desc "Get a comment in a #{notable_name} discussion" do success Entities::Note end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' + requires :noteable_id, type: notable_id_type, desc: "The ID of the #{notable_name}" requires :discussion_id, type: String, desc: 'The ID of a discussion' requires :note_id, type: Integer, desc: 'The ID of a note' end @@ -189,11 +196,11 @@ module API get_note(noteable, params[:note_id]) end - desc "Edit a comment in a #{noteable_type.to_s.downcase} discussion" do + desc "Edit a comment in a #{notable_name} discussion" do success Entities::Note end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' + requires :noteable_id, type: notable_id_type, desc: "The ID of the #{notable_name}" requires :discussion_id, type: String, desc: 'The ID of a discussion' requires :note_id, type: Integer, desc: 'The ID of a note' optional :body, type: String, desc: 'The content of a note' @@ -210,11 +217,11 @@ module API end end - desc "Delete a comment in a #{noteable_type.to_s.downcase} discussion" do + desc "Delete a comment in a #{notable_name} discussion" do success Entities::Note end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' + requires :noteable_id, type: notable_id_type, desc: "The ID of the #{notable_name}" requires :discussion_id, type: String, desc: 'The ID of a discussion' requires :note_id, type: Integer, desc: 'The ID of a note' end @@ -225,11 +232,11 @@ module API end if Noteable.resolvable_types.include?(noteable_type.to_s) - desc "Resolve/unresolve an existing #{noteable_type.to_s.downcase} discussion" do + desc "Resolve/unresolve an existing #{notable_name} discussion" do success Entities::Discussion end params do - requires :noteable_id, types: [Integer, String], desc: 'The ID of the noteable' + requires :noteable_id, type: notable_id_type, desc: "The ID of the #{notable_name}" requires :discussion_id, type: String, desc: 'The ID of a discussion' requires :resolved, type: Boolean, desc: 'Mark discussion resolved/unresolved' end |