| Andrew Geissler | 3c88e2d | 2021-01-28 15:18:11 -0600 | [diff] [blame] | 1 | #!/bin/bash -e | 
|  | 2 | # | 
|  | 3 | # Purpose: | 
|  | 4 | #  This script is responsible for determining the owner of a gerrit | 
|  | 5 | #  commit, verifying they are within an approved gerrit group, and | 
|  | 6 | #  then updating gerrit with that verification info. | 
|  | 7 | # | 
|  | 8 | # Note: It is assumed this script is run as a part of a jenkins job triggered | 
|  | 9 | #       by the gerrit plugin. Therefore it assumes certain env variables | 
|  | 10 | #       provided by that plugin are avialable (i.e. GERRIT_PROJECT, ...) | 
|  | 11 | # | 
|  | 12 | # Required Inputs: | 
|  | 13 | #  SSH_KEY:  Path to private ssh key used to post messages to gerrit | 
|  | 14 |  | 
|  | 15 | GERRIT_COMMAND="curl -s --anyauth -n https://gerrit.openbmc-project.xyz" | 
|  | 16 |  | 
|  | 17 | echo "Checking ${GERRIT_PROJECT}:${GERRIT_BRANCH}:${GERRIT_CHANGE_ID}:${GERRIT_PATCHSET_REVISION}" | 
|  | 18 |  | 
|  | 19 | COMMITTER_EMAIL=`${GERRIT_COMMAND}/a/changes/${GERRIT_PROJECT/\//%2F}~${GERRIT_BRANCH}~${GERRIT_CHANGE_ID}/revisions/${GERRIT_PATCHSET_REVISION}/commit | python2 -c "import sys, json; sys.stdin.read(4); print json.load(sys.stdin)['committer']['email']"` | 
|  | 20 | if [ "x${COMMITTER_EMAIL}" == "x" ]; then | 
|  | 21 | echo "Unable to find committer." | 
|  | 22 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit review \ | 
|  | 23 | ${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER} --label=Ok-To-Test=0 --message=\'Unable to determine committer\' | 
|  | 24 | exit -1 | 
|  | 25 | fi | 
|  | 26 |  | 
|  | 27 | #echo "Commit by '${COMMITTER_EMAIL}'" | 
|  | 28 | COMMITTER_USERNAME=`${GERRIT_COMMAND}/a/accounts/${COMMITTER_EMAIL} | python2 -c "import sys, json; sys.stdin.read(4); print json.load(sys.stdin)['username']"` | 
|  | 29 | #COMMITTER_USERNAME=`${GERRIT_COMMAND}/a/accounts/${COMMITTER_EMAIL}` | 
|  | 30 | echo "USERNAME: $COMMITTER_USERNAME" | 
|  | 31 | if [ "x${COMMITTER_USERNAME}" == "x" ]; then | 
|  | 32 | echo "Unable to determine github user for ${COMMITTER_EMAIL}." | 
|  | 33 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit review \ | 
|  | 34 | ${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER} --label=Ok-To-Test=0 --message=\'Unable to determine github user\' | 
|  | 35 | exit -1 | 
|  | 36 | fi | 
|  | 37 |  | 
|  | 38 | # Reset the vote to 0 so jenkins will detect a new +1 on retriggers | 
|  | 39 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit review \ | 
|  | 40 | ${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER} --label=Ok-To-Test=0 -t autogenerated:jenkins | 
|  | 41 |  | 
|  | 42 | # Write full list of users to a file | 
|  | 43 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 44 | ls-members openbmc/ci-authorized --recursive > $WORKSPACE/users.txt | 
|  | 45 |  | 
|  | 46 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 47 | ls-members ampere/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 48 |  | 
|  | 49 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 50 | ls-members facebook/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 51 |  | 
|  | 52 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 53 | ls-members google/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 54 |  | 
|  | 55 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 56 | ls-members ibm/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 57 |  | 
|  | 58 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 59 | ls-members intel/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 60 |  | 
|  | 61 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 62 | ls-members inventec/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 63 |  | 
|  | 64 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 65 | ls-members nuvoton/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 66 |  | 
|  | 67 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 68 | ls-members quanta/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 69 |  | 
|  | 70 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 71 | ls-members yadro/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 72 |  | 
|  | 73 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 74 | ls-members inspur/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 75 |  | 
|  | 76 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 77 | ls-members wistron/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 78 |  | 
|  | 79 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 80 | ls-members hcl/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 81 |  | 
|  | 82 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 83 | ls-members rcs/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 84 |  | 
|  | 85 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 86 | ls-members wiwynn/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 87 |  | 
|  | 88 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 89 | ls-members hpe/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 90 |  | 
|  | 91 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 92 | ls-members individual/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 93 |  | 
|  | 94 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 95 | ls-members gager-in/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 96 |  | 
|  | 97 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 98 | ls-members amd/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 99 |  | 
|  | 100 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 101 | ls-members nvidia/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 102 |  | 
|  | 103 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 104 | ls-members bytedance/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 105 |  | 
|  | 106 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 107 | ls-members alibaba/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 108 |  | 
|  | 109 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit \ | 
|  | 110 | ls-members supermicro/ci-authorized --recursive >> $WORKSPACE/users.txt | 
|  | 111 |  | 
|  | 112 | # grep for the specific username word in the file | 
|  | 113 | if grep -q -w ${COMMITTER_USERNAME} $WORKSPACE/users.txt; then | 
|  | 114 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit review \ | 
|  | 115 | ${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER} --label=Ok-To-Test=1 -t autogenerated:jenkins --message=\'User approved, CI ok to start\' | 
|  | 116 | exit 0 | 
|  | 117 | fi | 
|  | 118 |  | 
|  | 119 | echo "${COMMITTER_USERNAME} is not on the approved list." | 
|  | 120 | ssh -o 'StrictHostKeyChecking no' -i $SSH_KEY -p 29418 jenkins-openbmc-ci@gerrit.openbmc-project.xyz gerrit review \ | 
|  | 121 | ${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER} --label=Ok-To-Test=0 -t autogenerated:jenkins --message=\'User not approved, see admin, no CI\' | 
|  | 122 |  | 
|  | 123 | exit 0 |