GitHub code review with Emacs

At work, my team uses GitHub enterprise to store and manage our repositories. We also use GitHub code review.

Issues with code review:

When reviewing code:

  • I often check surrounding code to understand how it all fits together, which isn’t easy to do with a Web UI as opposed to a full-fledged editor like Vim or Emacs
  • I like to provide code snippets in comments, with the web UI it is not as easy to write code blocks and I often end up missing some indentation or syntax
  • I have to quit my editor, open a browser (be online at the time), and click a lot!

Wouldn’t it be nice to be able to review code in your favorite editor?

VSCode shipped last year integration for GitHub pull requests and I wanted to build the same kind of thing for my favorite editor, Emacs.

I built github-review an Emacs package to format and submit GitHub code reviews!

What does it look like?

In emacs you can start by calling github-review-start and entering a Pull Request URL. You will, then be prompted with a buffer containing the diff of the pull request. The diff contains the description of the PR at the top with line starting with ~. For example, reviewing this pull request would open the following buffer:

~ Fix broken link to closure cheat sheet
~
~ The owner of http://www.closurecheatsheet.com/ lost the domain and does not intend to maintain it. This commit replaces the now defunkt link to http://www.closurecheat$
~ ^M
~ I also opened an issue on the cheat sheet repo to follow up with the author of the cheat sheet https://github.com/kuzmisin/closurecheatsheet/issues/12.
diff --git a/content/reference/google-closure-library.adoc b/content/reference/google-closure-library.adoc
index 58baa4b..eae7707 100644
--- a/content/reference/google-closure-library.adoc
+++ b/content/reference/google-closure-library.adoc
@@ -18,7 +18,7 @@ rich-text editing, and UI widgets/controls.

 * http://google.github.io/closure-library/api/[Google Closure Library
 API Reference]
-* http://www.closurecheatsheet.com/[Closure Cheatsheet] - abridged API
+* https://github.com/kuzmisin/closurecheatsheet[Closure Cheatsheet] - abridged API
 with usage examples

 [[try-the-wrapper-libraries-first]]

You can add comments at the top level by writing lines starting with # after the PR description and before the beginning of the diff.

You can add comments inline by adding lines starting with # inline. See these features in the example below:

~ Fix broken link to closure cheat sheet
~
~ The owner of http://www.closurecheatsheet.com/ lost the domain and does not intend to maintain it. This commit replaces the now defunkt link to http://www.closurecheat$
~ ^M
~ I also opened an issue on the cheat sheet repo to follow up with the author of
the cheat sheet https://github.com/kuzmisin/closurecheatsheet/issues/12.
# This is a global comment at the top of the file
# with multiple
# lines and will be submitted as a top level review comment
diff --git a/content/reference/google-closure-library.adoc b/content/reference/google-closure-library.adoc
index 58baa4b..eae7707 100644
--- a/content/reference/google-closure-library.adoc
+++ b/content/reference/google-closure-library.adoc
@@ -18,7 +18,7 @@ rich-text editing, and UI widgets/controls.

 * http://google.github.io/closure-library/api/[Google Closure Library
 API Reference]
-* http://www.closurecheatsheet.com/[Closure Cheatsheet] - abridged API
+* https://github.com/kuzmisin/closurecheatsheet[Closure Cheatsheet] - abridged API
# And a comment inline about
# a specific line
# ```with some
# code```
  with usage examples
# Some other comment inline
 with usage examples

 [[try-the-wrapper-libraries-first]]

Once your are done, you can submit your review with one of github-review-approve, github-review-comment and github-review-reject.

Advantages

It solves the problem identified above:

  • I can browse the repository and my code review side by side in my editor
  • It is easy to format snippets and submit them as comments
  • No app switch and click needed to review code, I can download a bunch of PR and work on my GitHub code reviews in a plane, offline

This workflow has made me more focused, fast, and thorough when reviewing code!

Where is the code? How can I use it?

  • I put the code on GitHub

  • I am working on submitting github-review to MELPA to make it accessible to a broader audience!

  • For now, install from source using quelpa, for example if you use doom emacs you can use:

    (package! 
      github-review
      :recipe 
        (:fetcher github 
         :repo "charignon/github-review"
         :files ("github-review.el")))