make it work with any Apache repository mirrored on GitHub

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/fed5c2b0
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/fed5c2b0
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/fed5c2b0

Branch: refs/heads/master
Commit: fed5c2b06a7d7aa5d9715ab1430492ab3146a4fc
Parents: 23b9365
Author: Remi Bergsma <[email protected]>
Authored: Mon Aug 24 11:59:24 2015 +0200
Committer: Remi Bergsma <[email protected]>
Committed: Mon Aug 24 16:00:30 2015 +0200

----------------------------------------------------------------------
 tools/git/git-pr | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fed5c2b0/tools/git/git-pr
----------------------------------------------------------------------
diff --git a/tools/git/git-pr b/tools/git/git-pr
index 48b8168..49eee79 100755
--- a/tools/git/git-pr
+++ b/tools/git/git-pr
@@ -47,6 +47,7 @@ fi
 # Check the arguments
 if [ -z ${prId} ]; then
   echo "Usage: git pr pool-request-number [ --force ]"
+  echo "Works for any Apache repository mirrored on GitHub'"
   echo "For instructions, see: 
https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61311655";
   clean_up_and_exit 1
 fi
@@ -54,13 +55,14 @@ fi
 # Vars we need
 jsonTmp="${PWD}/${prId}.json"
 tmpMessageFile="${PWD}/.git-tmp-message.txt"
+repoName=$(basename `git rev-parse --show-toplevel`)
 
 # We need UTF-8 to support the GitHub '...' 3-dots-in-1-char, for example.
 export LANG="en_EN.UTF-8"
 
 if [ "${prId}" -eq "${prId}" 2>/dev/null ]; then
   # Get json data from Github API
-  curl -s https://api.github.com/repos/apache/cloudstack/pulls/${prId} > 
${jsonTmp}
+  curl -s https://api.github.com/repos/apache/${repoName}/pulls/${prId} > 
${jsonTmp}
 else
   echo "ERROR: Pull-request id must be an integer, not '${prId}'"
   clean_up_and_exit 1
@@ -176,9 +178,9 @@ elif [ "${prMergeableState}" != "clean" ] && [ ${force} -eq 
1 ]; then
   echo "WARNING: You used --force to merge a PR with non-clean merge state 
'${prMergeableState}'."
 fi
 
-github_remote=$(git remote -v | grep "apache/cloudstack.git" | head -n 1 | cut 
-f1)
+github_remote=$(git remote -v | grep -E "apache/${repoName}(.git)?" | head -n 
1 | cut -f1)
 if [ ${#github_remote} -eq 0 ]; then
-  echo "ERROR: We couldn't find a git remote pointing to 
'apache/cloudstack.git' to merge the PR from."
+  echo "ERROR: We couldn't find a git remote pointing to 
'apache/${repoName}.git' to merge the PR from."
   echo "INFO: Currently, your configured remotes are:"
   echo "INFO: 
***********************************************************************************"
   git remote -v
@@ -186,13 +188,13 @@ if [ ${#github_remote} -eq 0 ]; then
   echo "INFO: To merge a PR, we need access to two remotes: "
   echo "INFO: 1. Read-only access to GitHub mirror"
   echo "INFO: 2. Read/write access to Apache git"
-  echo "INFO: Please add a remote like this: 'git remote add github 
https://github.com/apache/cloudstack.git'"
+  echo "INFO: Please add a remote like this: 'git remote add github 
https://github.com/apache/${repoName}.git'"
   echo "INFO: For more help, visit: 
https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61311655";
   echo "INFO: Once done, run this script again."
   clean_up_and_exit 1
 fi
 
-echo "INFO: Using remote repository '${github_remote}' to fetch PR (should 
point to github.com/apache/cloudstack.git)"
+echo "INFO: Using remote repository '${github_remote}' to fetch PR (should 
point to github.com/apache/${repoName}.git)"
 echo "INFO: PR #${prId} against branch '${prDestinationBranch}' from 
'${prAuthor}': '${prTitle}'"
 echo "INFO: has state '${prState}' and mergable state '${prMergeableState}', 
about to be merged in branch '${currentBranch}'."
 
@@ -220,6 +222,7 @@ if [ $? -eq 0 ]; then
 else
   echo "ERROR: Merge failed, aborting."
   git merge --abort
+  clean_up_and_exit 1
 fi
 
 # What's next

Reply via email to