This section documents the process of merging code changes contributed via Github Pull Requests. It assumes you have a clone of ZooKeeper's Git repository and the user has committer access rights.
zk-merge-pr.py is a script that automates the process of accepting a code change into the project. It creates a temporary branch from apache/master, squashes the commits in the pull request, rewrites the commit message in the squashed commit to follow a standard format including information about each original commit, merges the squashed commit into the temporary branch, pushes the code to apache/master and closes the JIRA ticket. The push will then be mirrored to apache-github/master, which will cause the PR to be closed due to the pattern in the commit message. Note that the script will ask the user before executing remote updates (ie git push and closing JIRA ticket), so it can still be used even if the user wants to skip those steps.
This script is a modified version of an Apache Kafka tool: https://github.com/apache/kafka/blob/trunk/kafka-merge-pr.py that, in its turn, is a modified version of an Apache Spark tool: https://github.com/apache/spark/blob/master/dev/merge_spark_pr.py
Step-by-step guide
Setting Up:
Add aliases for the remotes expected by the merge script (if you haven't already):
$ cd $ZOOKEPER_BASE_DIR $ git remote add apache-github https://github.com/apache/zookeeper.git $ git remote add apache https://git-wip-us.apache.org/repos/asf/zookeeper.git
- Before starting using the script it’s required to setup environment variables below:
PR_REMOTE_NAME - points to Github mirror of Apache project (default git-remote name: apache-github)
PUSH_REMOTE_NAME - points to Apache Git repo (default git-remote name: apache)
$ export PR_REMOTE_NAME=apache-github $ export PUSH_REMOTE_NAME=apache
Install jira-python:
sudo easy_install JIRA
- Setup environment variables to JIRA credentials:
JIRA_USERNAME & JIRA_PASSWORD - apache JIRA credentials
$ export JIRA_USERNAME=myname $ export JIRA_PASSWORD=mypassword
If you don't execute steps 3 and 4 then the script will not be able to automatically close the JIRA after merging the PR.
- (Optional) Setup Github OAUTH token:
GITHUB_OAUTH_KEY (optional) - if you exceed Github API rate limit then set this variable to allow it to surpass this limit as the script comment states:
$ export GITHUB_OAUTH_KEY=<your-github-oauth-key>
“OAuth key used for issuing requests against the GitHub API. If this is not defined, then requests will be unauthenticated. You should only need to configure this if you find yourself regularly exceeding your IP's unauthenticated request rate limit. You can create an OAuth key at https://github.com/settings/tokens. This script only requires the "public_repo" scope.”
Once the pull request is ready to be merged (it has been reviewed, feedback has been addressed, CI build has been successful and the branch merges cleanly into trunk):
Run the merge script:
python kafka-merge-pr.py
- Answer the questions prompted by the script.
Related articles