首页 > 其他 > 详细

gitlab email notify related

时间:2020-01-02 13:53:24      阅读:85      评论:0      收藏:0      [点我收藏+]
技术分享图片
emailnotify:
    stage: notify
    before_script:
        - echo "start emailnotify"
    after_script:
        - echo "finish emailnotify"
    script:
        - bash scripts/notify.sh
    only:
        - merge_requests
    only:
        - develop
    except:
        - schedules
.gitlab-ci.yml
技术分享图片
#!/usr/bin/env bash

###############################################################################
# Copyright 2018 The MoonX Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################

# set -e

merge_id=`git log -1 |tail -1 |awk -F "!" {print $2}`
merge_url="https://gitlab.moonx.cn/Developers/apollo/merge_requests/"$merge_id"/diffs"

declare -A modinfo

function readcfg() {
  IFS==
  cat "./scripts/module_info.cfg" | grep -Ev "^$|^#" > module_info.cfg.tmp
  while read mod mail
  do
    modinfo[$mod]=$mail
  done < module_info.cfg.tmp
  rm module_info.cfg.tmp
  IFS= 
  # for key in $(echo ${!modinfo[*]})
  # do
  #   echo "$key : ${modinfo[$key]}"
  # done
}

# sendmail module
function sendmail() {
  mod=$1
  email=${modinfo[${mod}email]}
  contentregex=${modinfo[${mod}contentregex]}
  file=$(git diff HEAD^ HEAD --name-only |grep -E "$contentregex")
  if [ -z $file ]; then
    echo "not revise modules/$mod"
    return 0
  fi
  patch=$(git diff HEAD^ HEAD `echo $file |tr \n  `)
  content=$merge_url"

"$patch
  echo "python sendmail.py $mod $email content." # $contentregex  #$content
  python scripts/sendmail.py $mod $email "$content"
}

readcfg
for value in $(echo ${modinfo[allmodule]})
do
  sendmail $value
done

exit 0
notify.sh
技术分享图片
#coding:utf-8
#server.login(my_sender,"ydydmvthorlqbgbg") my_sender=490195356@qq.com
#coding=utf-8
# Usage:
#   python sendmailtoa.py mod email content

import sys
import smtplib
from email.mime.text import MIMEText

mod=sys.argv[1]
email=sys.argv[2]
content=sys.argv[3]

msg_from=490195356@qq.com
passwd=ydydmvthorlqbgbg
msg_to="490195356@qq.com,%s" % email
subject="no reply<Moonx/apollo/modules/%s>" % mod

msg = MIMEText(content)
msg[Subject] = subject
msg[From] = msg_from
msg[To] = msg_to
try:
    s = smtplib.SMTP_SSL("smtp.qq.com",465)
    s.login(msg_from, passwd)
    s.sendmail(msg_from, msg_to.split(,), msg.as_string())
    print "Send success"
except s.SMTPException,e:
    print "Send fail"
finally:
    s.quit()
sendmail.py
技术分享图片
#
allmodule=infra driver map localization perception
#
infraemail=peng.yang@moonx.ai
infracontentregex=docker/|cyber/|scripts/
#
driveremail=peng.yang@moonx.ai
drivercontentregex=modules/drivers/
#
mapemail=490195356@qq.com
mapcontentregex=modules/map/
#
localizationemail=peng.yang@moonx.ai
localizationcontentregex=modules/localization/
#
perceptionemail=peng.yang@moonx.ai
perceptioncontentregex=modules/perception/|modules/prediction/
module_info.cfg

 

gitlab email notify related

原文:https://www.cnblogs.com/cjyp/p/12131707.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!