Skip to content

Commit

Permalink
dev-tools: fix pylint in cherrypick_pr (#3770)
Browse files Browse the repository at this point in the history
  • Loading branch information
7AC authored and ruflin committed Mar 24, 2017
1 parent 8ae76e6 commit 0d85e09
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions dev-tools/cherrypick_pr
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python
"""Cherry pick and backport a PR"""

import sys
import json
import argparse
from os.path import expanduser
import re
from subprocess import check_call, call, check_output
import requests
import re

"""
Example usage:
Expand Down Expand Up @@ -35,6 +36,7 @@ PR.


def main():
"""Main"""
parser = argparse.ArgumentParser(
description="Creates a PR for merging two branches")
parser.add_argument("to_branch",
Expand All @@ -43,7 +45,7 @@ def main():
help="The PR number being merged (e.g. 2345)")
parser.add_argument("commit_hashes", metavar="hash", nargs="+",
help="The commit hashes to cherry pick." +
" You can specify multiple.")
" You can specify multiple.")
parser.add_argument("--yes", action="store_true",
help="Assume yes. Warning: discards local changes.")
parser.add_argument("--continue", action="store_true",
Expand All @@ -52,10 +54,10 @@ def main():
help="From branch")
parser.add_argument("--create_pr", action="store_true",
help="Create a PR using the Github API " +
"(requires token in ~/.github_token)")
"(requires token in ~/.github_token)")
args = parser.parse_args()

print args
print(args)

tmp_branch = "backport_{}_{}".format(args.pr_number, args.to_branch)

Expand Down Expand Up @@ -106,33 +108,32 @@ def main():
else:
token = open(expanduser("~/.github_token"), "r").read().strip()
base = "https://api.github.com/repos/elastic/beats"
s = requests.Session()
s.headers.update({"Authorization": "token " + token})
session = requests.Session()
session.headers.update({"Authorization": "token " + token})

original_pr = s.get(base+"/pulls/"+args.pr_number).json()
original_pr = session.get(base + "/pulls/" + args.pr_number).json()

# get the github username from the remote where we pushed
remote_url = check_output("git remote get-url {}".format(remote),
shell=True)
remote_user = re.search("github.com:(.+)/beats", remote_url).group(1)

# create PR
r = s.post(base+"/pulls", json=dict(
title="Cherry-pick to {}: {}"
.format(args.to_branch, original_pr["title"]),
request = session.post(base + "/pulls", json=dict(
title="Cherry-pick to {}: {}".format(args.to_branch, original_pr["title"]),
head=remote_user + ":" + tmp_branch,
base=args.to_branch,
body="Cherry-pick of PR #{} to {} branch. Original message: \n\n{}"
.format(args.pr_number, args.to_branch, original_pr["body"])
.format(args.pr_number, args.to_branch, original_pr["body"])
))
if r.status_code > 299:
print("Creating PR failed: {}".format(r.json()))
if request.status_code > 299:
print("Creating PR failed: {}".format(request.json()))
sys.exit(1)
new_pr = r.json()
new_pr = request.json()

# add labels
s.post(base+"/issues/{}/labels".format(new_pr["number"]),
json=["backport", "review"])
session.post(
base + "/issues/{}/labels".format(new_pr["number"]), json=["backport", "review"])

print("\nDone. PR created: {}".format(new_pr["html_url"]))
print("Please go and check it and add the review tags")
Expand Down

0 comments on commit 0d85e09

Please sign in to comment.