repo.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. from walle.service.extensions import permission
  12. class RepoAPI(SecurityResource):
  13. actions = ['tags', 'branches', 'commits']
  14. @permission.upper_reporter
  15. def get(self, action, commit=None):
  16. """
  17. fetch project list or one item
  18. /project/<int:project_id>
  19. :return:
  20. """
  21. super(RepoAPI, self).get()
  22. project_id = request.args.get('project_id', '')
  23. if action in self.actions:
  24. self_action = getattr(self, action.lower(), None)
  25. return self_action(project_id=project_id)
  26. else:
  27. abort(404)
  28. def tags(self, project_id=None):
  29. """
  30. fetch project list or one item
  31. /tag/
  32. :return:
  33. """
  34. wi = Deployer(project_id=project_id)
  35. tag_list = wi.list_tag()
  36. tags = tag_list.stdout.strip().split('\n')
  37. return self.render_json(data={
  38. 'tags': tags,
  39. })
  40. def branches(self, project_id=None):
  41. """
  42. fetch project list or one item
  43. /tag/
  44. :return:
  45. """
  46. wi = Deployer(project_id=project_id)
  47. branches = wi.list_branch()
  48. return self.render_json(data={
  49. 'branches': branches,
  50. })
  51. def commits(self, project_id):
  52. """
  53. fetch project list or one item
  54. /tag/
  55. :return:
  56. """
  57. branch = request.args.get('branch', '')
  58. wi = Deployer(project_id=project_id)
  59. commits = wi.list_commit(branch)
  60. return self.render_json(data={
  61. 'branches': commits,
  62. })