Skip to content

Commit 005870c

Browse files
committed
tweak(skel): move config example for jiralib to skel/config.el
1 parent ceec2f3 commit 005870c

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

modules/me-services.el

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,6 @@ The link style depends on the current major mode."
5959
(format "[%s%s](%s)" id (if with-summary (concat ": " summary) "") link))
6060
(t link)))))
6161

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-default +jira-commit-auto-insert-ticket-id-function
65-
;; (lambda ()
66-
;; (when-let* ((id (and (cl-some (apply-partially #'string-match-p (rx (or "github.com/abougouffa" "gitlab.com/abougouffa")))
67-
;; (mapcar (lambda (remote) (string-trim-right (shell-command-to-string (format "git config --get remote.%s.url" remote))))
68-
;; (magit-list-remotes)))
69-
;; (+jira-get-ticket))))
70-
;; (insert (car id) ": ")
71-
;; (save-excursion (insert "\n\n\n" (car id) ": " (cdr id))))))
72-
7362
(defun +jira-commit-auto-insert-ticket-id ()
7463
"Insert a ticket ID at the beginning of the commit if the first line is empty.
7564

skel/config.el

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -270,20 +270,28 @@
270270
jiralib-host "my-jira-server.tld"
271271
jiralib-user "my-username")
272272

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)
287295

288296
;; Login automatically using credentials from `auth-source'
289297
;; You can achieve this by adding this line in your "~/.authinfo.gpg"

0 commit comments

Comments
 (0)