Skip to content

Commit

Permalink
More Explicit PRs (#120)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
allenh1 authored Jan 22, 2018
1 parent 780cb60 commit 234de34
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
28 changes: 26 additions & 2 deletions superflore/generators/bitbake/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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!')
30 changes: 25 additions & 5 deletions superflore/generators/ebuild/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!')
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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!')
3 changes: 3 additions & 0 deletions superflore/repo_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion superflore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 234de34

Please # to comment.