Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom field support #347

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow overriding existing org-jira properties with custom fields
  • Loading branch information
Ruin0x11 committed Jan 20, 2024
commit 94d2378ab39829bcc36f4d40a387ed6130ac45bd
45 changes: 25 additions & 20 deletions org-jira-sdk.el
Original file line number Diff line number Diff line change
Expand Up @@ -144,30 +144,35 @@
(funcall hydrate-fn proj-key id callback)))

(cl-defmethod org-jira-sdk-from-data ((rec org-jira-sdk-issue))
(cl-flet ((path (keys) (org-jira-sdk-path (oref rec data) keys)))
(cl-flet ((path (keys) (org-jira-sdk-path (oref rec data) keys))
(field (keys)
(let* ((org-name (car keys))
(jira-field-id (org-jira--org->api-field-id org-name))
(path (cdr keys)))
(result (org-jira-sdk-path (oref rec data) (cons 'fields (cons jira-field-id path)))))))
(org-jira-sdk-issue
:assignee (path '(fields assignee displayName))
:components (mapconcat (lambda (c) (org-jira-sdk-path c '(name))) (path '(fields components)) ", ")
:labels (mapconcat (lambda (c) (format "%s" c)) (mapcar #'identity (path '(fields labels))) ", ")
:created (path '(fields created)) ; confirm
:description (or (path '(fields description)) "")
:duedate (or (path '(fields sprint endDate)) (path '(fields duedate))) ; confirm
:filename (path '(fields project key))
:headline (path '(fields summary)) ; Duplicate of summary, maybe different.
:assignee (field '(assignee displayName))
:components (mapconcat (lambda (c) (org-jira-sdk-path c '(name))) (field '(components)) ", ")
:labels (mapconcat (lambda (c) (format "%s" c)) (mapcar #'identity (field '(labels))) ", ")
:created (field '(created)) ; confirm
:description (or (field '(description)) "")
:duedate (or (field '(sprint endDate)) (field '(duedate))) ; confirm
:filename (field '(project key))
:headline (field '(summary)) ; Duplicate of summary, maybe different.
:id (path '(key))
:issue-id (path '(key))
:issue-id-int (path '(id))
:priority (path '(fields priority name))
:proj-key (path '(fields project key))
:reporter (path '(fields reporter displayName)) ; reporter could be an object of its own slot values
:resolution (path '(fields resolution name)) ; confirm
:sprint (path '(fields sprint name))
:start-date (path '(fields start-date)) ; confirm
:status (org-jira-decode (path '(fields status name)))
:summary (path '(fields summary))
:type (path '(fields issuetype name))
:type-id (path '(fields issuetype id))
:updated (path '(fields updated)) ; confirm
:priority (field '(priority name))
:proj-key (field '(project key))
:reporter (field '(reporter displayName)) ; reporter could be an object of its own slot values
:resolution (field '(resolution name)) ; confirm
:sprint (field '(sprint name))
:start-date (field '(start-date)) ; confirm
:status (org-jira-decode (field '(status name)))
:summary (field '(summary))
:type (field '(issuetype name))
:type-id (field '(issuetype id))
:updated (field '(updated)) ; confirm
;; TODO: Remove this
;; :data (oref rec data)
)))
Expand Down
77 changes: 66 additions & 11 deletions org-jira.el
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,39 @@ See `org-default-priority' for more info."
:group 'org-jira
:type 'boolean)

(defcustom org-jira-issue-field-overrides-alist '()
"Alist mapping `org-mode' field names to Jira issue field IDs.
The car of each element is the org-jira field name.
The cdr of each element is the Jira issue field ID as returned by the API.

A sample value might be
(list (cons 'description 'customfield_10000)
(cons 'summary 'customfield_10001)
(cons 'duedate 'customfield_10002)).

Valid org-jira fields you can use:
- assignee
- components
- labels
- created
- description
- duedate
- project
- summary
- priority
- project
- reporter
- resolution
- sprint
- start-date
- status
- summary
- issuetype
- issuetype
- updated"
:group 'org-jira
:type '(alist :key-type symbol :value-type symbol))

(defvar org-jira-serv nil
"Parameters of the currently selected blog.")

Expand Down Expand Up @@ -424,6 +457,20 @@ See `org-default-priority' for more info."
"Get the proper proj-key from an ISSUE instance."
(oref Issue filename))

(defun org-jira--org->api-field-id (org-name)
"Convert an org-jira slot name ORG-NAME to a Jira API field ID."
(-if-let (org-id-pair (assoc org-name org-jira-issue-field-overrides-alist))
(cdr org-id-pair)
org-name))

(defun org-jira--api->org-field-id (jira-id)
"Convert a Jira API field ID JIRA-ID to an org-jira slot name.

Used to override the default description/etc. fields with custom fields."
(-if-let (org-id-pair (rassoc jira-id org-jira-issue-field-overrides-alist))
(car org-id-pair)
jira-id))

;; TODO: Merge these 3 ensure macros (or, scrap all but ones that work on Issue)
(defmacro ensure-on-issue-id (issue-id &rest body)
"Just do some work on ISSUE-ID, execute BODY."
Expand Down Expand Up @@ -2202,29 +2249,37 @@ otherwise it should return:
(org-jira-update-worklogs-from-org-clocks))

;; Send the update to jira
(let ((update-fields
(let* ((update-fields
(list (cons
'components
(org-jira--org->api-field-id 'components)
(or (org-jira-build-components-list
project-components
org-issue-components) []))
(cons 'labels (split-string org-issue-labels ",\\s *"))
(cons 'priority (org-jira-get-id-name-alist org-issue-priority
(cons (org-jira--org->api-field-id 'labels)
(split-string org-issue-labels ",\\s *"))
(cons (org-jira--org->api-field-id 'priority)
(org-jira-get-id-name-alist org-issue-priority
(jiralib-get-priorities)))
(cons 'description org-issue-description)
(cons 'assignee (list (cons 'id (jiralib-get-user-account-id project org-issue-assignee))))
(cons 'reporter (list (cons 'id (jiralib-get-user-account-id project org-issue-reporter))))
(cons 'summary (org-jira-strip-priority-tags (org-jira-get-issue-val-from-org 'summary)))
(cons 'issuetype `((id . ,org-issue-type-id)
(name . ,org-issue-type))))))
(cons (org-jira--org->api-field-id 'description)
org-issue-description)
(cons (org-jira--org->api-field-id 'assignee)
(list (cons 'id (jiralib-get-user-account-id project org-issue-assignee))))
(cons (org-jira--org->api-field-id 'reporter)
(list (cons 'id (jiralib-get-user-account-id project org-issue-reporter))))
(cons (org-jira--org->api-field-id 'summary)
(org-jira-strip-priority-tags (org-jira-get-issue-val-from-org 'summary)))
(cons (org-jira--org->api-field-id 'issuetype)
`((id . ,org-issue-type-id)
(name . ,org-issue-type))))))


;; If we enable duedate sync and we have a deadline present
(when (and org-jira-deadline-duedate-sync-p
(org-jira-get-issue-val-from-org 'deadline))
(setq update-fields
(append update-fields
(list (cons 'duedate (org-jira-get-issue-val-from-org 'deadline))))))
(list (cons (org-jira--org->api-field-id 'duedate)
(org-jira-get-issue-val-from-org 'deadline))))))

;; TODO: We need some way to handle things like assignee setting
;; and refreshing the proper issue in the proper buffer/filename.
Expand Down