This commit is contained in:
		
							parent
							
								
									de700cfdef
								
							
						
					
					
						commit
						745daedf91
					
				@ -50,20 +50,33 @@ func (p *plugin) Find(ctx context.Context, req *config.Request) (*drone.Config,
 | 
			
		||||
	// 4. 根据文件树以及原始配置文件的信息,组装需要构建的服务的ci信息
 | 
			
		||||
	// 4.1 api
 | 
			
		||||
	modifiedApiList := getModifiedApi(cfg.Api, modifiedFileList)
 | 
			
		||||
	destinationApi, err := modifiedApiList.toDestinationConfig()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logrus.Error(err)
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_ = modifiedApiList
 | 
			
		||||
	// 4.2 service
 | 
			
		||||
	modifiedServiceList := getModifiedService(cfg.Service, modifiedFileList)
 | 
			
		||||
	destinationService, err := modifiedServiceList.toDestinationConfig()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logrus.Error(err)
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 5. 组装所有ci信息并输出
 | 
			
		||||
	return nil, nil
 | 
			
		||||
	return &drone.Config{
 | 
			
		||||
		Data: destinationApi + "\n\n" + destinationService,
 | 
			
		||||
		Kind: "pipeline",
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getGitClient(req *config.Request) git.Client {
 | 
			
		||||
	return git.New(req.Repo.Namespace, req.Repo.Name, req.Build.After, req.Repo.Config)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getModifiedApi(api []Api, modifiedFileList []string) []Api {
 | 
			
		||||
	ret := make([]Api, 0)
 | 
			
		||||
func getModifiedApi(api ApiList, modifiedFileList []string) ApiList {
 | 
			
		||||
	ret := make(ApiList, 0)
 | 
			
		||||
	tempIndex := NewSet()
 | 
			
		||||
	for i, a := range api {
 | 
			
		||||
		for _, file := range modifiedFileList {
 | 
			
		||||
@ -78,3 +91,20 @@ func getModifiedApi(api []Api, modifiedFileList []string) []Api {
 | 
			
		||||
	}
 | 
			
		||||
	return ret
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getModifiedService(service ServiceList, modifiedFileList []string) ServiceList {
 | 
			
		||||
	ret := make(ServiceList, 0)
 | 
			
		||||
	tempIndex := NewSet()
 | 
			
		||||
	for i, s := range service {
 | 
			
		||||
		for _, file := range modifiedFileList {
 | 
			
		||||
			if strings.HasSuffix(file, s.Root) {
 | 
			
		||||
				tempIndex.Add(i)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, i := range tempIndex.ToSlice() {
 | 
			
		||||
		ret = append(ret, service[i])
 | 
			
		||||
	}
 | 
			
		||||
	return ret
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -2,26 +2,58 @@ package config_handler
 | 
			
		||||
 | 
			
		||||
import "git.icechen.cn/pkg/drone_plugin/go_handler"
 | 
			
		||||
 | 
			
		||||
type ApiHandler interface {
 | 
			
		||||
type Handler interface {
 | 
			
		||||
	ToDestinationConfig() (string, error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (al ApiList) toDestinationConfig() (string, error) {
 | 
			
		||||
	return "", nil
 | 
			
		||||
	retConfig := ""
 | 
			
		||||
	for _, api := range al {
 | 
			
		||||
		config, err := api.toDestinationConfig()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "", err
 | 
			
		||||
		}
 | 
			
		||||
		retConfig += config + "\n\n---\n\n"
 | 
			
		||||
	}
 | 
			
		||||
	return retConfig, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a Api) toDestinationConfig() (string, error) {
 | 
			
		||||
	var handler ApiHandler
 | 
			
		||||
	var handler Handler
 | 
			
		||||
	switch a.Type {
 | 
			
		||||
	case go_handler.TypeGolang:
 | 
			
		||||
		handler = go_handler.GoApiHandler{}
 | 
			
		||||
		handler = go_handler.GoApiHandler{
 | 
			
		||||
			Name: a.Name,
 | 
			
		||||
			Root: a.Root,
 | 
			
		||||
			Port: a.Port,
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return handler.ToDestinationConfig()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (sl ServiceList) toDestinationConfig() {
 | 
			
		||||
func (sl ServiceList) toDestinationConfig() (string, error) {
 | 
			
		||||
	retConfig := ""
 | 
			
		||||
	for _, service := range sl {
 | 
			
		||||
		config, err := service.toDestinationConfig()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "", err
 | 
			
		||||
		}
 | 
			
		||||
		retConfig += config + "\n\n---\n\n"
 | 
			
		||||
	}
 | 
			
		||||
	return retConfig, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (s Service) toDestinationConfig() {
 | 
			
		||||
func (s Service) toDestinationConfig() (string, error) {
 | 
			
		||||
	var handler Handler
 | 
			
		||||
	switch s.Type {
 | 
			
		||||
	case go_handler.TypeGolang:
 | 
			
		||||
		handler = go_handler.GoApiHandler{
 | 
			
		||||
			Name: s.Name,
 | 
			
		||||
			Root: s.Root,
 | 
			
		||||
			Port: s.Port,
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return handler.ToDestinationConfig()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -21,6 +21,7 @@ type (
 | 
			
		||||
		Name string `json:"name" yaml:"name"`
 | 
			
		||||
		Root string `json:"root" yaml:"root"`
 | 
			
		||||
		Type string `json:"type" yaml:"type"`
 | 
			
		||||
		Port string `json:"port" yaml:"port"`
 | 
			
		||||
	}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@ -30,6 +31,7 @@ type (
 | 
			
		||||
		Name string `json:"name" yaml:"name"`
 | 
			
		||||
		Root string `json:"root" yaml:"root"`
 | 
			
		||||
		Type string `json:"type" yaml:"type"`
 | 
			
		||||
		Port string `json:"port" yaml:"port"`
 | 
			
		||||
	}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -13,7 +13,11 @@ steps:
 | 
			
		||||
  - go test -v
 | 
			
		||||
`
 | 
			
		||||
 | 
			
		||||
type GoApiHandler struct{}
 | 
			
		||||
type GoApiHandler struct {
 | 
			
		||||
	Name string
 | 
			
		||||
	Root string
 | 
			
		||||
	Port string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (GoApiHandler) ToDestinationConfig() (string, error) {
 | 
			
		||||
	return "", nil
 | 
			
		||||
							
								
								
									
										11
									
								
								go_handler/go_service_handler.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								go_handler/go_service_handler.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
package go_handler
 | 
			
		||||
 | 
			
		||||
type GoServiceHandler struct {
 | 
			
		||||
	Name string
 | 
			
		||||
	Root string
 | 
			
		||||
	Port string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (GoServiceHandler) ToDestinationConfig() (string, error) {
 | 
			
		||||
	return "", nil
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user