diff --git a/lib/api/discussions.rb b/lib/api/discussions.rb index 45466a1894c76e338ba3b1227330eb42ddfe5745..5c2337cdde403e55036a11a88911523eed135178 100644 --- a/lib/api/discussions.rb +++ b/lib/api/discussions.rb @@ -76,7 +76,7 @@ class Discussions < ::API::Base 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) + requires :position_type, type: String, desc: 'Type of the position reference', values: %w(text image file) 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' diff --git a/spec/requests/api/discussions_spec.rb b/spec/requests/api/discussions_spec.rb index a65dc6e0175f05de407b1a62ae04f9ae2f8fef7b..aebdcebbc5a84022c6a08315d774faa85f6b6ba3 100644 --- a/spec/requests/api/discussions_spec.rb +++ b/spec/requests/api/discussions_spec.rb @@ -116,6 +116,17 @@ it_behaves_like 'diff discussions API', 'projects', 'merge_requests', 'iid' it_behaves_like 'resolvable discussions API', 'projects', 'merge_requests', 'iid' + context "when position_type is file" do + it "creates a new diff note" do + position = diff_note.position.to_h.merge({ position_type: 'file' }).except(:ignore_whitespace_change) + + post api("/projects/#{parent.id}/merge_requests/#{noteable['iid']}/discussions", user), + params: { body: 'hi!', position: position } + + expect(response).to have_gitlab_http_status(:created) + end + end + context "when position is for a previous commit on the merge request" do it "returns a 400 bad request error because the line_code is old" do # SHA taken from an earlier commit listed in spec/factories/merge_requests.rb