git-commit-mklog.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python3
  2. # Copyright (C) 2020 Free Software Foundation, Inc.
  3. #
  4. # This file is part of GCC.
  5. #
  6. # GCC is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3, or (at your option)
  9. # any later version.
  10. #
  11. # GCC is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with GCC; see the file COPYING. If not, write to
  18. # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
  19. # Boston, MA 02110-1301, USA.
  20. #
  21. # The script is wrapper for git commit-mklog alias where it parses
  22. # -b/--pr-numbers argument and passes it via environment variable
  23. # to mklog.py script.
  24. import argparse
  25. import os
  26. import subprocess
  27. if __name__ == '__main__':
  28. children_args = []
  29. myenv = os.environ.copy()
  30. parser = argparse.ArgumentParser(description='git-commit-mklog wrapped')
  31. parser.add_argument('-b', '--pr-numbers', action='store',
  32. type=lambda arg: arg.split(','), nargs='?',
  33. help='Add the specified PRs (comma separated)')
  34. parser.add_argument('-p', '--fill-up-bug-titles', action='store_true',
  35. help='Download title of mentioned PRs')
  36. parser.add_argument('--co',
  37. help='Add Co-Authored-By trailer (comma separated)')
  38. args, unknown_args = parser.parse_known_args()
  39. myenv['GCC_FORCE_MKLOG'] = '1'
  40. mklog_args = []
  41. if args.pr_numbers:
  42. mklog_args.append(f'-b {",".join(args.pr_numbers)}')
  43. if args.fill_up_bug_titles:
  44. mklog_args.append('-p')
  45. if mklog_args:
  46. myenv['GCC_MKLOG_ARGS'] = ' '.join(mklog_args)
  47. if args.co:
  48. for author in args.co.split(','):
  49. unknown_args.append(f'--trailer "Co-Authored-By: {author}"')
  50. commit_args = ' '.join(unknown_args)
  51. subprocess.run(f'git commit {commit_args}', shell=True, env=myenv)