|
270 | 270 | jiralib-host "my-jira-server.tld"
|
271 | 271 | jiralib-user "my-username")
|
272 | 272 |
|
273 |
| - ;; Add a hook on git-commit, so it automatically prompt for a ticket number to |
274 |
| - ;; add to the commit message |
275 |
| - (add-hook |
276 |
| - 'git-commit-mode-hook |
277 |
| - (satch-defun +jira-commit-auto-insert-ticket-id-h () |
278 |
| - (require 'jiralib) |
279 |
| - (when (and jiralib-url jiralib-token |
280 |
| - ;; Do not auto insert if the commit message is not empty (ex. amend) |
281 |
| - (+first-line-empty-p)) |
282 |
| - (goto-char (point-min)) |
283 |
| - (insert "\n") |
284 |
| - (goto-char (point-min)) |
285 |
| - (+jira-insert-ticket-id) |
286 |
| - (insert ": ")))) |
| 273 | + ;; INFO: Here is an example of a function, it inserts the following template |
| 274 | + ;; if the project's remote contains the username "abougouffa" |
| 275 | + ;; ------------------------------------------ |
| 276 | + ;; JIRA-TICKET-ID: | <- cursor here |
| 277 | + ;; |
| 278 | + ;; |
| 279 | + ;; Ref: JIRA-TICKET-ID: JIRA TICKET TITLE |
| 280 | + ;; ------------------------------------------ |
| 281 | + (setq-default |
| 282 | + +jira-commit-auto-insert-ticket-id-function |
| 283 | + (lambda () |
| 284 | + (when-let* ((id (and (cl-some (apply-partially #'string-match-p (rx (or "github.com/abougouffa" "gitlab.com/abougouffa"))) |
| 285 | + (mapcar (lambda (remote) (string-trim-right (shell-command-to-string (format "git config --get remote.%s.url" remote)))) |
| 286 | + (magit-list-remotes))) |
| 287 | + (+jira-get-ticket)))) |
| 288 | + (insert (car id) ": ") |
| 289 | + (save-excursion (insert "\n\n\nRef: " (car id) ": " (cdr id)))))) |
| 290 | + |
| 291 | + ;; Add the hook which uses `+jira-commit-auto-insert-ticket-id-function' on |
| 292 | + ;; git-commit, so it automatically prompt for a ticket number to add to the |
| 293 | + ;; commit message |
| 294 | + (add-hook 'git-commit-mode-on-hook #'+jira-commit-auto-insert-ticket-id) |
287 | 295 |
|
288 | 296 | ;; Login automatically using credentials from `auth-source'
|
289 | 297 | ;; You can achieve this by adding this line in your "~/.authinfo.gpg"
|
|
0 commit comments