;;; my-gerrit.el --- magit integration for Gerrit -*- lexical-binding: t -*- ;; Author: Franck Cuny ;;; 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