diff options
Diffstat (limited to 'emacs/elisp')
-rw-r--r-- | emacs/elisp/my-gerrit.el | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/emacs/elisp/my-gerrit.el b/emacs/elisp/my-gerrit.el new file mode 100644 index 0000000..856d01f --- /dev/null +++ b/emacs/elisp/my-gerrit.el @@ -0,0 +1,76 @@ +;;; my-gerrit.el --- magit integration for Gerrit -*- lexical-binding: t -*- +;; Author: Franck Cuny <franck@fcuny.net> + +;;; Commentary: + +;; interact with Gerrit from magit + +;;; Code: + +(require 'magit) +(require 's) + +(defgroup my/gerrit nil + "Customization options for Gerrit integration with magit." + :group 'magit) + +(defcustom my/gerrit-remote "origin" + "Name of the git remote for Gerrit." + :type '(string) + :group 'my/gerrit) + +(defun my/gerrit-ref (target-branch &optional flags) + "Target ref to push change based on TARGET-BRANCH, with optional FLAGS." + (let ((flag-suffix (if flags (format "%%%s" (s-join "," flags)) + ""))) + (format "HEAD:refs/for/%s%s" target-branch flag-suffix))) + +(transient-define-suffix my/magit-gerrit-push-for-review () + "Push to Gerrit for review." + (interactive) + (magit-push-refspecs my/gerrit-remote (my/gerrit-ref (magit-main-branch)) nil)) + +(transient-append-suffix 'magit-push "m" + '("R" "push to Gerrit for review" my/magit-gerrit-push-for-review)) + +;; By appending `%wip' to the ref, we mark the change as `work in progress'. +;; https://gerrit-review.googlesource.com/Documentation/intro-user.html#wip +(transient-define-suffix my/magit-gerrit-push-for-review-wip () + "Push to Gerrit as work in progress." + (interactive) + (magit-push-refspecs my/gerrit-remote (my/gerrit-ref (magit-main-branch) '("wip")) nil)) + +(transient-append-suffix 'magit-push "R" + '("W" "push to Gerrit for review (WIP)" my/magit-gerrit-push-for-review-wip)) + +;; By appending `%ready' to the ref, we mark the change as ready for +;; review. +;; https://gerrit-review.googlesource.com/Documentation/intro-user.html#wip +(transient-define-suffix my/magit-gerrit-push-for-review-ready () + "Push to Gerrit as ready." + (interactive) + (magit-push-refspecs my/gerrit-remote (my/gerrit-ref (magit-main-branch) '("ready")) nil)) + +(transient-append-suffix 'magit-push "W" + '("r" "push to Gerrit for review (ready)" my/magit-gerrit-push-for-review-ready)) + +;; For this to work, permissions need to be setup, as per +;; https://gerrit.cloudera.org/Documentation/user-upload.html#auto_merge +(transient-define-suffix my/magit-gerrit-submit () + (interactive) + (magit-push-refspecs my/gerrit-remote (my/gerrit-ref (magit-main-branch) '("submit")) nil)) + +(transient-append-suffix 'magit-push "r" + '("P" "push to Gerrit to submit change" my/magit-gerrit-submit)) + +(transient-define-suffix my/magit-gerrit-shipit () + "Ship it." + (interactive) + (magit-push-refspecs my/gerrit-remote (my/gerrit-ref (magit-main-branch)'("l=Code-Review+2" "publish-comments")) nil)) + +(transient-append-suffix 'magit-push "P" + '("S" "Approve the change in Gerrit" my/magit-gerrit-shipit)) + +(provide 'my-gerrit) + +;;; my-gerrit.el ends here |