postpush 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/env python
  2. import datetime
  3. """
  4. If you are using github.com frank works pretty much with github's own hooks,
  5. which will submit a JSON to your listening server.
  6. If you don't feel like working with github you can host your repository at
  7. the same place where you host frank, and then you can simply run this script
  8. directly after your push.
  9. If this not the case you will need to invoke the script with the correct
  10. parameters.
  11. See below.
  12. """
  13. # List changed in the last commit
  14. # git diff-tree --no-commit-id --name-only -r $(git rev-list HEAD^..HEAD)
  15. # Python version
  16. # [patch.new_file_path for patch in repo.diff('HEAD', 'HEAD~1'))]
  17. SUBMIT_HOST = '192.168.1.100'
  18. SUBMIT_PORT = 5000
  19. GIT_URL = "git@yourhost.domain:oz123/frank.git"
  20. """
  21. This scripts submit a very simplified json record witht the following
  22. information::
  23. {
  24. 'repository': full_path_on_file_system
  25. 'commit': 1481a2de7b2a7d02428ad93446ab166be7793fbb
  26. 'branch': branch_name
  27. "committer":{
  28. "email":"lolwut@noway.biz",
  29. "name":"Garen Torikian",
  30. },
  31. "author": {
  32. "email":"lolwut@noway.biz",
  33. "name":"Garen Torikian",
  34. },
  35. "url": "host.domain.full_path"
  36. }
  37. """
  38. from pygit2 import Repository
  39. repo = Repository('..')
  40. head = repo.head
  41. commit = head.get_object()
  42. json_to_submit = {}
  43. json_to_submit['commit'] = head.id
  44. json_to_submit['branch'] = repo.head.shorthand
  45. json_to_submit['committer'] = {'email': commit.committer.email,
  46. 'name', commit.committer.name}
  47. json_to_submit['author'] = {'email': commit.author.email,
  48. 'name', commit.author.name}
  49. json_to_sumbit['url'] = GIT_URL
  50. json_to_submit['time'] = datetime.datetime.now()