Просмотр исходного кода

walle 2.1 - 支持多个钉钉hooks,兼容tag在钉钉上显示

walle 6 лет назад
Родитель
Сommit
37d28fc5c1
3 измененных файлов с 27 добавлено и 16 удалено
  1. 2 1
      walle/service/deployer.py
  2. 17 13
      walle/service/notice/dingding.py
  3. 8 2
      walle/service/notice/email.py

+ 2 - 1
walle/service/deployer.py

@@ -453,7 +453,8 @@ class Deployer:
                 'task_name': '%s ([%s](%s))' % (self.taskMdl.get('name'), self.task_id, Notice.task_url(project_name=self.project_info['name'], task_id=self.task_id)),
                 'branch': self.taskMdl.get('branch'),
                 'commit': self.taskMdl.get('commit_id'),
-                'is_branch': self.project_info['repo_mode'],
+                'tag': self.taskMdl.get('tag'),
+                'repo_mode': self.project_info['repo_mode'],
             }
             notice = Notice.create(self.project_info['notice_type'])
             if success:

+ 17 - 13
walle/service/notice/dingding.py

@@ -10,11 +10,26 @@ import json
 
 import requests
 from . import Notice
+from walle.model.project import ProjectModel
 
 
 class Dingding(Notice):
 
     def deploy_task(self, project_info, notice_info):
+        if notice_info['repo_mode'] == ProjectModel.repo_mode_tag:
+            version = notice_info['tag']
+        else:
+            version = '%s/%s' % (notice_info['branch'], notice_info['commit'])
+        data = {
+            "msgtype": "markdown",
+            "markdown": {
+                "title": "上线单通知",
+                "text": """#### ![screenshot](http://walle-web.io/dingding.jpg) %s %s  \n> **项目**:%s \n
+                > **任务**:%s \n
+                > **版本**:%s \n """ % (
+                notice_info['username'], notice_info['title'], notice_info['project_name'], notice_info['task_name'],
+                version)}
+        }
         '''
         上线单新建, 上线完成, 上线失败
 
@@ -29,19 +44,8 @@ class Dingding(Notice):
             'is_branch',
         @return:
         '''
-        data = {
-            "msgtype": "markdown",
-            "markdown": {
-                "title": "上线单通知",
-                "text": """#### ![screenshot](http://walle-web.io/dingding.jpg) %s %s  \n> **项目**:%s \n
-                > **任务**:%s \n
-                > **分支**:%s \n
-                > **版本**:%s \n """ % (
-                notice_info['username'], notice_info['title'], notice_info['project_name'], notice_info['task_name'],
-                notice_info['branch'], notice_info['commit'])
-            }
-        }
         headers = {'Content-Type': 'application/json;charset=UTF-8'}
-        response = requests.post(project_info['notice_hook'], data=json.dumps(data).encode('utf-8'), headers=headers)
+        for hook in project_info['notice_hook'].split(','):
+            response = requests.post(hook, data=json.dumps(data).encode('utf-8'), headers=headers)
 
         return response.json()['errcode'] == 0

+ 8 - 2
walle/service/notice/email.py

@@ -8,11 +8,18 @@
 """
 from . import Notice
 from walle.service import emails
+from walle.model.project import ProjectModel
 
 
 class Email(Notice):
 
     def deploy_task(self, project_info, notice_info):
+
+        if notice_info['repo_mode'] == ProjectModel.repo_mode_tag:
+            version = notice_info['tag']
+        else:
+            version = '%s/%s' % (notice_info['branch'], notice_info['commit'])
+
         '''
         上线单新建, 上线完成, 上线失败
 
@@ -31,8 +38,7 @@ class Email(Notice):
                 <br><br> <strong>项目</strong>:%s
                 <br><br> <strong>任务</strong>:%s
                 <br><br> <strong>分支</strong>:%s
-                <br><br> <strong>版本</strong>:%s
                 <br><br><br><img src='http://walle-web.io/dingding.jpg'> """ % (
                 notice_info['username'], notice_info['title'], notice_info['project_name'], notice_info['task_name'],
-                notice_info['branch'], notice_info['commit'])
+                version)
         emails.send_email(project_info['notice_hook'], notice_info['title'], message, '')