Skip to content

Commit

Permalink
Make cherrypick_pr and open_pr scripts add version labels (#6707)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tsg authored and ruflin committed Mar 30, 2018
1 parent 1a25bea commit a69f617
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dev-tools/cherrypick_pr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Cherry pick and backport a PR"""

import sys
import os
import argparse
from os.path import expanduser
import re
Expand Down Expand Up @@ -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<version>.*)"')
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())
15 changes: 15 additions & 0 deletions dev-tools/open_pr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Open a PR from the current branch"""

import sys
import os
import argparse
import requests
import re
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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<version>.*)"')
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())

0 comments on commit a69f617

Please sign in to comment.