The following post is about viewing data from azure work items (ticket id, title etc..) and managing org notes by tagging them.
Setting up az cli & az devops extension for az cli
azure has a cli and for azure devops there is an extension .
#after installing azure cli & cli devops extension
#login
az devops login
Viewing tickets in org mode (using az wiql)
This snippet does two things
- Shows a table of ticket ids , titles etc.. in org mode
- Saves it as JSON to be used by other functions Azure-cli supports queries with a syntax called wiql
cd C:\Users\Tejaswi.DPrakash\Documents\code\azure-devops;
#I use a python venv.
scripts\activate
$res = az boards query --output json --wiql "SELECT [id],[Description], [Title],[Priority], [Changed Date] FROM workitems where [system.assignedto] = 'widp' and [system.state] <> 'DONE' and [system.state] <> 'RESOLVED' " --organization "https://dev.azure.com/myorg/" --project "my project";
$res | out-file C:\Users\tickets.json ;
$res = az boards query --output table --wiql "SELECT [id], [Title],[Priority], [Changed Date] FROM workitems where [system.assignedto] = 'widp' and [system.state] <> 'DONE' and [system.state] <> 'RESOLVED' " --organization "https://dev.azure.com/myorg/" --project "my project";
write-output $res
write-output "fetching results complete";
Tagging org mode entries with ticket numbers using completing-read
This snippet parses the json file. The set-ticket-id function displays a completion interface with work item title, and sets the id of the work item as the tag/property of the current org subtree.
(defvar titleID-hashtable (make-hash-table :test 'equal ))
(defun set-ticket-id(&optional return-string)
(interactive)
(with-temp-buffer
(insert-file-contents "C:\\Users\\\\tickets.json")
(setq tickets-json (json-parse-buffer))
(setq tickets-json-list (append tickets-json nil))
(mapcar
(lambda (x)
(puthash
(gethash "System.Title" (gethash "fields" x))
(gethash "id" x)
titleID-hashtable))
tickets-json-list))
(setq tag-or-prop (completing-read "tag or prop?" '("tag" "property")))
(setq selected-id (number-to-string (gethash (completing-read "get-ticket-id" titleID-hashtable) titleID-hashtable)))
(if (equal return-string nil)
(if (equal tag-or-prop "property")
(org-set-property "TICKET_ID" selected-id)
(org-set-tags selected-id))
selected-id))