fix(grfn/emacs): Fix clocked-in-ticket-id for linear tickets

Change-Id: Id0e8883c1b621afb99edde3d256cccd057e89097
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9972
Autosubmit: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
Aspen Smith 2023-11-06 10:40:26 -05:00 committed by clbot
parent 81047cfcd7
commit f3dea2ffbc
2 changed files with 33 additions and 18 deletions

View file

@ -228,12 +228,13 @@
(use-package! org-tracker
:hook (org-mode . org-tracker-mode)
:config
(setq org-tracker-state-alist '(("INBOX" . "Inbox")
(setq org-tracker-state-alist '(("INBOX" . "Triage")
("BACKLOG" . "Backlog")
("TODO" . "Selected for Development")
("TODO" . "Todo")
("ACTIVE" . "In Progress")
("PR" . "Code Review")
("DONE" . "Done"))
("DONE" . "Done")
("CANCELLED" . "Canceled"))
org-tracker-username "griffin@readyset.io"
org-tracker-claim-ticket-on-status-update '("ACTIVE" "PR" "DONE")
org-tracker-create-stories-with-labels 'existing)
@ -467,21 +468,21 @@
(setq projectile-create-missing-test-files 't)
(setq grfn/jira-refs-re
(setq grfn/tracker-refs-re
(rx line-start
(or "Refs" "Fixes")
": "
"ENG-" (one-or-more digit)
(one-or-more graph)
line-end))
(defun grfn/add-jira-reference-to-commit-message ()
(defun grfn/add-tracker-reference-to-commit-message ()
(interactive)
(when-let* ((jira-id (grfn/org-clocked-in-jira-ticket-id)))
(when-let* ((ticket-id (grfn/org-clocked-in-ticket-id)))
(save-excursion
(save-match-data
(goto-char (point-min))
;; Don't add one if we've already got one
(unless (search-forward-regexp grfn/jira-refs-re nil t)
(unless (search-forward-regexp grfn/tracker-refs-re nil t)
(or
(and
(search-forward-regexp (rx line-start "Change-Id:") nil t)
@ -489,14 +490,14 @@
(and
(search-forward-regexp (rx line-start "# Please enter") nil t)
(forward-line -2)))
(insert (format "\nRefs: %s" jira-id)))))))
(insert (format "\nRefs: %s" ticket-id)))))))
(defun grfn/switch-jira-refs-fixes ()
(defun grfn/switch-tracker-refs-fixes ()
(interactive)
(save-excursion
(save-match-data
(if (not (search-forward-regexp grfn/jira-refs-re nil t))
(message "Could not find reference to JIRA ticket")
(if (not (search-forward-regexp grfn/tracker-refs-re nil t))
(message "Could not find reference to ticket")
(goto-char (point-at-bol))
(save-restriction
(narrow-to-region (point-at-bol)
@ -581,9 +582,9 @@
)
(add-hook 'git-commit-setup-hook #'grfn/add-jira-reference-to-commit-message)
(add-hook 'git-commit-setup-hook #'grfn/add-tracker-reference-to-commit-message)
(map! (:map git-commit-mode-map
"C-c C-f" #'grfn/switch-jira-refs-fixes))
"C-c C-f" #'grfn/switch-tracker-refs-fixes))
;; (defun grfn/split-window-more-sensibly (&optional window)
;; (let ((window (or window (selected-window))))
@ -1119,3 +1120,5 @@
(set-popup-rule!
"^\\*gud-"
:quit nil)
(setq elcord-editor-icon "emacs_icon")

View file

@ -115,11 +115,22 @@
(grfn/org-current-clocked-in-task-message)
)
(defun grfn/org-clocked-in-jira-ticket-id ()
(cl-defgeneric grfn/org-tracker-ticket-id-label (backend elt)
(org-tracker-backend/extract-issue-id backend elt))
(cl-defmethod grfn/org-tracker-ticket-id-label
((backend org-tracker-linear-backend) elt)
(when-let* ((link (plist-get elt :LINEAR-KEY)))
(string-match
(rx "[[" (one-or-more anything) "]"
"[" (group (one-or-more anything)) "]]")
link)
(match-string 1 link)))
(defun grfn/org-clocked-in-ticket-id ()
(grfn/at-org-clocked-in-item
(when (org-tracker-current-backend t)
(org-tracker-backend/extract-issue-id
(org-tracker-current-backend)
(when-let* ((backend (org-tracker-current-backend t)))
(grfn/org-tracker-ticket-id-label
backend
(cadr (org-element-at-point))))))
(comment
@ -128,4 +139,5 @@
(org-tracker-current-backend)
(cadr (org-element-at-point))))
(grfn/org-clocked-in-ticket-id)
)