From a69f6171ed0c8a80a2030dbb04474496503f8301 Mon Sep 17 00:00:00 2001 From: Tudor Golubenco Date: Fri, 30 Mar 2018 08:16:27 +0200 Subject: [PATCH] Make cherrypick_pr and open_pr scripts add version labels (#6707) When cherry-picking, automatically reads the version from the target branch and adds it as a label to the original PR. When opening a new PR, automatically add the version label. --- dev-tools/cherrypick_pr | 15 +++++++++++++++ dev-tools/open_pr | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/dev-tools/cherrypick_pr b/dev-tools/cherrypick_pr index b2b08ee33f93..c648d6a176f0 100755 --- a/dev-tools/cherrypick_pr +++ b/dev-tools/cherrypick_pr @@ -2,6 +2,7 @@ """Cherry pick and backport a PR""" import sys +import os import argparse from os.path import expanduser import re @@ -148,9 +149,23 @@ def main(): # remove needs backport label from the original PR session.delete(base + "/issues/{}/labels/needs_backport".format(args.pr_number)) + # get version and set a version label on the original PR + version = get_version(os.getcwd()) + if version: + session.post( + base + "/issues/{}/labels".format(args.pr_number), json=["v" + version]) + print("\nDone. PR created: {}".format(new_pr["html_url"])) print("Please go and check it and add the review tags") +def get_version(beats_dir): + pattern = re.compile(r'(const\s|)\w*(v|V)ersion\s=\s"(?P.*)"') + with open(os.path.join(beats_dir, "libbeat/version/version.go"), "r") as f: + for line in f: + match = pattern.match(line) + if match: + return match.group('version') + if __name__ == "__main__": sys.exit(main()) diff --git a/dev-tools/open_pr b/dev-tools/open_pr index b98599cab357..1bde2d3871ce 100755 --- a/dev-tools/open_pr +++ b/dev-tools/open_pr @@ -2,6 +2,7 @@ """Open a PR from the current branch""" import sys +import os import argparse import requests import re @@ -54,6 +55,11 @@ def main(): if args.wip: lables += "in progress" + # get version and set a version label on the original PR + version = get_version(os.getcwd()) + if version: + labels.append("v" + version) + print("Branch: {}".format(args.branch)) print("Remote: {}".format(args.remote)) print("Local branch: {}".format(local_branch)) @@ -98,5 +104,14 @@ def main(): print("Please go and review it for the message and labels.") +def get_version(beats_dir): + pattern = re.compile(r'(const\s|)\w*(v|V)ersion\s=\s"(?P.*)"') + with open(os.path.join(beats_dir, "libbeat/version/version.go"), "r") as f: + for line in f: + match = pattern.match(line) + if match: + return match.group('version') + + if __name__ == "__main__": sys.exit(main())