From 3eed8a4ef7b9002888b160055fd2b9350aecaf22 Mon Sep 17 00:00:00 2001 From: icechen Date: Thu, 6 Jan 2022 17:54:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E4=BB=8E=20params=20?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=9E=84=E5=BB=BA=E5=AF=B9=E8=B1=A1=E7=9A=84?= =?UTF-8?q?=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config_handler/config_handler.go | 34 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/config_handler/config_handler.go b/config_handler/config_handler.go index 679c360..a64e94e 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, req.Build.Message) + modifiedApiList := getModifiedApi(cfg.Api, modifiedFileList, foundAppByMessage(req.Build.Message), foundAppByParams(req.Build.Params)) 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, req.Build.Message) + modifiedServiceList := getModifiedService(cfg.Service, modifiedFileList, foundAppByMessage(req.Build.Message), foundAppByParams(req.Build.Params)) destinationService, err := modifiedServiceList.toDestinationConfig(cfg.Name, getDeployEnv(req), cfg.toServiceEnv()) if err != nil { logrus.Error(err) @@ -111,7 +111,7 @@ func getDeployEnv(req *config.Request) consts.Env { return consts.EnvNone } -func getModifiedApi(api ApiList, modifiedFileList []string, message string) ApiList { +func getModifiedApi(api ApiList, modifiedFileList []string, appByMessage []string, appByParams []string) ApiList { ret := make(ApiList, 0) tempIndex := NewSet() for i, a := range api { @@ -125,16 +125,15 @@ func getModifiedApi(api ApiList, modifiedFileList []string, message string) ApiL for _, i := range tempIndex.ToSlice() { ret = append(ret, api[i]) } - ret = append(ret, getDeployApiByCommitMessage(api, message)...) + ret = append(ret, getDeployApiByAppSlice(api, append(appByMessage, appByParams...))...) return ret } -func getDeployApiByCommitMessage(api ApiList, message string) ApiList { +func getDeployApiByAppSlice(api ApiList, appSlice []string) ApiList { ret := make(ApiList, 0) - foundApp := foundAppByMessage(message) - for _, app := range foundApp { + for _, app := range appSlice { for _, a := range api { - if "api-"+a.Name == app { + if "api-"+a.Name == strings.TrimSpace(app) { ret = append(ret, a) } } @@ -142,7 +141,7 @@ func getDeployApiByCommitMessage(api ApiList, message string) ApiList { return ret } -func getModifiedService(service ServiceList, modifiedFileList []string, message string) ServiceList { +func getModifiedService(service ServiceList, modifiedFileList []string, appByMessage []string, appByParams []string) ServiceList { ret := make(ServiceList, 0) tempIndex := NewSet() for i, s := range service { @@ -156,16 +155,15 @@ func getModifiedService(service ServiceList, modifiedFileList []string, message for _, i := range tempIndex.ToSlice() { ret = append(ret, service[i]) } - ret = append(ret, getDeployServiceByCommitMessage(service, message)...) + ret = append(ret, getDeployServiceByAppSlice(service, append(appByMessage, appByParams...))...) return ret } -func getDeployServiceByCommitMessage(service ServiceList, message string) ServiceList { +func getDeployServiceByAppSlice(service ServiceList, appSlice []string) ServiceList { ret := make(ServiceList, 0) - foundApp := foundAppByMessage(message) - for _, app := range foundApp { + for _, app := range appSlice { for _, s := range service { - if "service-"+s.Name == app { + if "service-"+s.Name == strings.TrimSpace(app) { ret = append(ret, s) } } @@ -183,3 +181,11 @@ func foundAppByMessage(message string) []string { } return []string{} } + +func foundAppByParams(params map[string]string) []string { + app, has := params["app"] + if has { + return strings.Split(app, ",") + } + return []string{} +}