From 234de3458f290f899a4c730a3aea44fcd7f613b9 Mon Sep 17 00:00:00 2001 From: Hunter Allen Date: Mon, 22 Jan 2018 16:44:29 -0500 Subject: [PATCH] More Explicit PRs (#120) * Added a get_last_hash function that returns the hash of the previous commit. * Write a default comment style in English that is automatically generated from the calling arguments. * Update PR style changes for open embedded. --- superflore/generators/bitbake/run.py | 28 ++++++++++++++++++++++++-- superflore/generators/ebuild/run.py | 30 +++++++++++++++++++++++----- superflore/repo_instance.py | 3 +++ superflore/utils.py | 2 +- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/superflore/generators/bitbake/run.py b/superflore/generators/bitbake/run.py index 032616f6..011cf5a5 100644 --- a/superflore/generators/bitbake/run.py +++ b/superflore/generators/bitbake/run.py @@ -66,8 +66,14 @@ def main(): nargs='+', help='generate only the specified packages' ) + parser.add_argument( + '--pr-comment', + help='comment to add to the PR', + type=str + ) selected_targets = active_distros args = parser.parse_args(sys.argv[1:]) + pr_comment = args.pr_comment if args.all: warn('"All" mode detected... this may take a while!') preserve_existing = False @@ -82,6 +88,24 @@ def main(): os.chmod(_repo, 17407) # clone if args.output-repository_path is None overlay = RosMeta(_repo, not args.output_repository_path) + if not args.only: + pr_comment = pr_comment or ( + 'Superflore yocto generator began regeneration of all ' + + 'packages form ROS distribution(s) %s from allenh1\'s ' + + 'fork of Meta-ROS from commit %s.' % ( + selected_targets, + overlay.repo.get_last_hash() + ) + ) + else: + pr_comment = pr_comment or ( + 'Superflore yocto generator began regeneration of package(s)' + + ' %s from ROS distro %s from allenh1\'s fork of Meta-ROS ' + + 'from commit %s.' % ( + args.only, + overlay.repo.get_last_hash() + ) + ) # generate installers total_installers = dict() total_broken = set() @@ -117,7 +141,7 @@ def main(): overlay.regenerate_manifests(regen_dict) overlay.commit_changes(args.ros_distro) delta = "Regenerated: '%s'\n" % args.only - file_pr(overlay, delta, '') + file_pr(overlay, delta, '', pr_comment) ok('Successfully synchronized repositories!') sys.exit(0) @@ -187,5 +211,5 @@ def main(): # Commit changes and file pull request overlay.commit_changes(args.ros_distro) - file_pr(overlay, delta, missing_deps, args.ros_distro) + file_pr(overlay, delta, missing_deps, pr_comment) ok('Successfully synchronized repositories!') diff --git a/superflore/generators/ebuild/run.py b/superflore/generators/ebuild/run.py index f72b6d27..0ad89a24 100755 --- a/superflore/generators/ebuild/run.py +++ b/superflore/generators/ebuild/run.py @@ -85,6 +85,7 @@ def main(): type=str ) args = parser.parse_args(sys.argv[1:]) + pr_comment = args.pr_comment selected_targets = None if args.all: warn('"All" mode detected... This may take a while!') @@ -130,12 +131,31 @@ def main(): os.chmod(_repo, 17407) # clone if args.output_repository_path is None overlay = RosOverlay(_repo, not args.output_repository_path) + if not preserve_existing and not args.only: + pr_comment = pr_comment or ( + 'Superflore ebuild generator began regeneration of all' + ' packages from ROS distro %s from ROS-Overlay commit %s.' % ( + selected_targets, + overlay.repo.get_last_hash() + ) + ) + elif not args.only: + pr_comment = pr_comment or ( + 'Superflore ebuild generator ran update from ROS-Overlay ' + + 'commit %s.' % (overlay.repo.get_last_hash()) + ) # generate installers total_installers = dict() total_broken = set() total_changes = dict() - if args.only: + pr_comment = pr_comment or ( + 'Superflore ebuild generator began regeneration of ' + + 'package(s) %s from commit %s.' % ( + args.only, + overlay.repo.get_last_hash() + ) + ) for pkg in args.only: info("Regenerating package '%s'..." % pkg) try: @@ -153,15 +173,15 @@ def main(): regen_dict[args.ros_distro] = args.only overlay.regenerate_manifests(regen_dict) overlay.commit_changes(args.ros_distro) - delta = "Regenerated: '%s'\n" % args.only if args.dry_run: + # TODO(allenh1): update this PR style. info('Running in dry mode, not filing PR') title_file = open('.pr-title.tmp', 'w') title_file.write('rosdistro sync, {0}\n'.format(time.ctime())) pr_message_file = open('.pr-message.tmp', 'w') - pr_message_file.write('%s\n%s\n' % (delta, '')) + pr_message_file.write('%s\n%s\n' % (pr_comment, '')) sys.exit(0) - file_pr(overlay, delta, '', args.pr_comment) + file_pr(overlay, '', '', pr_comment) clean_up() ok('Successfully synchronized repositories!') sys.exit(0) @@ -240,7 +260,7 @@ def main(): pr_message_file = open('.pr-message.tmp', 'w') pr_message_file.write('%s\n%s\n' % (delta, missing_deps)) sys.exit(0) - file_pr(overlay, delta, missing_deps, args.pr_comment) + file_pr(overlay, delta, missing_deps, pr_comment) clean_up() ok('Successfully synchronized repositories!') diff --git a/superflore/repo_instance.py b/superflore/repo_instance.py index ecf8eb9e..af4957a6 100644 --- a/superflore/repo_instance.py +++ b/superflore/repo_instance.py @@ -89,3 +89,6 @@ def pull_request(self, message, title, branch='master', remote='origin'): target_remote='{0}'.format(remote), ) ok('Successfully filed a pull request.') + + def get_last_hash(self): + return self.repo.head.object.hexsha diff --git a/superflore/utils.py b/superflore/utils.py index ae77ead6..a524df6f 100644 --- a/superflore/utils.py +++ b/superflore/utils.py @@ -45,7 +45,7 @@ def file_pr(overlay, delta, missing_deps, comment): msg = '' if comment: msg += '%s\n' % comment - msg += 'This Superflore PR was generated with the following arguments.\n\n' + msg += 'To reproduce this PR, run the following command.\n\n' msg += '```\n%s\n```' % ' '.join(sys.argv) try: overlay.pull_request('%s\n%s\n%s' % (msg, delta, missing_deps))