gitlab email notify related

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

 

posted on 2020-01-02 10:07  csuyangpeng  阅读(191)  评论(0编辑  收藏  举报

导航

//替换成自己路径的js文件