post-update 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. """
  18. This scripts submit a very simplified json record witht the following
  19. information::
  20. {
  21. 'repository': full_path_on_file_system
  22. 'commit': 1481a2de7b2a7d02428ad93446ab166be7793fbb
  23. 'branch': branch_name
  24. "committer":{
  25. "email":"lolwut@noway.biz",
  26. "name":"Garen Torikian",
  27. },
  28. "author": {
  29. "email":"lolwut@noway.biz",
  30. "name":"Garen Torikian",
  31. },
  32. "url": "host.domain.full_path"
  33. }
  34. """
  35. SUBMIT_HOST = '192.168.1.100'
  36. SUBMIT_PORT = 5000
  37. GITURL = "git@yourhost.domain:oz123/frank.git"
  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'] = commit.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_submit['url'] = GITURL
  50. json_to_submit['time'] = datetime.datetime.now()
  51. print json_to_submit