Advertisement
Guest User

Untitled

a guest
May 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import os
  4. import webbrowser
  5. import shlex
  6. import subprocess
  7. import tempfile
  8. import click
  9.  
  10. CMD_TPL = '''git log {0}...{1} "--pretty=format:<li><a href="{remote_origin}/commit/%H">view commit</a> (Author: %an) %s - %Cgreen%ar</li>"'''
  11. REMOTE_ORIGIN = 'git config --get remote.origin.url'
  12.  
  13. def get_remote():
  14. ret = subprocess.check_output(shlex.split(REMOTE_ORIGIN))
  15. return ret.decode('utf-8').rsplit('.', 1)[0]
  16.  
  17. def get_compare_result(commits):
  18. remote_origin = get_remote()
  19. cmd = CMD_TPL.format(*commits, remote_origin=remote_origin)
  20. ret = subprocess.check_output(shlex.split(cmd))
  21. return ret.decode('utf-8')
  22.  
  23. def write_to_file(result):
  24. with tempfile.NamedTemporaryFile('w', suffix='.html', delete=False) as f:
  25. f.write(result)
  26. webbrowser.open_new_tab('file:///' + f.name)
  27.  
  28.  
  29. @click.command()
  30. @click.option('-b', '--branch', default='dev', required=False, help='The remote branch that compared with local HEAD commit.')
  31. @click.option('-c', '--commit', required=False, multiple=True, help='The commits to compare.')
  32. @click.option('-r', '--repo', required=True, help='The git repo.')
  33. def get_change_log(branch, commit, repo):
  34. os.chdir(os.path.abspath(os.path.join(r'e:\gitrepos', repo)))
  35. if not len(commit):
  36. commit = [f'origin/{branch}', 'HEAD']
  37. if len(commit) == 1:
  38. commit = ['HEAD'] + list(commit)
  39. ret = get_compare_result(commit)
  40. write_to_file(ret)
  41.  
  42.  
  43. if __name__ == '__main__':
  44. get_change_log()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement