DEV Community

Cover image for Reviewing PR from Vim: Critiq.vim
leojpod
leojpod

Posted on • Edited on

Reviewing PR from Vim: Critiq.vim

Reviewing PRs is daunting at times, even when dealing with merge requests less massive than the one showed in the cover picture. But regardless of the size of the PR, it has become my latest obsession: why should I quit the comfort of my own settings to review some code? Wouldn't I do the same faster if I was keeping my own cherished environment?

So, after a quick web search, I found a few candidates and narrowed it to one by applying the "last commit on GitHub/Gitlab shouldn't be 3+ years old if issues are more recent" rule: Critiq.vim.

Preliminary work

Before using critiq.vim I had to make a few changes to my config files: mainly, I introduced a new file, which will be imported when loading zsh, that will load some secrets into environment variables to let Critiq use my GitHub account (the changes are in this commit if anyone is mad enough to check it). The nice thing to remember here is that you don't have to put your GitHub password to authenticate with Critiq (thanks for that!). Instead, you can just head to https://github.com/settings/tokens and generate an access token, give it just the rights you want and use that.

Reviewing Critiq.vim

(pun intended)

The first thing you need to do once you've installed Critiq.vim is to simply call it: :Critiq which should list the open PRs from Github for your current project in a new tab (this was also a good opportunity for me to (re)learn about tabs in vim since I tend to do most things with only buffers). Pick one and press Enter. This should open 2 panes: the description of the PR in the upper pane and the diff in the lower one.

From there, just go about your business as you would in GH, with a few twists.

I don't get how it runs 🤔

:CritiqCheckout while it doesn't do exactly what it should (check out the branch locally), it does check out the code but under a weird name. I assume it does this to prevent conflicts with a potential local branch. Either way, after that you can just move to the previous tab to get your regular vim setting and go check that file or even simpler: CritiqOpenFile which will open the file in a new vertical pane for you. Isn't that neat?

That's code could be better!

:CritiqCommentLine while the cursor is on the line you want to comment will open a new small pane at the bottom in which you can type your comment. When you're ready to submit it: :CritiqSubmitComment

I haven't found yet if there is a possibility to write up a suggestion directly but it's not too complicated to write it yourself since it is after all just a simple code sample typed as suggestion

Approve/Reject/Comment

The last part of the process is now to submit your final assessment of the review: :CritiqComment, :CritiqApprove & :CritiqRequestChanges are here for that. They will open a new pane to write a comment justifying your assessment. Then use :CritiqSubmitReview and job done!

I've created a quick terminal recording (with asciinema) to show how it works (which sadly doesn't keep my beloved colour scheme):

asciicast

Final thoughts

I'd like to see if it is possible to achieve the same thing for Gitlab as well. I also spend a good time on Gitlab-hosted projects and that would be grand!

Hope this can be somewhat useful to others and see you next time!

Top comments (0)