dev(ci): refactor commit message reader for linter

This commit is contained in:
Henrik Lissner 2021-09-17 09:10:37 +02:00
parent f80eed41bb
commit 14729d21d1

View file

@ -31,6 +31,10 @@
;; ;;
;;; Git hooks ;;; Git hooks
(defvar doom-cli-commit-ref-types '("Fix" "Ref" "Close" "Revert"))
(defvar doom-cli-commit-ref-git-types '("Co-authored-by:" "Signed-off-by:"))
(defvar doom-cli-commit-rules (defvar doom-cli-commit-rules
(list (fn! (&key subject) (list (fn! (&key subject)
(when (<= (length subject) 10) (when (<= (length subject) 10)
@ -162,7 +166,7 @@
(catch 'found (catch 'found
(dolist (line refs) (dolist (line refs)
(cl-destructuring-bind (type . ref) (split-string line " +") (cl-destructuring-bind (type . ref) (split-string line " +")
(unless (member type '("Co-authored-by:" "Signed-off-by:")) (unless (member type doom-cli-commit-ref-git-types)
(setq ref (string-join ref " ")) (setq ref (string-join ref " "))
(or (string-match "^\\(https?://.+\\|[^/]+/[^/]+\\)?\\(#[0-9]+\\|@[a-z0-9]+\\)" ref) (or (string-match "^\\(https?://.+\\|[^/]+/[^/]+\\)?\\(#[0-9]+\\|@[a-z0-9]+\\)" ref)
(string-match "^https?://" ref) (string-match "^https?://" ref)
@ -205,27 +209,19 @@
(let (subject body refs summary type scopes bang refs errors warnings) (let (subject body refs summary type scopes bang refs errors warnings)
(with-temp-buffer (with-temp-buffer
(save-excursion (insert (cdr commit))) (save-excursion (insert (cdr commit)))
(let ((end (save-excursion
(or (and (re-search-forward
(format "\n\n%s "
(regexp-opt (append doom-cli-commit-ref-types
doom-cli-commit-ref-git-types)
t))
nil t)
(match-beginning 1))
(point-max)))))
(setq subject (buffer-substring (point-min) (line-end-position)) (setq subject (buffer-substring (point-min) (line-end-position))
body (buffer-substring body (buffer-substring (line-beginning-position 3) end)
(line-beginning-position 3) refs (split-string (buffer-substring end (point-max))
(save-excursion "\n" t)))
(or (and (re-search-forward (format "\n\n%s "
(regexp-opt '("Co-authored-by:" "Signed-off-by:" "Fix" "Ref" "Close" "Revert")
t))
nil t)
(match-beginning 1))
(point-max))))
refs (split-string
(save-excursion
(buffer-substring
(or (and (re-search-forward (format "\n\n%s "
(regexp-opt '("Co-authored-by:" "Signed-off-by:" "Fix" "Ref" "Close" "Revert")
t))
nil t)
(match-beginning 1))
(point-max))
(point-max)))
"\n" t))
(save-match-data (save-match-data
(when (looking-at "^\\([a-zA-Z0-9_-]+\\)\\(!?\\)\\(?:(\\([^)]+\\))\\)?: \\([^\n]+\\)") (when (looking-at "^\\([a-zA-Z0-9_-]+\\)\\(!?\\)\\(?:(\\([^)]+\\))\\)?: \\([^\n]+\\)")
(setq type (intern (match-string 1)) (setq type (intern (match-string 1))