about summary refs log tree commit diff
path: root/tools/emacs-pkgs/tvl/tvl.el
blob: 4947f66a65c9d95bcbba86f9e220575f095be911 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
;;; tvl.el --- description -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2020 Griffin Smith
;; Copyright (C) 2020 The TVL Contributors
;;
;; Author: Griffin Smith <grfn@gws.fyi>
;; Version: 0.0.1
;; Package-Requires: (s magit)
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;; This file provides shared utilities for interacting with the TVL monorepo
;;
;;; Code:

(require 'magit)
(require 's)

(defgroup tvl nil
  "Customisation options for TVL functionality.")

(defcustom tvl-gerrit-remote "origin"
  "Name of the git remote for gerrit"
  :group 'tvl)

(defun tvl--gerrit-ref (target-branch &optional flags)
  (let ((flag-suffix (if flags (format "%%l=%s" (s-join "," flags))
                       "")))
    (format "HEAD:refs/for/%s%s" target-branch flag-suffix)))

(define-suffix-command magit-gerrit-push-for-review ()
  "Push to Gerrit for review."
  (interactive)
  (magit-push-refspecs tvl-gerrit-remote
                       (tvl--gerrit-ref "master")
                       nil))

(transient-append-suffix
  #'magit-push ["r"]
  (list "R" "push to Gerrit for review" #'magit-gerrit-push-for-review))

(define-suffix-command magit-gerrit-submit ()
  "Push to Gerrit for review."
  (interactive)
  (magit-push-refspecs tvl-gerrit-remote
                       (tvl--gerrit-ref "master" '("submit"))
                       nil))

(transient-append-suffix
  #'magit-push ["r"]
  (list "S" "push to Gerrit to submit" #'magit-gerrit-submit))


(define-suffix-command magit-gerrit-rubberstamp ()
  "Push, automatically approve and submit to Gerrit. This
rubberstamp operation is dangerous and should only be used in
`//users'."
  (interactive)
  (magit-push-refspecs tvl-gerrit-remote
                       (tvl--gerrit-ref "master"
                                        '("Code-Review+2" "publish-comments" "submit"))
                       nil))

(transient-append-suffix
  #'magit-push ["r"]
  (list "P" "push, rubberstamp & submit to Gerrit" #'magit-gerrit-rubberstamp))

(provide 'tvl)
;;; tvl.el ends here