-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mr discussion: allow to comment on specific lines in a diff
GitLab allows to comment on lines within a commit's diff [1] (or even ranges of lines[2]). This is standard practise when using the web interface, and arguably friendlier to MR authors because it gives context information in a standardized way. Teach "lab mr discussion" a a new parameter "--position" that takes the file, line type (added, deleted, context) and two line numbers (before and after the diff). It looks like this: lab mr discussion --commit=my-commit --position=README.md:+101,103 For added and deleted lines we only need one line number (the one in the "new" and the "old" version of the file, respectively), but due to a deficiency in the GitLab API[3] we need to pass both line numbers for context lines. [1]: https://docs.gitlab.com/ee/api/discussions.html#create-new-merge-request-thread [2]: commenting on ranges of lines is not yet supported. That can be added in future supplementing the single-line syntax +<old_line>,<new_line> with a range variant +<start_old_line>,<start_new_line>_+<end_old_line>,<end_new_line> (where + can be - or space of course). [3]: https://gitlab.com/gitlab-org/gitlab/-/issues/325161 For reference, I've been testing this with [Tig](https://github.com/jonas/tig), using the following binding in my ~/.tigrc: bind diff C !tiglab %(remote) %(branch) %(commit) %(file) %(file_old) %(text) %(lineno) %(lineno_old) where "tiglab" is this small wrapper script: #!/bin/sh set -eu remote=$1 branch=$2 commit=$3 file=$4 file_old=$5 text=$6 lineno=$7 lineno_old=$8 line_type=${text%"${text#?}"} # First character of the diff line. # Use the new filename, except if we are commenting on a deleted file. if [ -z "$file" ] || [ "$file" = /dev/null ]; then file=$file_old fi lab mr discussion "$remote" "$branch" --commit="$commit" --position="${file}:${line_type}${lineno_old},${lineno}"
- Loading branch information
Showing
2 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters