Copy a might means [a]pi
⇡
$ curl -X PUT http://domain.name/a/path/to/api/
$ curl -X POST http://domain.name/a/path/to/api/
$ curl -X DELETE http://domain.name/a/path/to/api/
Copy $ curl -v -n -X DELETE http://domain.name/a/path/to/api/
Copy $ curl -s -X GET https://domain.name/a/changes/ ${changeid} /detail |
tail -n +2 |
jq -r '.labels."Code-Review".approved.name'
Copy $ curl -s -X GET https://domain.name/a/changes/ ${changeid} /detail |
tail -n +2 |
jq -r '.labels."Code-Review".all[] | select ( .value == -2 ) | .username'
# : |⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂| :
# : ⇣ :
# : select ".value"== -2 :
# : :
# ⇣ ⇣
# pipe pipe
# or
$ curl -s -X GET https://domain.name/a/changes/ ${changeid} /detail |
tail -n +2 |
jq -r '( .labels."Code-Review".all[] | select ( .value == -2 ) ).username'
# : :
# ⇣ ⇣
# expression expression
# or
$ curl -s -X GET https://domain.name/a/changes/ ${changeid} /detail |
tail -n +2 |
jq -r '[ .labels."Code-Review".all[] | select ( .value == -2 ) ][].username'
# : :
# ⇣ ⇣
# expression expression
# or
$ curl -s -X GET https://domain.name/a/changes/ ${changeid} /detail |
tail -n +2 |
jq -r '.labels."Code-Review".all[] | select ( .value == -2 )' |
jq -r .username # :
# ⇣
# pipe
Copy $ curl -s -X GET https://domain.name/a/changes/ ${changeid} /detail |
tail -n +2 |
jq -r .labels.Verified.approved.username
access list contains account
Copy # i.e. : check all repos who contains account marslo@sample.com
$ while read -r _proj ; do
output = $( curl -fsSL https://gerrit.sample.com/a/projects/ "${_proj}" /access |
tail -n+2 |
jq -r '.. | .rules? | select(. != null) | keys[] | ascii_downcase | select(contains("marslo@sample.com"))';
)
[[ -z "${output}" ]] || echo ">> https://gerrit.sample.com/admin/repos/$( sed 's:%2F:/:g' <<< "${_proj}")"
done < <( curl -fsSL https://gerrit.sample.com/a/projects/?d |
tail -n+2 |
jq -r '.[].id' |
grep --color=never -E 'keyword-1|keyword-2'
)
all reviews at a certain time
Copy project = 'PROJECT'
branch = 'BRANCH'
start = '2023-01-01'
end = '2024-01-01'
curlOpt = '--silent --insecure --globoff --netrc-file ~/.netrc'
query = "project:${project}+branch:${branch}+after:${start}+before:${end}"
filter by status if necessary
query = "${query}+is:closed+-is:abandoned"
echo ">> ${project} ~ ${branch}"
while IFS = '|' read -r _change_id _id ; do
echo -e "\t- [${_id}] [_change_id]"
done < <( eval "curl ${curlOpt} 'https://gerrit.sample.com/a/changes/?q=${query}'" |
tail -n +2 |
jq -r '.[] | .change_id + "|" + .id'
)
get review rate in certain time
Copy gerritUrl = 'https://gerrit.sample.com'
sum = 0
rnum = 0
onum = 0
echo ">> ${project} ~ ${branch}"
while IFS = '|' read -r _change_id _id ; do
sum = $(( sum+1 ))
output = $( eval "curl ${curlOpt} '${gerritUrl}/a/changes/${_id}/detail' | tail -n+2" )
reviewed=$( jq -r '.labels."Code-Review".all[] | select(.value != null) | select( .value | contains(2) ) | .username' <<< "${output}" )
owned = $( jq -r '.owner.username' <<< "${output}" )
if grep 'marslo' <<< "${reviewed}" > /dev/null ; then rnum = $(( rnum+1 )); fi
if grep 'marslo' <<< "${owned}" > /dev/null ; then onum = $(( onum+1 )); fi
done < <( eval "curl ${curlOpt} '${gerritUrl}/a/changes/?q=${query}'" |
tail -n +2 |
jq -r '.[] | .change_id + "|" + .id'
)
echo "${sum} ${rnum} ${onum} $(( sum-onum ))" |
awk '{ sum=$1; reviewed=$2; owned=$3; rsum=$4; rate=$2*100/$4 } END { printf("\t- gerrit review: %s/(%s-%s) ( %s% )\n", reviewed, sum, owned, rate) }'
Copy $ curl -fsSL "${gerritUrl}" /a/projects/?d | tail -n+2 | jq -r '.[].id'
list gerrit projects with certain account
Copy $ account= 'marslo'
$ id= 1
$ gerritUrl= 'https://gerrit.sample.com'
$ while read -r _proj ; do
output = $( curl -fsSL "${gerritUrl}" /a/projects/ "${_proj}" /access |
tail -n+2 |
jq -r --arg ACCOUNT "${account}" '.. | ."rules"? | select(. != null) | keys[] | ascii_downcase | select(contains($ACCOUNT))';
)
[[ -n "${output}" ]] && echo "[${id}] >> " ${gerritUrl} "/admin/repos/$( sed 's:%2F:/:g' <<< "${_proj}")" && ((id ++ ));
done < <( curl -fsSL "${gerritUrl}" /a/projects/?d | tail -n+2 | jq -r '.[].id' )
Copy $ project= 'path/to/project'
$ curl -g -fsSL "https://${gerritUrl}/a/projects/$( printf %s "${project}" | jq -sRr @uri )/config" | tail -n+2 | jq -r