blob: 250785db8f10836f130539304a4de39838ab5f93 [file] [log] [blame]
Andrew Geissler3c88e2d2021-01-28 15:18:11 -06001#!/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
15GERRIT_COMMAND="curl -s --anyauth -n https://gerrit.openbmc-project.xyz"
16
17echo "Checking ${GERRIT_PROJECT}:${GERRIT_BRANCH}:${GERRIT_CHANGE_ID}:${GERRIT_PATCHSET_REVISION}"
18
19COMMITTER_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']"`
20if [ "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
25fi
26
27#echo "Commit by '${COMMITTER_EMAIL}'"
28COMMITTER_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}`
30echo "USERNAME: $COMMITTER_USERNAME"
31if [ "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
36fi
37
38# Reset the vote to 0 so jenkins will detect a new +1 on retriggers
39ssh -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
43ssh -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
46ssh -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
49ssh -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
52ssh -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
55ssh -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
58ssh -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
61ssh -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
64ssh -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
67ssh -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
70ssh -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
73ssh -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
76ssh -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
79ssh -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
82ssh -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
85ssh -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
88ssh -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
91ssh -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
94ssh -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
97ssh -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
100ssh -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
103ssh -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
106ssh -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
109ssh -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
113if 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
117fi
118
119echo "${COMMITTER_USERNAME} is not on the approved list."
120ssh -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
123exit 0