Skip to content

Commit

Permalink
Script used to fetch pullRequests and create stg patches
Browse files Browse the repository at this point in the history
  • Loading branch information
amaltaro committed Nov 21, 2013
1 parent 6d730d2 commit 73fbad7
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions admin/getPulls
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash

### It fetches pullRequests made against a given <repository>.
### For cmsdist repo (cms-sw user), it only fecthes those against "comp" branch.
### For deployment repo (dmwm user), it's going to fetch everything.
### It creates a new stg patch for every pull request.
###
### Usage: getPulls -h
### Usage: getPulls -r <repository> <list of pull request numbers separated by space>
### Usage: Example: getPulls -r cmsdist 263 266 267

usage()
{
perl -ne '/^### Usage:/ && do { s/^### ?//; print }' < $0
exit 1
}

help()
{
perl -ne '/^###/ && do { s/^### ?//; print }' < $0
exit 0
}

for arg; do
case $arg in
-h) help ;;
-r) REPO=$2; shift; shift ;;
-*) usage ;;
esac
done

cmsdist()
{
URL="https://github.com/${USER}/${REPO}/pull"
stg init

for PULL in $PULLS; do
echo "Pull: $URL/$PULL"
BRANCH=`curl -ks GET ${URL}/${PULL} | grep "cms-sw/cmsdist:branch:comp" | awk -F' ' '{print $3}' | sed 's/"//g'`
if [ -n "$BRANCH" ]; then
echo "$PULL against comp branch? YES"
else
echo "$PULL against comp branch? NO! Skipping it ..."
continue
fi
authdate=`curl -ks ${URL}/${PULL}.patch | head -n4 | egrep -o 'Date:.*' | cut -d: -f 2- | sed 's/^ *//g'`
author=`curl -ks ${URL}/${PULL}.patch | head -n4 | egrep -o 'From:.*' | cut -d: -f 2-| sed 's/^ *//g'`
title=`curl -ks ${URL}/${PULL}.patch | head -n4 | grep 'PATCH' | cut -d"]" -f 2- | sed 's/^ *//g'`
echo "Summary: authdate=$authdate, author=$author, title=$title"

stg new -m "${title%\.}. Close #$PULL." pullreq-$PULL --author "$author" --authdate "$authdate"
curl -ks ${URL}/${PULL}.patch | git apply --whitespace=fix
# When there are new files, we need to add them
git add -A
stg refresh

echo ""
sleep 1
done
}

deployment()
{
URL="https://github.com/${USER}/${REPO}/pull"
stg init

for PULL in $PULLS; do
echo "Pull: $URL/$PULL"

authdate=`curl -ks ${URL}/${PULL}.patch | head -n4 | egrep -o 'Date:.*' | cut -d: -f 2- | sed 's/^ *//g'`
author=`curl -ks ${URL}/${PULL}.patch | head -n4 | egrep -o 'From:.*' | cut -d: -f 2- | sed 's/^ *//g'`
title=`curl -ks ${URL}/${PULL}.patch | head -n4 | grep 'PATCH' | cut -d"]" -f 2- | sed 's/^ *//g'`
echo "Summary: authdate=$authdate, author=$author, title=$title"

stg new -m "${title%\.}. Close #$PULL." pullreq-$PULL --author "$author" --authdate "$authdate"
curl -ks ${URL}/${PULL}.patch | git apply --whitespace=fix
# When there are new files, we need to add them
git add -A
stg refresh

echo ""
sleep 1
done
}

PULLS=$@

if [ "$REPO" == "cmsdist" ]; then
USER="cms-sw"
cmsdist
elif [ "$REPO" == "deployment" ]; then
USER="dmwm"
deployment
else
echo "$REPO I do *not* know this repository. Quitting ..."
exit 2
fi

exit 0

0 comments on commit 73fbad7

Please sign in to comment.