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 all commits
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
15 changes: 14 additions & 1 deletion jiralib.el
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ Example: (list '('t \"descriptive-predicate-label\" (lambda (x) x)))"
:type '(repeat (list boolean string function))
:group 'org-jira)


(defcustom jiralib-update-issue-fields-exclude-list nil
"A list of symbols to check for exclusion on updates based on matching key.
Key names should be one of components, description, assignee, reporter, summary, issuetype."
Expand Down Expand Up @@ -357,6 +356,7 @@ request.el, so if at all possible, it should be avoided."
(cl-case (intern method)
('getStatuses (jiralib--rest-call-it "/rest/api/2/status"))
('getIssueTypes (jiralib--rest-call-it "/rest/api/2/issuetype"))
('getIssueFields (jiralib--rest-call-it "/rest/api/2/field"))
('getSubTaskIssueTypes (jiralib--rest-call-it "/rest/api/2/issuetype"))
('getIssueTypesByProject
(let ((response (jiralib--rest-call-it (format "/rest/api/2/project/%s" (first params)))))
Expand Down Expand Up @@ -1042,6 +1042,19 @@ CALLBACK will be invoked if passed in upon endpoint completion."
(comment . ,comment))))
(jiralib-call "updateWorklog" callback issue-id worklog-id worklog)))

(defvar jiralib-issue-fields-cache nil
"Mapping of jiralib issue field IDs to names.")

(defun jiralib-get-issue-fields ()
"Return an assoc list mapping an issue field id to its details.

This function will only ask JIRA for the list of fields once, then
will cache it."
(unless jiralib-issue-fields-cache
(setq jiralib-issue-fields-cache
(jiralib-make-assoc-list (jiralib-call "getIssueFields" nil) 'id 'name)))
jiralib-issue-fields-cache)

(defvar jiralib-components-cache nil "An alist of project components.")

(defun jiralib-get-components (project-key)
Expand Down
49 changes: 29 additions & 20 deletions org-jira-sdk.el
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
(type :type string :initarg :type)
(type-id :type string :initarg :type-id)
(updated :type string :initarg :updated)
(custom-fields :type list :initarg :custom-fields)
(data :initarg :data :documentation "The remote Jira data object (alist).")
(hydrate-fn :initform #'jiralib-get-issue :initarg :hydrate-fn))
"An issue on the end. ID of the form EX-1, or a numeric such as 10000.")
Expand Down Expand Up @@ -144,30 +145,38 @@
(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)))
(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
:custom-fields (cl-remove-if-not
(lambda (f) (assoc (car f) org-jira-issue-custom-fields-alist))
(path '(fields)))
;; TODO: Remove this
;; :data (oref rec data)
)))
Expand Down
Loading