Initial commit

This commit is contained in:
Donny
2019-04-22 20:46:32 +08:00
commit 49ab8aadd1
25441 changed files with 4055000 additions and 0 deletions

21
app/tool/ci/BUILD Normal file
View File

@@ -0,0 +1,21 @@
package(default_visibility = ["//visibility:public"])
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/tool/ci/cmd/mail:all-srcs",
"//app/tool/ci/lib/changes:all-srcs",
"//app/tool/ci/lib/commit:all-srcs",
"//app/tool/ci/lib/lint:all-srcs",
"//app/tool/ci/lib/mail:all-srcs",
],
tags = ["automanaged"],
)

12
app/tool/ci/CHANGELOG.md Normal file
View File

@@ -0,0 +1,12 @@
# tools.rider
# v1.0.1
1. add send mail
2. update log print
# v1.0.1
1. fix rider/changes log dir
2. update vendor
# v1.0.0
1. 初始化项目

View File

@@ -0,0 +1,10 @@
# Owner
fangrongchang
# Author
fangrongchang
zhanglin
# Reviewer
fangrongchang
zhanglin

12
app/tool/ci/OWNERS Normal file
View File

@@ -0,0 +1,12 @@
# See the OWNERS docs at https://go.k8s.io/owners
approvers:
- fangrongchang
- zhanglin
labels:
- tool
options:
no_parent_owners: true
reviewers:
- fangrongchang
- zhanglin

View File

@@ -0,0 +1,41 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_binary",
)
go_library(
name = "go_default_library",
srcs = ["main.go"],
importmap = "go-common/app/tool/rider/sendEmail/cmd",
importpath = "go-common/app/tool/ci/cmd/mail",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/tool/ci/lib/mail:go_default_library",
"//library/log:go_default_library",
"//vendor/github.com/BurntSushi/toml:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
go_binary(
name = "mail",
embed = [":go_default_library"],
tags = ["automanaged"],
)

View File

@@ -0,0 +1,92 @@
package main
import (
"flag"
"os"
"strings"
"go-common/app/tool/ci/lib/mail"
"go-common/library/log"
"github.com/BurntSushi/toml"
)
type sendInfo struct {
SenderName string
SendTitle string
SendContent string
ExtraData string
}
type receiverInfo struct {
ReceiverName []string
}
type config struct {
Title string
SendInfo sendInfo
ReceiverInfo receiverInfo
}
func mailToml(cPath string) (conf config, err error) {
if _, err = toml.DecodeFile(cPath, &conf); err != nil {
log.Error("Error(%v)", err)
}
return
}
func main() {
var (
filePath string
ciSendTo string
pipeStatus string
eConf config
sendTo []string
sendContent string
extraData string
err error
ciProjectURL = os.Getenv("CI_PROJECT_URL")
ciPipelineId = os.Getenv("CI_PIPELINE_ID")
ciUserEmail = os.Getenv("GITLAB_USER_EMAIL")
sourceBranch = os.Getenv("CI_COMMIT_REF_NAME")
)
//log init
logConfig := &log.Config{
Stdout: true,
}
log.Init(logConfig)
//pipeline url
if ciProjectURL == "" {
log.Warn("Error: Not CI_PROJECT_URL")
}
pipelineURL := ciProjectURL + "/pipelines/" + ciPipelineId
log.Info("url: %v", pipelineURL)
//send email data from config files
flag.StringVar(&filePath, "configPath", "", "config path, eg: /data/gitlab/email.toml")
flag.StringVar(&ciSendTo, "sendTo", "", "send to email, eg: jiangkai@bilibili.com,tangyongqiang@bilibili.com")
flag.StringVar(&pipeStatus, "pipeStatus", "failed", "pipeStatus, only failed or success")
flag.StringVar(&extraData, "extraData", "", "email contents")
flag.Parse()
if ciSendTo != "" {
matchList := strings.Split(ciSendTo, ",")
sendTo = matchList
} else {
if filePath != "" {
if eConf, err = mailToml(filePath); err != nil {
log.Warn("Warn(%v)", err)
}
sendTo = eConf.ReceiverInfo.ReceiverName
sendContent = eConf.SendInfo.SendContent
extraData = eConf.SendInfo.ExtraData
} else {
sendTo = []string{ciUserEmail}
}
}
// delete saga send mail
if strings.Contains(ciUserEmail, "zzjs") {
log.Info("Saga exc pipeline")
} else {
sendmail.SendMail(sendTo, pipelineURL, sendContent, sourceBranch, extraData, pipeStatus)
}
}

View File

@@ -0,0 +1,21 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,21 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,21 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,43 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = ["sendmail.go"],
importpath = "go-common/app/tool/ci/lib/mail",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/tool/saga/model:go_default_library",
"//app/tool/saga/service/mail:go_default_library",
"//library/log:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = ["sendmail_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = ["//vendor/github.com/smartystreets/goconvey/convey:go_default_library"],
)

View File

@@ -0,0 +1,46 @@
package sendmail
import (
"go-common/app/tool/saga/model"
"go-common/app/tool/saga/service/mail"
"go-common/library/log"
)
/*
mail model:
【Saga 提醒】+mailTitle
Saga 事件通知
执行状态 : 成功
Pipeline信息: http://gitlab.bilibili.co/platform/go-common/pipelines/1551
来源分支 : ci-commit/test
修改说明 :
额外信息: 你真是棒棒的,合并成功了
*/
func SendMail(sendTo []string, url string, data string, sourceBranch string, extraData string, pipeStatus string) {
var (
mAddress model.Mail
mDada model.MailData
)
for _, to := range sendTo {
singleMail := &model.MailAddress{Address: to}
mAddress.ToAddress = append(mAddress.ToAddress, singleMail)
}
if pipeStatus == "failed" {
mAddress.Subject = "【Saga 提醒】Pipeline 执行失败 "
mDada.PipeStatus = "失败"
} else if pipeStatus == "success" {
mAddress.Subject = "【Saga 提醒】Pipeline 执行成功 "
mDada.PipeStatus = "成功"
} else {
mAddress.Subject = "【Saga 提醒】 " + pipeStatus
}
mDada.Info = extraData
mDada.Description = data
mDada.SourceBranch = sourceBranch
mDada.URL = url
mDada.PipelineStatus = pipeStatus
if err := mail.SendMail3("saga@bilibili.com", "SAGA", "Lexgm8AAQrF7CcNA", &mAddress, &mDada); err != nil {
log.Error("Error(%v)", err)
}
}

View File

@@ -0,0 +1,12 @@
package sendmail
import (
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestSendMail(t *testing.T) {
Convey("TODO", t, func() {
})
}