summaryrefslogtreecommitdiffstats
path: root/build/functions.sh
diff options
context:
space:
mode:
authorDan Radez <dradez@redhat.com>2016-06-13 14:56:16 -0400
committerDan Radez <dradez@redhat.com>2016-06-13 20:29:19 -0400
commitaf2f93cebc62cd0d6f7c4b1a74fdeb65fbcf90a8 (patch)
tree7602423433ca36535dfbd2e3b2114d8c4be5ce57 /build/functions.sh
parent61c08699e3cdfec36633ae869fddbc4f22c32244 (diff)
puppet-tripleo fork integration
moving the github integration with pull requests into a function so we can continue to service opnfv-tht and also service opnfv-puppet-tripleo with the same code opnfv-puppet-tripleo-pr: 3 Change-Id: Ief2b1e7309defce9ed2029f6baade3c1371b7d96 Signed-off-by: Dan Radez <dradez@redhat.com>
Diffstat (limited to 'build/functions.sh')
-rw-r--r--build/functions.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/build/functions.sh b/build/functions.sh
new file mode 100644
index 00000000..e61102ef
--- /dev/null
+++ b/build/functions.sh
@@ -0,0 +1,46 @@
+##############################################################################
+# Copyright (c) 2016 Dan Radez (Red Hat) and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+clone_fork () {
+ # ARG 1: opnfv-tht or opnfv-python-triplo
+ echo "Cloning $1"
+
+ # Use apex tripleo-heat-templates fork
+ local ghcreds=""
+ local pr_num=""
+ local ref="stable/colorado"
+ local repo="https://github.com/trozet/$1"
+
+ if git log -1 | grep "${1}-pr:" | grep -o '[0-9]*'; then
+ pr_num=$(git log -1 | grep "${1}-pr:" | grep -o '[0-9]*')
+ fi
+
+ if [ "$pr_num" != "" ]; then
+ echo "Using pull request $pr_num from $repo"
+ # Source credentials since we are rate limited to 60/day
+ if [ -f ~/.githubcreds ]; then
+ source ~/.githubcreds
+ ghcreds=" -u $GHUSERNAME:$GHACCESSTOKEN"
+ fi
+
+ PR=$(curl $ghcreds https://api.github.com/repos/trozet/$1/pulls/$pr_num)
+
+ # Do not pull from merged branches
+ MERGED=$(python -c "import json; print json.loads('''$PR'''.replace('\n', '').replace('\r', ''))['merged']")
+ if [ "$MERGED" == "False" ]; then
+ ref=$(python -c "import json; print json.loads('''$PR'''.replace('\n', '').replace('\r', ''))['head']['ref']")
+ echo "Setting GitHub Ref to: $REF"
+ repo=$(python -c "import json; print json.loads('''$PR'''.replace('\n', '').replace('\r', ''))['head']['repo']['clone_url']")
+ echo "Setting GitHub URL to: $repo"
+ fi
+ fi
+
+ rm -rf $1
+ git clone $repo -b $ref $1
+}