Skip to content

Instantly share code, notes, and snippets.

@williamspatrick
Created August 16, 2016 19:54
Show Gist options
  • Save williamspatrick/cb29e8575ddcca9fe368eca756104b87 to your computer and use it in GitHub Desktop.
Save williamspatrick/cb29e8575ddcca9fe368eca756104b87 to your computer and use it in GitHub Desktop.
#!/bin/bash
GERRIT_COMMAND="curl -s --anyauth -n https://gerrit.openbmc-project.xyz"
GITHUB_COMMAND="curl -s -n https://api.github.com"
GITHUB_TEAM=1777905
echo "Checking ${GERRIT_PROJECT}:${GERRIT_BRANCH}:${GERRIT_CHANGE_ID}:${GERRIT_PATCHSET_REVISION}"
COMMITTER_EMAIL=`${GERRIT_COMMAND}/a/changes/${GERRIT_PROJECT/\//%2F}~${GERRIT_BRANCH}~${GERRIT_CHANGE_ID}/revisions/${GERRIT_PATCHSET_REVISION}/commit | grep -Pzo "committer[^}]*" | grep -a '"email":' | sed 's/",$//' | sed 's/.*"//'`
if [ "x${COMMITTER_EMAIL}" == "x" ]; then
echo "Unable to find committer."
exit -1
fi
echo "Commit by '${COMMITTER_EMAIL}'"
COMMITTER_USERNAME=`${GERRIT_COMMAND}/a/accounts/${COMMITTER_EMAIL} | grep -a '"username":' | sed 's/",$//' | sed 's/.*"//'`
if [ "x${COMMITTER_USERNAME}" == "x" ]; then
echo "Unable to determine github user for ${COMMITTER_EMAIL}."
exit -1
fi
echo "${COMMITTER_EMAIL} is github:${COMMITTER_USERNAME}"
COMMITTER_MEMBERSHIP=`${GITHUB_COMMAND}/teams/${GITHUB_TEAM}/memberships/${COMMITTER_USERNAME} | grep -a '"state":' | sed 's/",$//' | sed 's/.*"//'`
if [ "x${COMMITTER_MEMBERSHIP}" == "x" ]; then
echo "${COMMITTER_USERNAME} is not a member of team ${GITHUB_TEAM}"
exit -1
fi
if [ "x${COMMITTER_MEMBERSHIP}" == "xactive" ]; then
echo "${COMMITTER_USERNAME} is active."
exit 0
fi
echo "${COMMITTER_USERNAME} is ${COMMITTER_MEMBERSHIP}, but not active."
exit -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment