Last active
April 24, 2023 07:30
-
-
Save CoRfr/9b1457d22377e528878de9414c65d26d to your computer and use it in GitHub Desktop.
List Gerrit users with NoteDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -e | |
| if ! [ -e "All-Users" ]; then | |
| [ -n "$GERRIT_GIT_PATH" ] || ( echo "GERRIT_GIT_PATH not set" && exit 1 ) | |
| git clone "${GERRIT_GIT_PATH}/All-Users.git" | |
| fi | |
| cd All-Users | |
| rm -f /tmp/users.csv | |
| set +e | |
| for user_id in $(git ls-remote origin | grep 'refs/users/' | awk '{print $2}' | sed 's#.*/\([0-9]*\)$#\1#' | sort -n -r); do | |
| last_digits=$(echo "$user_id" | sed 's/.*\([0-9][0-9]\)$/\1/') | |
| ref="refs/users/${last_digits}/${user_id}" | |
| git fetch origin $ref >/dev/null 2>&1 | |
| git checkout FETCH_HEAD >/dev/null 2>&1 | |
| user_fullname=$(git config --file account.config account.fullName) | |
| user_email=$(git config --file account.config account.preferredEmail) | |
| user_creationdate=$(git log --format="%ad" --date=format:'%Y-%m-%d %H:%M:%S' | tail -1) | |
| git fetch origin refs/meta/external-ids >/dev/null 2>&1 | |
| git checkout FETCH_HEAD >/dev/null 2>&1 | |
| user_ext=$(grep -B1 -Rh "accountId = $user_id" | grep externalId | sed 's/.*"\(.*\)"]/\1/' | sort) | |
| echo "$user_id,$user_email,$user_fullname,$user_creationdate,$(echo $user_ext | tr ' ' ',')" >> /tmp/users.csv | |
| echo "$user_id | $user_email | $user_fullname | $user_creationdate | $(echo $user_ext)" | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execution would be something like:
GERRIT_GIT_PATH=/var/gerrit/review_site/git bash list-gerrit-users.sh