diff --git a/admin/getPulls b/admin/getPulls new file mode 100755 index 000000000000..90f1ac52c863 --- /dev/null +++ b/admin/getPulls @@ -0,0 +1,99 @@ +#!/bin/bash + +### It fetches pullRequests made against a given . +### 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 +### 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