Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfgang Mederle committed Feb 10, 2021
2 parents 6a963e9 + 8675aae commit c6ac68a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 14 deletions.
14 changes: 14 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,17 @@ Commands available in =ejira-agenda=:
By default the items are rounded to 15 minutes. If exact times are desired, set =ejira-hourmaking-round-by= to 1.

Syncing worklogs from JIRA to org is not currently implemented, as I personally don't have a use case for it.
*** Syncing only your tickets

By default =ejira= synchronizes all tickets across a project. If you want to
restrict synchronization to only your tickets (assigned or reported), use the
following override:

#+begin_example emacs-lisp
(setq ejira-update-jql-unresolved-fn #'ejira-jql-my-unresolved-project-tickets)
#+end_example

*** Syncing tickets using custom JQL

=ejira-update-jql-unresolved-fn= can be set to any function that accepts a
string representing the project ID, and returns a JQL statement as a string.
9 changes: 4 additions & 5 deletions ejira-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,11 @@ Prefix argument causes discarding the cached issue key list."
(mapc #'ejira--update-task
(mapcar #'ejira--parse-item
(apply #'jiralib2-jql-search jql (ejira--get-fields-to-sync)))))
(when (or current-prefix-arg (not (assoc jql ejira-agenda--jql-cache)))
(map-put ejira-agenda--jql-cache jql (mapcar
(-partial #'alist-get 'key)
(jiralib2-jql-search jql "key"))))
(when (or current-prefix-arg (not (alist-get jql ejira-agenda--jql-cache nil nil #'equal)))
(setf (alist-get jql ejira-agenda--jql-cache nil nil 'equal)
(mapcar (-partial #'alist-get 'key) (jiralib2-jql-search jql "key"))))

(ejira-agenda-view (cdr (assoc jql ejira-agenda--jql-cache))))
(ejira-agenda-view (alist-get jql ejira-agenda--jql-cache nil nil #'equal)))

(defun ejira-agenda--cmd (fun &rest args)
"Call function FUN from agenda.
Expand Down
16 changes: 11 additions & 5 deletions ejira-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ key is given if the value is a key/value pair."
(find-file project-file-name))))

(unless existing-heading
(ejira--new-heading project-buffer key))
(ejira--new-heading project-buffer nil key))

(ejira--set-summary key (ejira-project-name project))
(ejira--set-property key "TYPE" "ejira-project"))))))
Expand Down Expand Up @@ -344,7 +344,9 @@ If the issue heading does not exist, fallback to full update."
;; Create a new heading if needed
(unless (ejira--find-heading key)
(when (fboundp 'helm-ejira-invalidate-cache) (helm-ejira-invalidate-cache))
(ejira--new-heading (marker-buffer (ejira--find-heading project)) key))
(ejira--new-heading (marker-buffer (ejira--find-heading project))
(or parent project)
key))

(ejira--set-todo-state key (alist-get status ejira-todo-states-alist 1 nil #'equal))

Expand Down Expand Up @@ -623,15 +625,19 @@ contents will be skipped."
(error nil))))


(defun ejira--new-heading (buffer id)
"Create a header with id ID into BUFFER and return a marker to it.
If TITLE is given, use it as header title."
(defun ejira--new-heading (buffer parent id)
"Create a header with ID under PARENT into BUFFER and return a marker to it.
If TITLE is given, use it as header title. If PARENT is nil assume the beginning
of the document."
(save-window-excursion
(with-current-buffer buffer
(org-with-wide-buffer
(ejira--with-expand-all
(goto-char (point-min))

;; `forward-line' won't work as intended if the org document contains
;; headers. We should jump to the parent.
(when parent (goto-char (ejira--find-heading parent)))
;; insert-heading-respect-content does not respect content if we are
;; before first heading in the file. Thus, we want to move to a safe
;; location. In an empty buffer, the first line has the visibility
Expand Down
3 changes: 2 additions & 1 deletion ejira-hourmarking.el
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
(defun ejira-hourmarking-round (time round-by)
"Round TIME to nearest ROUND-BY."
;; Account for stupid time zone issues.
(let* ((hours (- (string-to-number (format-time-string "%H" time)) 2))
(let* ((offset (/ (car (current-time-zone)) 3600))
(hours (- (string-to-number (format-time-string "%H" time)) offset))
(minutes (string-to-number (format-time-string "%M" time)))
(total (+ (* 60 hours) minutes))
(rounded (round total round-by))
Expand Down
36 changes: 33 additions & 3 deletions ejira.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
(defvar ejira-push-deadline-changes t
"Sync deadlines to server when updated with `ejira-set-deadline'.")

(defvar ejira-update-jql-resolved-fn #'ejira-jql-all-resolved-project-tickets
"Generates JQL used in `ejira-update-project' to find server-resolved items.
Must take a project-id as a string, a list of keys, and return JQL as a string."
)

(defvar ejira-update-jql-unresolved-fn
#'ejira-jql-all-unresolved-project-tickets
"Generates JQL used in `ejira-update-project' to find unresolved items.
Must take a project-id as a string and return JQL as a string.")

(defun ejira-add-comment (to-clocked)
"Capture new comment to issue under point.
With prefix-argument TO-CLOCKED add comment to currently clocked issue."
Expand All @@ -50,6 +60,27 @@ With prefix-argument TO-CLOCKED add comment to currently clocked issue."
(when (y-or-n-p (format "Delete comment %s? " (cdr id)))
(ejira--delete-comment (car id) (cdr id)))))

(defun ejira-jql-all-resolved-project-tickets (project-id keys)
"Builds JQL for server-resolved project tickets in PROJECT-ID from local KEYS.
This is the function used in `ejira-update-project'. Override with
`ejira-update-jql-resolved-fn'."
(format "project = '%s' and key in (%s) and resolution = done"
project-id (s-join ", " keys)))

(defun ejira-jql-all-unresolved-project-tickets (project-id)
"Builds JQL to find unresolved project tickets assigned to PROJECT-ID.
This is the default function used in `ejira-update-project'. Override with
`ejira-update-jql-unresolved-fn'."
(format "project = '%s' and resolution = unresolved" project-id))

(defun ejira-jql-my-unresolved-project-tickets (project-id)
"Builds JQL to find your unresolved project tickets assigned to PROJECT-ID.
This is a convenience function used in `ejira-update-project'. Override with
`ejira-update-jql-unresolved-fn'."
(format "project = '%s' and \
resolution = unresolved and \
(assignee = currentUser() or reporter = currentUser())" project-id))

(defun ejira-pull-item-under-point ()
"Update the issue, project or comment under point."
(interactive)
Expand Down Expand Up @@ -217,7 +248,7 @@ comments. With SHALLOW, only update todo status and assignee."
(ejira--alist-get i 'fields 'assignee 'displayName))
(ejira--update-task (ejira--parse-item i))))
(apply #'jiralib2-jql-search
(format "project = '%s' and resolution = unresolved" id)
(funcall ejira-update-jql-unresolved-fn id)
(ejira--get-fields-to-sync shallow)))

;; Then, sync any items that are still marked as unresolved in our local sync,
Expand All @@ -240,8 +271,7 @@ comments. With SHALLOW, only update todo status and assignee."
(ejira--alist-get i 'fields 'assignee 'displayName))
(ejira--update-task (ejira--parse-item i))))
(apply #'jiralib2-jql-search
(format "project = '%s' and key in (%s) and resolution = done"
id (s-join ", " keys))
(funcall ejira-update-jql-resolved-fn id keys)
(ejira--get-fields-to-sync shallow)))))

;; TODO: Handle issue being deleted from server:
Expand Down

0 comments on commit c6ac68a

Please sign in to comment.