repo.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding: utf-8 -*-
  2. """
  3. walle-web
  4. :copyright: © 2015-2017 walle-web.io
  5. :created time: 2017-03-25 11:15:01
  6. :author: wushuiyong@walle-web.io
  7. """
  8. from flask import request, abort
  9. from walle.api.api import SecurityResource
  10. from walle.service.deployer import Deployer
  11. class RepoAPI(SecurityResource):
  12. actions = ['tags', 'branches', 'commits']
  13. def get(self, action, commit=None):
  14. """
  15. fetch project list or one item
  16. /project/<int:project_id>
  17. :return:
  18. """
  19. super(RepoAPI, self).get()
  20. project_id = request.args.get('project_id', '')
  21. if action in self.actions:
  22. self_action = getattr(self, action.lower(), None)
  23. return self_action(project_id=project_id)
  24. else:
  25. abort(404)
  26. def tags(self, project_id=None):
  27. """
  28. fetch project list or one item
  29. /tag/
  30. :return:
  31. """
  32. wi = Deployer(project_id=project_id)
  33. tag_list = wi.list_tag()
  34. tags = tag_list.stdout.strip().split('\n')
  35. return self.render_json(data={
  36. 'tags': tags,
  37. })
  38. def branches(self, project_id=None):
  39. """
  40. fetch project list or one item
  41. /tag/
  42. :return:
  43. """
  44. wi = Deployer(project_id=project_id)
  45. branches = wi.list_branch()
  46. return self.render_json(data={
  47. 'branches': branches,
  48. })
  49. def commits(self, project_id):
  50. """
  51. fetch project list or one item
  52. /tag/
  53. :return:
  54. """
  55. branch = request.args.get('branch', '')
  56. wi = Deployer(project_id=project_id)
  57. commits = wi.list_commit(branch)
  58. return self.render_json(data={
  59. 'branches': commits,
  60. })