I’d like to use the Merge Request Discussions API to add a comment referencing a specific line of code on the branched side of the diff.
I’m using the python wrapper for the API, and my code looks something like:
file_to_comment = 'foo.py'
line_to_comment = 42
merge_request.discussions.create({
'body': 'a comment',
'position': {
'base_sha': merge_request.diff_refs['base_sha'],
'start_sha': merge_request.diff_refs['start_sha'],
'head_sha': merge_request.diff_refs['head_sha'],
'position': text,
'new_path': file_to_comment,
'new_line': line_to_comment,
'old_path': file_to_comment,
'old_line': line_to_comment,
}
})
Depending on the situation, I’ll get an error response of:
line_code can’t be blank, must be a valid line code.
My understanding is that the old_path
/ old_line
must match what gitlab computed as the values of that line on the left hand side of the diff. However, it’s unclear how I could even compute this given the APIs available in the Gitlab API.
Has anyone solved this or have ideas on how to approach it?