Skip to content

Commit

Permalink
Loop over gerrit account info pages
Browse files Browse the repository at this point in the history
Closes: #8, #41
Change-Id: I310a1ef5170fd30f084ca3e1fe4bd26a11fb130f
  • Loading branch information
twmr committed Dec 9, 2023
1 parent ff7ae69 commit 8acf741
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ This code is tested using gerrit=3.5 and the gerrit version used on

Dezember 2023:

* Try to fetch as much gerrit account-info objects as possible at
startup.
* Fix invalid json in request problems with
`gerrit-rest-change-delete-cr-vote`,
`gerrit-rest-change-delete-reviewer` and
`gerrit-rest-change-delete-verified-vote`.
`gerrit-rest-change-delete-cr-vote`,
`gerrit-rest-change-delete-reviewer` and
`gerrit-rest-change-delete-verified-vote`.

Use DELETE method for deleting verified votes + Improve rest-sync-v2

Expand Down
39 changes: 30 additions & 9 deletions gerrit-rest.el
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,38 @@ down the URL structure to send the request."
("o" "DETAILED_ACCOUNTS"))))

(defun gerrit-rest--get-gerrit-accounts ()
"Return an alist of all active gerrit users."
"Return an alist of account-info of all active gerrit users.
The key or the alist is the account-id."
(interactive)
(condition-case nil
(mapcar (lambda (account-info) (cons (cdr (assoc '_account_id account-info))
account-info))
;; see https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html
;; and https://gerrit-review.googlesource.com/Documentation/user-search-accounts.html#_search_operators
(gerrit-rest-sync-v2 "GET" "/accounts/"
:params '(("q" "is:active")
("o" "DETAILS")
("S" 0))))
(let ((continue t)
(start-idx 0)
(accounts '()))
(while continue
(let ((response
;; see https://gerrit-review.googlesource.com/Documentation/rest-api-accounts.html
;; and https://gerrit-review.googlesource.com/Documentation/user-search-accounts.html#_search_operators

;; it might happen that this outputs: "Cannot go
;; beyond page " + indexConfig.maxPages() + " of
;; results" see
;; https://gerrit.googlesource.com/gerrit/+/refs/heads/master/java/com/google/gerrit/index/query/QueryProcessor.java#
;; TODO output a warning in this case telling the
;; user that not all account-infos can be fetched.
(gerrit-rest-sync-v2 "GET" "/accounts/"
:params `(("q" "is:active")
("o" "DETAILS")
("S" ,start-idx)))))
(setq accounts (append
accounts
(mapcar (lambda (account-info) (cons (cdr (assoc '_account_id account-info))
account-info))
response)))
(setq start-idx (+ start-idx (length response)))
(setq continue (alist-get '_more_accounts (car (last response))))
;; (message "start: %s, continue %s" start-idx continue)
))
accounts)
(error '())))

(defun gerrit-rest-open-reviews-for-project (project)
Expand Down

0 comments on commit 8acf741

Please sign in to comment.