This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 22bfdc7b7b [ZEPPELIN-6070] Script for checking out PR to local (#4805)
22bfdc7b7b is described below
commit 22bfdc7b7ba73c56faecf5340cc2cf453ce683e0
Author: Cheng Pan <[email protected]>
AuthorDate: Mon Sep 2 06:29:24 2024 +0800
[ZEPPELIN-6070] Script for checking out PR to local (#4805)
---
dev/checkout_zeppelin_pr.sh | 62 +++++++++++++++++++++++++
dev/test_zeppelin_pr.py | 111 --------------------------------------------
2 files changed, 62 insertions(+), 111 deletions(-)
diff --git a/dev/checkout_zeppelin_pr.sh b/dev/checkout_zeppelin_pr.sh
new file mode 100755
index 0000000000..08a1a00ec7
--- /dev/null
+++ b/dev/checkout_zeppelin_pr.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# This utility creates a local branch PR_<PR_NUM> from specified pull request,
+# to help the test and review.
+#
+# Prerequisites:
+# Add Apache Zeppelin as remote repo, with name "apache" (or something else
+# defined by environment variable APACHE_ZEPPELIN_REMOTE_REPO_NAME)
+#
+# git remote add apache [email protected]:apache/zeppelin.git
+#
+
+set -o pipefail
+set -e
+set -x
+
+APACHE_ZEPPELIN_REMOTE_REPO_NAME=${APACHE_ZEPPELIN_REMOTE_REPO_NAME:-"apache"}
+
+function usage {
+ echo "Usage: dev/checkout_zeppelin_pr.sh [-f] <PR_NUM>"
+ echo " -f force overwrite of local branch (default: fail if exists)"
+ exit 1
+}
+
+if [[ ${#} -eq 0 ]]; then
+ usage
+fi
+
+FORCE=""
+while getopts ":f" arg; do
+ case "${arg}" in
+ f)
+ FORCE="--force"
+ ;;
+ ?)
+ usage
+ ;;
+ esac
+done
+shift "$(($OPTIND -1))"
+
+PR_NUM=$1
+
+git fetch ${APACHE_ZEPPELIN_REMOTE_REPO_NAME} pull/${PR_NUM}/head:PR_${PR_NUM}
${FORCE}
+git checkout PR_${PR_NUM}
diff --git a/dev/test_zeppelin_pr.py b/dev/test_zeppelin_pr.py
deleted file mode 100755
index 22602d0dd6..0000000000
--- a/dev/test_zeppelin_pr.py
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/usr/bin/python
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-#
-# This utility creates a local branch from specified pullrequest, to help the
test and review
-# You'll need to run this utility from master branch with command
-#
-# dev/test_zeppelin_pr.py [#PR]
-#
-# then pr[#PR] branch will be created.
-#
-
-from __future__ import print_function
-import sys, os, subprocess, json, codecs
-
-if sys.version_info[0] == 2:
- from urllib import urlopen
-else:
- from urllib.request import urlopen
-
-if len(sys.argv) == 1:
- print("usage) " + sys.argv[0] + " [#PR]")
- print(" eg) " + sys.argv[0] + " 122")
- sys.exit(1)
-
-
-pr=sys.argv[1]
-githubApi="https://api.github.com/repos/apache/zeppelin"
-
-reader = codecs.getreader("utf-8")
-prInfo = json.load(reader(urlopen(githubApi + "/pulls/" + pr)))
-if "message" in prInfo and prInfo["message"] == "Not Found":
- sys.stderr.write("PullRequest #" + pr + " not found\n")
- sys.exit(1)
-
-prUser=prInfo['user']['login']
-prRepoUrl=prInfo['head']['repo']['clone_url']
-prBranch=prInfo['head']['label'].replace(":", "/")
-print(prBranch)
-
-# create local branch
-exitCode = os.system("git checkout -b pr" + pr)
-if exitCode != 0:
- sys.exit(1)
-
-# add remote repository and fetch
-exitCode = os.system("git remote remove " + prUser)
-exitCode = os.system("git remote add " + prUser + " " + prRepoUrl)
-if exitCode != 0:
- sys.stderr.write("Can not add remote repository.\n")
- sys.exit(1)
-
-exitCode = os.system("git fetch " + prUser)
-if exitCode != 0:
- sys.stderr.write("Can't fetch remote repository.\n")
- sys.exit(1)
-
-
-currentBranch = subprocess.check_output("git rev-parse --abbrev-ref HEAD",
shell=True).rstrip().decode("utf-8")
-
-print("Merge branch " + prBranch + " into " + currentBranch)
-
-rev = subprocess.check_output("git rev-parse " + prBranch,
shell=True).rstrip().decode("utf-8")
-prAuthor = subprocess.check_output("git --no-pager show -s --format=\"%an
<%ae>\" " + rev, shell=True).rstrip().decode("utf-8")
-prAuthorDate = subprocess.check_output("git --no-pager show -s
--format=\"%ad\" " + rev, shell=True).rstrip().decode("utf-8")
-
-prTitle = prInfo['title']
-prBody = prInfo['body']
-
-commitList = subprocess.check_output("git log --pretty=format:\"%h\" " +
currentBranch + ".." + prBranch, shell=True).rstrip().decode("utf-8")
-authorList = []
-for commitHash in commitList.split("\n"):
- a = subprocess.check_output("git show -s --pretty=format:\"%an <%ae>\"
"+commitHash, shell=True).rstrip().decode("utf-8")
- if a not in authorList:
- authorList.append(a)
-
-commitMsg = prTitle + "\n"
-if prBody :
- commitMsg += prBody + "\n\n"
-for author in authorList:
- commitMsg += "Author: " + author +"\n"
-commitMsg += "\n"
-commitMsg += "Closes #" + pr + " from " + prBranch + " and squashes the
following commits:\n\n"
-commitMsg += subprocess.check_output("git log --pretty=format:\"%h [%an] %s\"
" + currentBranch + ".." + prBranch, shell=True).rstrip().decode("utf-8")
-
-exitCode = os.system("git merge --no-commit --squash " + prBranch)
-if exitCode != 0:
- sys.stderr.write("Can not merge\n")
- sys.exit(1)
-
-exitCode = os.system('git commit -a --author "' + prAuthor + '" --date "' +
prAuthorDate + '" -m"' + commitMsg + '"')
-if exitCode != 0:
- sys.stderr.write("Commit failed\n")
- sys.exit(1)
-
-os.system("git remote remove " + prUser)
-print("Branch " + prBranch + " is merged into " + currentBranch)