fix: 增加从 params 获取构建对象的能力
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		
							parent
							
								
									ae46c5d396
								
							
						
					
					
						commit
						3eed8a4ef7
					
				| @ -61,7 +61,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, | |||||||
| 
 | 
 | ||||||
| 	// 4. 根据文件树以及原始配置文件的信息,组装需要构建的服务的ci信息 | 	// 4. 根据文件树以及原始配置文件的信息,组装需要构建的服务的ci信息 | ||||||
| 	// 4.1 api | 	// 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()) | 	destinationApi, err := modifiedApiList.toDestinationConfig(cfg.Name, getDeployEnv(req), cfg.toServiceEnv()) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logrus.Error(err) | 		logrus.Error(err) | ||||||
| @ -69,7 +69,7 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config, | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// 4.2 service | 	// 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()) | 	destinationService, err := modifiedServiceList.toDestinationConfig(cfg.Name, getDeployEnv(req), cfg.toServiceEnv()) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logrus.Error(err) | 		logrus.Error(err) | ||||||
| @ -111,7 +111,7 @@ func getDeployEnv(req *config.Request) consts.Env { | |||||||
| 	return consts.EnvNone | 	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) | 	ret := make(ApiList, 0) | ||||||
| 	tempIndex := NewSet() | 	tempIndex := NewSet() | ||||||
| 	for i, a := range api { | 	for i, a := range api { | ||||||
| @ -125,16 +125,15 @@ func getModifiedApi(api ApiList, modifiedFileList []string, message string) ApiL | |||||||
| 	for _, i := range tempIndex.ToSlice() { | 	for _, i := range tempIndex.ToSlice() { | ||||||
| 		ret = append(ret, api[i]) | 		ret = append(ret, api[i]) | ||||||
| 	} | 	} | ||||||
| 	ret = append(ret, getDeployApiByCommitMessage(api, message)...) | 	ret = append(ret, getDeployApiByAppSlice(api, append(appByMessage, appByParams...))...) | ||||||
| 	return ret | 	return ret | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getDeployApiByCommitMessage(api ApiList, message string) ApiList { | func getDeployApiByAppSlice(api ApiList, appSlice []string) ApiList { | ||||||
| 	ret := make(ApiList, 0) | 	ret := make(ApiList, 0) | ||||||
| 	foundApp := foundAppByMessage(message) | 	for _, app := range appSlice { | ||||||
| 	for _, app := range foundApp { |  | ||||||
| 		for _, a := range api { | 		for _, a := range api { | ||||||
| 			if "api-"+a.Name == app { | 			if "api-"+a.Name == strings.TrimSpace(app) { | ||||||
| 				ret = append(ret, a) | 				ret = append(ret, a) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @ -142,7 +141,7 @@ func getDeployApiByCommitMessage(api ApiList, message string) ApiList { | |||||||
| 	return ret | 	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) | 	ret := make(ServiceList, 0) | ||||||
| 	tempIndex := NewSet() | 	tempIndex := NewSet() | ||||||
| 	for i, s := range service { | 	for i, s := range service { | ||||||
| @ -156,16 +155,15 @@ func getModifiedService(service ServiceList, modifiedFileList []string, message | |||||||
| 	for _, i := range tempIndex.ToSlice() { | 	for _, i := range tempIndex.ToSlice() { | ||||||
| 		ret = append(ret, service[i]) | 		ret = append(ret, service[i]) | ||||||
| 	} | 	} | ||||||
| 	ret = append(ret, getDeployServiceByCommitMessage(service, message)...) | 	ret = append(ret, getDeployServiceByAppSlice(service, append(appByMessage, appByParams...))...) | ||||||
| 	return ret | 	return ret | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getDeployServiceByCommitMessage(service ServiceList, message string) ServiceList { | func getDeployServiceByAppSlice(service ServiceList, appSlice []string) ServiceList { | ||||||
| 	ret := make(ServiceList, 0) | 	ret := make(ServiceList, 0) | ||||||
| 	foundApp := foundAppByMessage(message) | 	for _, app := range appSlice { | ||||||
| 	for _, app := range foundApp { |  | ||||||
| 		for _, s := range service { | 		for _, s := range service { | ||||||
| 			if "service-"+s.Name == app { | 			if "service-"+s.Name == strings.TrimSpace(app) { | ||||||
| 				ret = append(ret, s) | 				ret = append(ret, s) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @ -183,3 +181,11 @@ func foundAppByMessage(message string) []string { | |||||||
| 	} | 	} | ||||||
| 	return []string{} | 	return []string{} | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func foundAppByParams(params map[string]string) []string { | ||||||
|  | 	app, has := params["app"] | ||||||
|  | 	if has { | ||||||
|  | 		return strings.Split(app, ",") | ||||||
|  | 	} | ||||||
|  | 	return []string{} | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user