mb/google/fatcat: Suppress unnecessary extra space in device trees
[coreboot2.git] / util / scripts / find_new_user_commits.sh
blob32d79cc4881dbefa40d4484f8e03f25c13e58d69
1 #!/usr/bin/env bash
2 # shellcheck disable=SC2310,SC2312
3 # The above line must be directly after the shebang line.
4 # Disables these warnings:
5 # SC2310 - This function is invoked in an 'if' condition so set -e will be disabled.
6 # Invoke separately if failures should cause the script to exit.
7 # SC2312 - Consider invoking this command separately to avoid masking its return value
10 # SPDX-License-Identifier: GPL-2.0-only
14 # Description:
15 # Identifies new users in gerrit so that they can be greeted and marked
16 # as new users.
19 VERSION="1.00"
20 PROGRAM=$0
21 PROGNAME="$(basename "${PROGRAM}")"
23 COMMIT_COUNT=5 # Consider a user to be new until they have this many commits
24 AGE="1week"
25 #AGE="3months"
26 KNOWN_AUTHOR_FILE="./authorlist.txt"
27 NEW_AUTHOR_FILE="./new_authors.txt"
28 GERRIT_USER="$1"
29 GERRIT_REPO="review.coreboot.org"
31 show_version() {
32 echo "${PROGNAME} version ${VERSION}"
33 echo
36 usage() {
37 echo "Usage: ${PROGNAME} <gerrit username>"
38 echo "example: ${PROGNAME} martinlroth"
41 main() {
42 local commit_count
43 local patchlist
44 local owner
45 local owner_email
46 local commit_id
47 local new_users=0
49 show_version
51 if ! jq --version >/dev/null 2>&1; then
52 echo "Error: jq is not installed. Please install it with your package manager."
53 exit 1
56 if [[ -z ${GERRIT_USER} ]]; then
57 echo "Error: Please specify gerrit username on the command line." >&2
59 if [[ -z ${GERRIT_USER} || ${GERRIT_USER} == "--help" || ${GERRIT_USER} == "-h" ]]; then
60 usage
61 exit 1
64 echo "List of known users with more than 5 commits: ${KNOWN_AUTHOR_FILE}"
65 echo "List of new user's patches: ${NEW_AUTHOR_FILE}"
66 echo "Key: . = author in known user list or new user commit already seen"
67 echo " : = author getting added to known user list"
68 echo
70 touch "${NEW_AUTHOR_FILE}" "${KNOWN_AUTHOR_FILE}"
72 # Get all coreboot patches that aren't by known users, newer than the age set above
73 patchlist="$(ssh -p 29418 "${GERRIT_USER}@${GERRIT_REPO}" gerrit query --format=JSON --no-limit --current-patch-set "repo:coreboot AND status:open NOT age:${AGE} NOT ownerin:Reviewers NOT ownerin:\\\"Core Developers\\\"" |
74 jq -Mr '.currentPatchSet.uploader.name + ", " + .currentPatchSet.uploader.email + ", " + .currentPatchSet.revision + ", " + (.number | tostring)' |
75 grep -v "null\|^,");"
77 if [[ -z ${patchlist} ]]; then
78 echo "Error: No patches returned." >&2
79 exit 1
80 else
81 echo "$(wc -l <<<"${patchlist}") patches found."
84 # Loop through all patches found, looking for any that are not by a known author.
85 # If an author with more than 5 patches is found, add them to a list to filter out in the future.
86 # If we find a new patch, print it, then add it to a list so that it isn't reported again.
87 IFS=$'\n'
88 for patch in ${patchlist}; do
89 owner="$(echo "${patch}" | cut -f1 -d',')"
90 owner_email="$(echo "${patch}" | cut -f2 -d',')"
91 commit_id="$(echo "${patch}" | cut -f4 -d',')"
93 if grep -qi "${owner}" "${KNOWN_AUTHOR_FILE}" || grep -qi "${owner_email}" "${KNOWN_AUTHOR_FILE}" || grep -q "${commit_id}" "${NEW_AUTHOR_FILE}"; then
94 printf "."
95 continue
98 # Get the author's commit count
99 # shellcheck disable=SC2126 # (Consider using grep -c instead of grep | wc)
100 commit_count="$(ssh -p 29418 "${GERRIT_USER}@${GERRIT_REPO}" gerrit query --format=JSON "limit:6 AND repo:coreboot AND owner:${owner_email} and status:merged" |
101 jq -Mr '.owner.name + ", " + .owner.email' |
102 grep -v "null\|^," |
103 wc -l)"
104 if [[ ${commit_count} -ge ${COMMIT_COUNT} ]]; then
105 printf ":"
106 echo "${owner}, ${owner_email}" >>"${KNOWN_AUTHOR_FILE}"
107 continue
110 printf "\n%s looks to be a patch by a new author.\n" "${patch}"
111 echo "${patch}" >>"${NEW_AUTHOR_FILE}"
112 new_users+=1
113 done
114 printf "\n"
115 if [[ ${new_users} -eq 0 ]]; then
116 echo "No new patches by new users found."
120 main