Skip to content

Commit

Permalink
AccountID vs. username, displayName vs. name
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfgang Mederle committed May 2, 2020
1 parent 5123c29 commit ffdb3e3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 25 deletions.
68 changes: 53 additions & 15 deletions jiralib.el
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ request.el, so if at all possible, it should be avoided."
('getIssueTypesByProject
(let ((response (jiralib--rest-call-it (format "/rest/api/2/project/%s" (first params)))))
(cl-coerce (cdr (assoc 'issueTypes response)) 'list)))
('getUser (jiralib--rest-call-it "/rest/api/2/user" :params `((username . ,(first params)))))
('getUser (jiralib--rest-call-it "/rest/api/2/user" :params `((accountId . ,(first params)))))
('getVersions (jiralib--rest-call-it (format "/rest/api/2/project/%s/versions" (first params))))

;; Worklog calls
Expand Down Expand Up @@ -522,6 +522,31 @@ emacs-lisp"
remote-field-values)))

(apply 'vector (nreverse remote-field-values))))

(defvar jiralib-subvalue-map
'((assignee . displayName)
(creator . displayName)
(priority . name)
(issuetype . name)))

(defun jiralib-flatten-data (data)
"Extracts the displayName Value an creates a tuple of ((car list) . subvalue).
If no key is given, returns list as-is."
(loop for item in data collect
(cond ((and (listp (cdr item))
(assoc (car item) jiralib-subvalue-map))
(cons (car item) (cdr (assoc (cdr (assoc (car item) jiralib-subvalue-map)) (cdr item)))))
((listp (cdr item))
(cons (car item) (jiralib-flatten-data (cdr item))))
(t item))))









;;;; Wrappers around JIRA methods

Expand Down Expand Up @@ -850,15 +875,26 @@ Return nil if the field is not found"
(setf name (cdr (assoc 'name type)))))
name))

(defun jiralib-get-user-fullname (username)
"Return the full name (display name) of the user with USERNAME."
(if (assoc username jiralib-user-fullnames)
(cdr (assoc username jiralib-user-fullnames))
(progn
(let ((user (jiralib-get-user username)))
(setf jiralib-user-fullnames (append jiralib-user-fullnames (list (cons username (cdr (assoc 'fullname user))))))
(cdr (assoc 'fullname user))))))

;; (defun jiralib-get-user-fullname (account-id)
;; "Return the full name (display name) of the user with USERNAME."
;; (if (assoc account-id jiralib-user-fullnames)
;; (cdr (assoc account-id jiralib-user-fullnames))
;; (progn
;; (let ((user (jiralib-get-user account-id)))
;; (setf jiralib-user-fullnames (append jiralib-user-fullnames (list (cons account-id (cdr (assoc 'fullname user))))))
;; (cdr (assoc 'fullname user))))))

(defun jiralib-get-user-fullname (account-id)
"Return the full name (displaName) of the user with accountId."
(loop for user in (jiralib-get-users nil)
when (rassoc account-id user)
return (cdr (assoc 'displayName user))))

(defun jiralib-get-user-account-id (full-name)
"Return the account-id (accountId) of the user with displayName."
(loop for user in (jiralib-get-users nil)
when (rassoc full-name user)
return (cdr (assoc 'accountId user))))

(defun jiralib-get-filter (filter-id)
"Return a filter given its FILTER-ID."
Expand Down Expand Up @@ -1010,18 +1046,20 @@ Return no more than MAX-NUM-RESULTS."
"Return all visible subtask issue types in the system."
(jiralib-call "getSubTaskIssueTypes" nil))

(defun jiralib-get-user (username)
"Return a user's information given their USERNAME."
(cond ((eq 0 (length username)) nil) ;; Unassigned
(t (jiralib-call "getUser" nil username))))
(defun jiralib-get-user (account-id)
"Return a user's information given their full name."
(cond ((eq 0 (length account-id)) nil) ;; Unassigned
(t (jiralib-call "getUser" nil account-id))))

(defvar jiralib-users-cache nil "Cached list of users.")

(defun jiralib-get-users (project-key)
"Return assignable users information given the PROJECT-KEY."
(unless jiralib-users-cache
(setq jiralib-users-cache
(jiralib-call "getUsers" nil project-key)))
(jiralib-call "getUsers" nil project-key))
(loop for (name . id) in org-jira-users do
(setf jiralib-users-cache (append (list (jiralib-get-user id)) jiralib-users-cache))))
jiralib-users-cache)

(defun jiralib-get-versions (project-key)
Expand Down
4 changes: 2 additions & 2 deletions org-jira-sdk.el
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
(cl-defmethod org-jira-sdk-from-data ((rec org-jira-sdk-issue))
(cl-flet ((path (keys) (org-jira-sdk-path (oref rec data) keys)))
(org-jira-sdk-issue
:assignee (path '(fields assignee name))
: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)) (map 'list #'identity (path '(fields labels))) ", ")
:created (path '(fields created)) ; confirm
Expand All @@ -157,7 +157,7 @@
:issue-id-int (path '(id))
:priority (path '(fields priority name))
:proj-key (path '(fields project key))
:reporter (path '(fields reporter name)) ; reporter could be an object of its own slot values
:reporter (path '(fields reporter displayName)) ; reporter could be an object of its own slot values
:resolution (path '(fields resolution name)) ; confirm
:start-date (path '(fields start-date)) ; confirm
:status (org-jira-decode (path '(fields status name)))
Expand Down
17 changes: 9 additions & 8 deletions org-jira.el
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ where both are strings. NEW-FILE-NAME is relative to
:type '(repeat (string :tag "Jira state name:")))

(defcustom org-jira-users
'(("Full Name" . "username"))
'(("Full Name" . "account-id"))
"A list of displayName and key pairs."
:group 'org-jira
:type 'list)
Expand Down Expand Up @@ -596,7 +596,7 @@ Entry to this mode calls the value of `org-jira-mode-hook'."
org-jira-users
(mapcar (lambda (user)
(cons (org-jira-decode (cdr (assoc 'displayName user)))
(org-jira-decode (cdr (assoc 'name user)))))
(org-jira-decode (cdr (assoc 'accountId user)))))
(jiralib-get-users project-key))))

(defun org-jira-get-reporter-candidates (project-key)
Expand All @@ -605,7 +605,7 @@ Entry to this mode calls the value of `org-jira-mode-hook'."
org-jira-users
(mapcar (lambda (user)
(cons (org-jira-decode (cdr (assoc 'displayName user)))
(org-jira-decode (cdr (assoc 'name user)))))
(org-jira-decode (cdr (assoc 'accountId user)))))
(jiralib-get-users project-key))))

(defun org-jira-entry-put (pom property value)
Expand Down Expand Up @@ -950,7 +950,6 @@ With a prefix argument, allow you to customize the jql. See
(when issue-pos
(goto-char issue-pos)
(recenter 0))))

;;;###autoload
(defun org-jira-get-issues-by-fixversion (fixversion)
"Get list of issues by FIXVERSION."
Expand Down Expand Up @@ -1565,7 +1564,7 @@ purpose of wiping an old subtree."
(cdr (rassoc user jira-users)))))
(when (null reporter)
(error "No reporter found, this should probably never happen."))
(org-jira-update-issue-details issue-id filename :reporter reporter))
(org-jira-update-issue-details issue-id filename :reporter (jiralib-get-account-id reporter)))
(error "Not on an issue"))))

;;;###autoload
Expand All @@ -1586,7 +1585,7 @@ purpose of wiping an old subtree."
(cdr (rassoc user jira-users)))))
(when (null assignee)
(error "No assignee found, use org-jira-unassign-issue to make the issue unassigned"))
(org-jira-update-issue-details issue-id filename :assignee assignee))
(org-jira-update-issue-details issue-id filename :assignee (jiralib-get-account-id assignee)))
(error "Not on an issue"))))

;;;###autoload
Expand Down Expand Up @@ -2105,8 +2104,8 @@ otherwise it should return:
(cons 'priority (org-jira-get-id-name-alist org-issue-priority
(jiralib-get-priorities)))
(cons 'description org-issue-description)
(cons 'assignee (jiralib-get-user org-issue-assignee))
(cons 'reporter (jiralib-get-user org-issue-reporter))
(cons 'assignee (list (cons 'id (jiralib-get-account-id org-issue-assignee))))
(cons 'reporter (list (cons 'id (jiralib-get-account-id org-issue-reporter))))
(cons 'summary (org-jira-strip-priority-tags (org-jira-get-issue-val-from-org 'summary)))
(cons 'issuetype (org-jira-get-id-name-alist org-issue-type
(jiralib-get-issue-types))))))
Expand Down Expand Up @@ -2134,6 +2133,8 @@ otherwise it should return:
))
)))



(defun org-jira-parse-issue-id ()
"Get issue id from org text."
(save-excursion
Expand Down

0 comments on commit ffdb3e3

Please sign in to comment.