From 188af3a0d3b661a12e3b854253d112e9f9044714 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Tue, 31 Mar 2020 15:34:45 -0400 Subject: [PATCH] Allow creating epics without milestones The same as how we allow creating stories without epics, add a "No Milestone" list item to the top of the list of milestones to select from when creating an epic. --- org-clubhouse.el | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/org-clubhouse.el b/org-clubhouse.el index d0f2b2c4c..1894f344e 100644 --- a/org-clubhouse.el +++ b/org-clubhouse.el @@ -553,9 +553,10 @@ If set to nil, will never create stories with labels") (funcall cb epic-id))))) (defun org-clubhouse-prompt-for-milestone (cb) + "Prompt the user for a milestone using ivy and call CB with its ID." (ivy-read "Select a milestone: " - (-map #'cdr (org-clubhouse-milestones)) + (-map #'cdr (append '((nil . "No Milestone")) (org-clubhouse-milestones))) :require-match t :history 'org-clubhouse-milestone-history :action (lambda (selected) @@ -593,7 +594,8 @@ If set to nil, will never create stories with labels") (cl-defun org-clubhouse-create-epic-internal (title &key milestone-id) (cl-assert (and (stringp title) - (integerp milestone-id))) + (or (null milestone-id) + (integerp milestone-id)))) (org-clubhouse-request "POST" "epics" @@ -606,7 +608,6 @@ If set to nil, will never create stories with labels") (let ((elt-start (plist-get elt :begin)) (epic-id (alist-get 'id epic)) (milestone-id (alist-get 'milestone_id epic))) - (save-excursion (goto-char elt-start) @@ -615,10 +616,11 @@ If set to nil, will never create stories with labels") (org-clubhouse-link-to-epic epic-id) (number-to-string epic-id))) - (org-set-property "clubhouse-milestone" - (org-link-make-string - (org-clubhouse-link-to-milestone milestone-id) - (alist-get milestone-id (org-clubhouse-milestones))))))) + (when milestone-id + (org-set-property "clubhouse-milestone" + (org-link-make-string + (org-clubhouse-link-to-milestone milestone-id) + (alist-get milestone-id (org-clubhouse-milestones)))))))) (defun org-clubhouse-create-epic (&optional beg end) "Creates a clubhouse epic using selected headlines. @@ -635,14 +637,13 @@ If the epics already have a CLUBHOUSE-EPIC-ID, they are filtered and ignored." (elts (-remove (lambda (elt) (plist-get elt :CLUBHOUSE-EPIC-ID)) elts))) (org-clubhouse-prompt-for-milestone (lambda (milestone-id) - (when milestone-id - (dolist (elt elts) - (let* ((title (plist-get elt :title)) - (epic (org-clubhouse-create-epic-internal - title - :milestone-id milestone-id))) - (org-clubhouse-populate-created-epic elt epic)) - elts)))))) + (dolist (elt elts) + (let* ((title (plist-get elt :title)) + (epic (org-clubhouse-create-epic-internal + title + :milestone-id milestone-id))) + (org-clubhouse-populate-created-epic elt epic)) + elts))))) ;;; ;;; Story creation