From 3e0ef078c9773ec83944c1753db1bb4afd64d0e7 Mon Sep 17 00:00:00 2001 From: icechen Date: Tue, 4 Jan 2022 20:32:45 +0800 Subject: [PATCH] feat: add [app] deploy --- README.md | 2 ++ config_handler/config_handler.go | 47 +++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f74cd56..b16d335 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # drone_plugin +## TODO +- new build with deploy app \ No newline at end of file diff --git a/config_handler/config_handler.go b/config_handler/config_handler.go index 98ac3ce..7fd120d 100644 --- a/config_handler/config_handler.go +++ b/config_handler/config_handler.go @@ -61,7 +61,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, // 4. 根据文件树以及原始配置文件的信息,组装需要构建的服务的ci信息 // 4.1 api - modifiedApiList := getModifiedApi(cfg.Api, modifiedFileList) + modifiedApiList := getModifiedApi(cfg.Api, modifiedFileList, req.Build.Message) destinationApi, err := modifiedApiList.toDestinationConfig(cfg.Name, getDeployEnv(req), cfg.toServiceEnv()) if err != nil { logrus.Error(err) @@ -69,7 +69,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, } // 4.2 service - modifiedServiceList := getModifiedService(cfg.Service, modifiedFileList) + modifiedServiceList := getModifiedService(cfg.Service, modifiedFileList, req.Build.Message) destinationService, err := modifiedServiceList.toDestinationConfig(cfg.Name, getDeployEnv(req), cfg.toServiceEnv()) if err != nil { logrus.Error(err) @@ -109,7 +109,7 @@ func getDeployEnv(req *config.Request) consts.Env { return consts.EnvNone } -func getModifiedApi(api ApiList, modifiedFileList []string) ApiList { +func getModifiedApi(api ApiList, modifiedFileList []string, message string) ApiList { ret := make(ApiList, 0) tempIndex := NewSet() for i, a := range api { @@ -123,10 +123,24 @@ func getModifiedApi(api ApiList, modifiedFileList []string) ApiList { for _, i := range tempIndex.ToSlice() { ret = append(ret, api[i]) } + ret = append(ret, getDeployApiByCommitMessage(api, message)...) return ret } -func getModifiedService(service ServiceList, modifiedFileList []string) ServiceList { +func getDeployApiByCommitMessage(api ApiList, message string) ApiList { + ret := make(ApiList, 0) + foundApp := foundAppByMessage(message) + for _, app := range foundApp { + for _, a := range api { + if a.Name == app { + ret = append(ret, a) + } + } + } + return ret +} + +func getModifiedService(service ServiceList, modifiedFileList []string, message string) ServiceList { ret := make(ServiceList, 0) tempIndex := NewSet() for i, s := range service { @@ -140,5 +154,30 @@ func getModifiedService(service ServiceList, modifiedFileList []string) ServiceL for _, i := range tempIndex.ToSlice() { ret = append(ret, service[i]) } + ret = append(ret, getDeployServiceByCommitMessage(service, message)...) return ret } + +func getDeployServiceByCommitMessage(service ServiceList, message string) ServiceList { + ret := make(ServiceList, 0) + foundApp := foundAppByMessage(message) + for _, app := range foundApp { + for _, s := range service { + if s.Name == app { + ret = append(ret, s) + } + } + } + return ret +} + +func foundAppByMessage(message string) []string { + i := strings.Index(message, "[") + if i >= 0 { + j := strings.Index(message[i:], "]") + if j >= 0 { + return append([]string{message[i+1 : j+i]}, foundAppByMessage(message[j+i:])...) + } + } + return []string{} +}