|
15 | 15 | :autoload +jira-get-ticket
|
16 | 16 | :init
|
17 | 17 | (defvar-local +jira-open-status '("open" "to do" "in progress"))
|
| 18 | + (defvar-local +jira-commit-auto-insert-ticket-id-predicate nil) |
18 | 19 | :config
|
19 | 20 | (defun +jira--ticket-annotation-fn (ticket)
|
20 | 21 | (let ((item (assoc ticket minibuffer-completion-table)))
|
@@ -58,6 +59,31 @@ The link style depends on the current major mode."
|
58 | 59 | (format "[%s%s](%s)" id (if with-summary (concat ": " summary) "") link))
|
59 | 60 | (t link)))))
|
60 | 61 |
|
| 62 | + ;; INFO: Here is an example of a predicate function, it inserts a Jira ID |
| 63 | + ;; only if the project's remote contains the username "abougouffa" |
| 64 | + ;; (setq +jira-commit-auto-insert-ticket-id-predicate |
| 65 | + ;; (lambda () |
| 66 | + ;; (when-let* ((urls (mapcar (lambda (remote) (string-trim-right (shell-command-to-string (format "git config --get remote.%s.url" remote)))) (magit-list-remotes)))) |
| 67 | + ;; (cl-some (apply-partially #'string-match-p (rx (or "github.com/abougouffa" "gitlab.com/abougouffa"))) urls)))) |
| 68 | + |
| 69 | + (defun +jira-commit-auto-insert-ticket-id () |
| 70 | + "Insert a ticket ID at the beginning of the commit if the first line is empty. |
| 71 | +
|
| 72 | +This function is meant to be hooked to `git-commit-mode-hook' for |
| 73 | +projects to uses the convention of commit messages like: |
| 74 | +
|
| 75 | +\"JIRA-TICKET-ID: Commit message\"." |
| 76 | + (when (and (+first-line-empty-p) ; Do not auto insert if the commit message is not empty (ex. amend) |
| 77 | + +jira-commit-auto-insert-ticket-id-predicate |
| 78 | + (funcall +jira-commit-auto-insert-ticket-id-predicate)) |
| 79 | + (goto-char (point-min)) |
| 80 | + (insert "\n") |
| 81 | + (goto-char (point-min)) |
| 82 | + (let ((pt (point))) |
| 83 | + (+jira-insert-ticket-id nil) |
| 84 | + (when (/= pt (point)) |
| 85 | + (insert ": "))))) |
| 86 | + |
61 | 87 | (defun +jiralib-auto-login ()
|
62 | 88 | "Auto login to Jira using credentials from `auth-source'."
|
63 | 89 | (interactive)
|
|
0 commit comments