Skip to content

Commit

Permalink
improve msg title
Browse files Browse the repository at this point in the history
  • Loading branch information
seoktaehyeon committed Jun 25, 2021
1 parent 35133b1 commit 8d2c434
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions app/services/svcParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def parse_user(self, key_smart_path: str):

def parse_jira_webhook(self):
self.webhook_event = self.webhook_body['webhookEvent'].replace('jira:', '').replace('_', '').capitalize()
self.webhook_title = 'Attention! Jira @you'
self.webhook_title = 'Jira @you'
self.webhook_content = self.webhook_body
self.parse_user('comment.author.name')
self.parse_user('comment.updateAuthor.name')
Expand All @@ -75,20 +75,21 @@ def parse_jira_a4j_webhook(self):
self.webhook_event = 'Create'
else:
self.webhook_event = 'Update'
self.webhook_title = 'Attention! Jira @you'
self.webhook_title = 'Jira @you'
self.webhook_content = self.webhook_body
self.parse_user('fields.creator.name')
self.parse_user('fields.reporter.name')
self.parse_user('fields.assignee.name')
return True

def parse_gitlab_webhook(self):
self.webhook_title = 'GitLab @you'
self.webhook_content = self.webhook_body
return True

def parse_harbor_webhook(self):
self.webhook_event = self.webhook_body['type'].replace('_', ' ').capitalize()
self.webhook_title = 'GREAT! Harbor @you'
self.webhook_title = 'Harbor @you'
self.webhook_content = self.webhook_body
return True

Expand Down
9 changes: 6 additions & 3 deletions app/services/svcRobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def msg_content(headers, tmpl, body):
"""
_body = parse_webhook(headers, body)
_sender = _body.get('sender')
_users = _body.get('users')
_event = _body.get('event')
_title = _body.get('title')
_data = _body.get('content')
Expand All @@ -82,7 +83,7 @@ def msg_content(headers, tmpl, body):
raise KeyError(e.message)
# 结束

# 开始 # 检查内容中是否包含 @用户 信息: 格式有可能为 @user 或者 [~user]
# 开始 # 进一步检查消息内容中是否包含 @用户 信息: 格式有可能为 @user 或者 [~user]
# 若包含,则检查是否能转换为自定义(如企业微信、飞书、钉钉使用)的 ID
# 若能转换,则替换原 @用户 字符串,并记录下来
_at_users = list()
Expand All @@ -95,19 +96,21 @@ def msg_content(headers, tmpl, body):
if '@%s' % _user in _content_raw:
logging.info('Replace: %s --> %s' % (_user, _im_user))
_content_raw = _content_raw.replace('@%s' % _user, '@%s' % _im_user)
_at_users.append(_im_user)
_at_users.append(_user)
# jira comment 中 at 用户的格式为 [~userid]
if '[~%s]' % _user in _content_raw:
logging.info('Replace %s --> %s' % (_user, _im_user))
_content_raw = _content_raw.replace('[~%s]' % _user, '@%s' % _im_user)
_at_users.append(_im_user)
_at_users.append(_user)
# 飞书消息中 @用户 比较特殊,是 user_id: 用户 的格式
if 'user_id: "%s"' % _user in _content_raw:
logging.info('Replace %s --> %s' % (_user, _im_user))
_content_raw = _content_raw.replace('user_id: "%s"' % _user, 'user_id: "%s"' % _im_user)
_at_users.append(_user)
elif 'user_id: \'%s\'' % _user in _content_raw:
logging.info('Replace %s --> %s' % (_user, _im_user))
_content_raw = _content_raw.replace('user_id: \'%s\'' % _user, 'user_id: "%s"' % _im_user)
_at_users.append(_user)
# 结束

# 开始 # 若有需要 @用户 就替换标题中的 @you
Expand Down

0 comments on commit 8d2c434

Please sign in to comment.