From commits-return-14004-archive-asf-public=cust-asf.ponee.io@pulsar.incubator.apache.org Thu Sep 6 10:22:59 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 50F951807A5 for ; Thu, 6 Sep 2018 10:22:57 +0200 (CEST) Received: (qmail 38544 invoked by uid 500); 6 Sep 2018 08:22:56 -0000 Mailing-List: contact commits-help@pulsar.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pulsar.incubator.apache.org Delivered-To: mailing list commits@pulsar.incubator.apache.org Received: (qmail 38532 invoked by uid 99); 6 Sep 2018 08:22:56 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Sep 2018 08:22:56 +0000 From: GitBox To: commits@pulsar.apache.org Subject: [GitHub] ivankelly commented on a change in pull request #2526: [dev] provide a python merge script for merging pull requests Message-ID: <153622217569.28507.3543156263671380867.gitbox@gitbox.apache.org> Date: Thu, 06 Sep 2018 08:22:55 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit ivankelly commented on a change in pull request #2526: [dev] provide a python merge script for merging pull requests URL: https://github.com/apache/incubator-pulsar/pull/2526#discussion_r215531360 ########## File path: dev/pulsar-merge-pr.py ########## @@ -0,0 +1,699 @@ +#!/usr/bin/env 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. +# + +# Utility for creating well-formed pull request merges and pushing them to Apache. This script is a modified version +# of the one created by the BookKeeper project (https://github.com/apache/bookkeeper/blob/master/dev/bk-merge-pr.py). +# +# Usage: ./pulsar-merge-pr.py (see config env vars below) +# +# This utility assumes you already have local a pulsar git folder and that you +# have added remotes corresponding to the github apache pulsar repo. + +import json +import os +import re +import subprocess +import sys +import urllib2 + +PROJECT_NAME = "incubator-pulsar" + +CAPITALIZED_PROJECT_NAME = "pulsar".upper() +GITHUB_ISSUES_NAME = "issue".upper() + +# Location of the local git repository +REPO_HOME = os.environ.get("%s_HOME" % CAPITALIZED_PROJECT_NAME, os.getcwd()) +# Remote name which points to the GitHub site +PR_REMOTE_NAME = os.environ.get("PR_REMOTE_NAME", "apache") +# Remote name which points to Apache git +PUSH_REMOTE_NAME = os.environ.get("PUSH_REMOTE_NAME", "apache") +# Reference branch name +DEV_BRANCH_NAME = os.environ.get("DEV_BRANCH_NAME", "master") +# Github API page size +GITHUB_PAGE_SIZE = os.environ.get("GH_PAGE_SIZE", "100") +# 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. +GITHUB_OAUTH_KEY = os.environ.get("GITHUB_OAUTH_KEY") + +GITHUB_USER = os.environ.get("GITHUB_USER", "apache") +GITHUB_BASE = "https://github.com/%s/%s/pull" % (GITHUB_USER, PROJECT_NAME) +GITHUB_API_URL = "https://api.github.com" +GITHUB_API_BASE = "%s/repos/%s/%s" % (GITHUB_API_URL, GITHUB_USER, PROJECT_NAME) +# Prefix added to temporary branches +TEMP_BRANCH_PREFIX = "PR_TOOL" +RELEASE_BRANCH_PREFIX = "branch-" + +DEFAULT_FIX_VERSION = os.environ.get("DEFAULT_FIX_VERSION", "0.9.1.0") + +def get_json(url, preview_api = False): + try: + request = urllib2.Request(url) + if GITHUB_OAUTH_KEY: + request.add_header('Authorization', 'token %s' % GITHUB_OAUTH_KEY) + if preview_api: + request.add_header('Accept', 'application/vnd.github.black-cat-preview+json') + return json.load(urllib2.urlopen(request)) + except urllib2.HTTPError as e: + if "X-RateLimit-Remaining" in e.headers and e.headers["X-RateLimit-Remaining"] == '0': + print "Exceeded the GitHub API rate limit; see the instructions in " + \ + "pulsar-merge-pr.py to configure an OAuth token for making authenticated " + \ + "GitHub requests." + else: + print "Unable to fetch URL, exiting: %s" % url + sys.exit(-1) + +def post_json(url, data): + try: + request = urllib2.Request(url, data, { 'Content-Type': 'application/json' }) + if GITHUB_OAUTH_KEY: + request.add_header('Authorization', 'token %s' % GITHUB_OAUTH_KEY) + return json.load(urllib2.urlopen(request)) + except urllib2.HTTPError as e: + if "X-RateLimit-Remaining" in e.headers and e.headers["X-RateLimit-Remaining"] == '0': + print "Exceeded the GitHub API rate limit; see the instructions in " + \ + "pulsar-merge-pr.py to configure an OAuth token for making authenticated " + \ + "GitHub requests." + else: + print "Unable to fetch URL, exiting: %s - %s" % (url, e) + sys.exit(-1) Review comment: call fail() ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services