forked from dmwm/deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script used to fetch pullRequests and create stg patches
- Loading branch information
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |