#8 add cli, need fix parse yaml.

This commit is contained in:
Gorbunov Kirill Andreevich
2024-03-23 18:52:13 +03:00
parent 367426a1f9
commit 90fcbf6a21
18 changed files with 615 additions and 105 deletions

View File

@@ -26,7 +26,6 @@ import (
)
var (
ErrPRExist = errors.New("pull request exists")
ErrPRNotExist = errors.New("pull request does not exist")
)
@@ -145,10 +144,10 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
}
for _, pull := range pulls {
logger.Info(ctx, fmt.Sprintf("PULL title - %s | ref - %s", pull.Title, pull.Base.Ref))
logger.Debugf(ctx, fmt.Sprintf("PULL title - %s | ref - %s", pull.Title, pull.Base.Ref))
if strings.Contains(pull.Title, path) && strings.Contains(pull.Base.Ref, branch) {
logger.Info(ctx, fmt.Sprintf("skip %s as pr already exists %s", path, pull.URL))
return ErrPRExist
logger.Info(ctx, fmt.Sprintf("PR for %s exists %s, call RequestUpdate", path, pull.URL))
return g.RequestUpdate(ctx, branch, path, mod)
} // хотим проверить есть ли пулл реквест для этой ветки, если есть то выходим
}
@@ -362,6 +361,25 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m
return g.RequestOpen(ctx, branch, path, mod)
}
func (g *Gitea) RequestList(ctx context.Context, branch string) (map[string]string, error) {
logger.Debugf(ctx, fmt.Sprintf("RequestList for %s", branch))
gPulls, err := GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token)
if err != nil {
return nil, err
}
var path string
rMap := make(map[string]string)
for _, pull := range gPulls {
path = strings.Split(pull.Title, " ")[1] //todo Работет только для дефолтного шаблона
rMap[path] = pull.Title
}
return rMap, nil
}
func getVersions(s string) string {
re := regexp.MustCompile("[vV][0-9]+\\.[0-9]+\\.[0-9]+")

View File

@@ -26,3 +26,6 @@ func (g *Github) RequestClose(ctx context.Context, branch string, path string) e
func (g *Github) RequestUpdate(ctx context.Context, branch string, path string, mod modules.Update) error {
return nil
}
func (g *Github) RequestList(ctx context.Context, branch string) (map[string]string, error) {
return nil, nil
}

View File

@@ -26,3 +26,6 @@ func (g *Gitlab) RequestClose(ctx context.Context, branch string, path string) e
func (g *Gitlab) RequestUpdate(ctx context.Context, branch string, path string, mod modules.Update) error {
return nil
}
func (g *Gitlab) RequestList(ctx context.Context, branch string) (map[string]string, error) {
return nil, nil
}

View File

@@ -26,3 +26,6 @@ func (g *Gogs) RequestClose(ctx context.Context, branch string, path string) err
func (g *Gogs) RequestUpdate(ctx context.Context, branch string, path string, mod modules.Update) error {
return nil
}
func (g *Gogs) RequestList(ctx context.Context, branch string) (map[string]string, error) {
return nil, nil
}

View File

@@ -15,6 +15,7 @@ type SourceControl interface {
RequestOpen(ctx context.Context, branch string, path string, mod modules.Update) error
RequestClose(ctx context.Context, branch string, path string) error
RequestUpdate(ctx context.Context, branch string, path string, mod modules.Update) error
RequestList(ctx context.Context, branch string) (map[string]string, error)
}
func NewSourceControl(cfg configcli.Config) SourceControl {