Commit 3ee03d28 authored by David Kim's avatar David Kim

Merge branch '335337-gitlab-commit-comments-fail-with-old-line_type-2' into 'master'

Resolve "GitLab commit comments fail with "old" line_type"

See merge request gitlab-org/gitlab!67735
parents 22229805 f3a54684
...@@ -336,7 +336,7 @@ module API ...@@ -336,7 +336,7 @@ module API
lines = Gitlab::Diff::Parser.new.parse(diff.diff.each_line) lines = Gitlab::Diff::Parser.new.parse(diff.diff.each_line)
lines.each do |line| lines.each do |line|
next unless line.new_pos == params[:line] && line.type == params[:line_type] next unless line.line == params[:line] && line.type == params[:line_type]
break opts[:line_code] = Gitlab::Git.diff_line_code(diff.new_path, line.new_pos, line.old_pos) break opts[:line_code] = Gitlab::Git.diff_line_code(diff.new_path, line.new_pos, line.old_pos)
end end
......
...@@ -5,7 +5,7 @@ module API ...@@ -5,7 +5,7 @@ module API
class CommitNote < Grape::Entity class CommitNote < Grape::Entity
expose :note expose :note
expose(:path) { |note| note.diff_file.try(:file_path) if note.diff_note? } expose(:path) { |note| note.diff_file.try(:file_path) if note.diff_note? }
expose(:line) { |note| note.diff_line.try(:new_line) if note.diff_note? } expose(:line) { |note| note.diff_line.try(:line) if note.diff_note? }
expose(:line_type) { |note| note.diff_line.try(:type) if note.diff_note? } expose(:line_type) { |note| note.diff_line.try(:type) if note.diff_note? }
expose :author, using: Entities::UserBasic expose :author, using: Entities::UserBasic
expose :created_at expose :created_at
......
...@@ -1879,6 +1879,26 @@ RSpec.describe API::Commits do ...@@ -1879,6 +1879,26 @@ RSpec.describe API::Commits do
expect(json_response['line_type']).to eq('new') expect(json_response['line_type']).to eq('new')
end end
it 'correctly adds a note for the "old" line type' do
commit = project.repository.commit("markdown")
commit_id = commit.id
route = "/projects/#{project_id}/repository/commits/#{commit_id}/comments"
post api(route, current_user), params: {
note: 'My comment',
path: commit.raw_diffs.first.old_path,
line: 4,
line_type: 'old'
}
expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/commit_note')
expect(json_response['note']).to eq('My comment')
expect(json_response['path']).to eq(commit.raw_diffs.first.old_path)
expect(json_response['line']).to eq(4)
expect(json_response['line_type']).to eq('old')
end
context 'when ref does not exist' do context 'when ref does not exist' do
let(:commit_id) { 'unknown' } let(:commit_id) { 'unknown' }
......
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