Skip to content

Instantly share code, notes, and snippets.

@richlowe
Last active Aug 29, 2015
Embed
What would you like to do?
(defun il--break-lines (pattern)
"Break the buffer such that each PATTERN is at the beginning of a line"
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp pattern nil t)
(goto-char (match-beginning 0))
(unless (bolp)
(insert "\n"))
(goto-char (match-end 0)))))
(defun il--insert-approver ()
"Insert the illumos Approver metadata in the correct spot"
(let ((approver (format "%s <%s>" user-full-name user-mail-address)))
(goto-char (point-max))
(if (search-backward-regexp "^Approved.by:\\(.*\\)$" nil t)
(replace-match (format " %s" approver) nil t nil 1)
(search-backward-regexp "^Reviewed.by:.*$")
(goto-char (match-end 0))
(insert (format "\nApproved by: %s\n" approver)))))
(defun illumos-approve-commit ()
"Fix an illumos commit message that's been destroyed by `git
format-patch', and insert the approval"
(interactive)
(save-excursion
(goto-char (point-min))
;; Split bug IDs
(il--break-lines "\\s-[0-9]\\{4,\\}\\s-")
;; Split reviewers
(il--break-lines "\\(Reviewed\\|Approved\\).by:")
(il--insert-approver)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment