[chronometrist] OSM hook function - handle no saved changeset
This commit is contained in:
parent
1a4313f02c
commit
cd07480db8
50
init.org
50
init.org
|
@ -644,6 +644,15 @@ Return nil (and run `magit-status') if the user answers no."
|
|||
#+BEGIN_SRC emacs-lisp
|
||||
(require 'request)
|
||||
(require 'esxml-query)
|
||||
|
||||
(defun my-get-changeset-comment (changeset)
|
||||
(->> (esxml-query "[k=comment]" changeset)
|
||||
(esxml-node-attributes)
|
||||
(alist-get 'v)))
|
||||
|
||||
(defun my-make-osm-url (id)
|
||||
(concat "https://www.openstreetmap.org/changeset/" id))
|
||||
|
||||
(defun contrapunctus-after-project-stop (project)
|
||||
(pcase project
|
||||
("OSM"
|
||||
|
@ -666,26 +675,31 @@ Return nil (and run `magit-status') if the user answers no."
|
|||
return plist))
|
||||
(((&plist :osm-url last-url))
|
||||
(last saved-changesets))
|
||||
((last-id) (last (split-string last-url "/")))
|
||||
((last-id)
|
||||
(when last-url
|
||||
(last (split-string last-url "/"))))
|
||||
(response-changesets (esxml-node-children data))
|
||||
(new-changesets
|
||||
(cl-loop with attributes with id
|
||||
for changeset in response-changesets do
|
||||
(setq attributes (esxml-node-attributes changeset)
|
||||
id (alist-get 'id attributes))
|
||||
if (equal id last-id)
|
||||
return
|
||||
else collect
|
||||
(list
|
||||
:osm-url
|
||||
(concat
|
||||
"https://www.openstreetmap.org/changeset/" id)
|
||||
:osm-comment
|
||||
(->> (esxml-query "[k=comment]"
|
||||
latest-changeset)
|
||||
(esxml-node-attributes)
|
||||
(alist-get 'v))) into changesets
|
||||
finally return (reverse changesets))))
|
||||
(if last-id
|
||||
(cl-loop with id
|
||||
for changeset in response-changesets do
|
||||
(setq id (alist-get
|
||||
'id (esxml-node-attributes changeset)))
|
||||
if (equal id last-id)
|
||||
return (reverse changesets)
|
||||
else collect
|
||||
(list
|
||||
:osm-url
|
||||
(my-make-osm-url id)
|
||||
:osm-comment
|
||||
(my-get-changeset-comment changeset)) into changesets)
|
||||
;; no changeset information in file - just use
|
||||
;; the latest changeset from the response
|
||||
(let* ((changeset (first response-changes))
|
||||
(id (alist-get 'id (esxml-node-attributes changeset)))
|
||||
(comment (my-get-changeset-comment changeset)))
|
||||
`((:osm-url ,(my-make-osm-url id)
|
||||
:osm-comment ,comment))))))
|
||||
(chronometrist-sexp-replace-last
|
||||
(chronometrist-plist-update
|
||||
(chronometrist-last) `(:changesets ,new-changesets))))))))
|
||||
|
|
Loading…
Reference in New Issue