dingding.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. """
  3. walle-web
  4. :copyright: © 2015-2019 walle-web.io
  5. :created time: 2018-12-23 20:17:14
  6. :author: wushuiyong@walle-web.io
  7. """
  8. import json
  9. import requests
  10. from . import Notice
  11. class Dingding(Notice):
  12. def deploy_task(self, project_info, notice_info):
  13. '''
  14. 上线单新建, 上线完成, 上线失败
  15. @param hook:
  16. @param notice_info:
  17. 'title',
  18. 'username',
  19. 'project_name',
  20. 'task_name',
  21. 'branch',
  22. 'commit',
  23. 'is_branch',
  24. @return:
  25. '''
  26. data = {
  27. "msgtype": "markdown",
  28. "markdown": {
  29. "title": "上线单通知",
  30. "text": """#### ![screenshot](http://walle-web.io/dingding.jpg) %s %s  \n> **项目**:%s \n
  31. > **任务**:%s \n
  32. > **分支**:%s \n
  33. > **版本**:%s \n """ % (
  34. notice_info['username'], notice_info['title'], notice_info['project_name'], notice_info['task_name'],
  35. notice_info['branch'], notice_info['commit'])
  36. }
  37. }
  38. headers = {'Content-Type': 'application/json;charset=UTF-8'}
  39. response = requests.post(project_info['notice_hook'], data=json.dumps(data).encode('utf-8'), headers=headers)
  40. return response.json()['errcode'] == 0