#19 #20

Closed
kgorbunov wants to merge 112 commits from kgorbunov/pkgdash:#19 into master
Showing only changes of commit 0d4c2e2e85 - Show all commits

View File

@ -33,6 +33,7 @@ type Gitea struct {
PRBody string
Repository string
Owner string
pulls []*giteaPull
}
func NewGitea(cfg configcli.Config) *Gitea {
@ -138,13 +139,13 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
logger.Fatal(ctx, fmt.Sprintf("failed to get worktree: %v", err))
}
pulls, err := GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token)
g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token)
if err != nil && err != ErrPRNotExist {
logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err))
return err
}
logger.Info(ctx, "len: ", len(pulls))
for _, pull := range pulls {
for _, pull := range g.pulls {
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("PR for %s exists %s, call RequestUpdate", path, pull.URL))
@ -322,15 +323,18 @@ func (g *Gitea) RequestClose(ctx context.Context, branch string, path string) er
func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, mod modules.Update) error {
logger.Debugf(ctx, fmt.Sprintf("RequestUpdate start, mod title: %s", path))
var err error
pulls, err := GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token)
if len(g.pulls) == 0 {
g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token)
if err != nil {
logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err))
return err
}
}
prExist := false
for _, pull := range pulls {
for _, pull := range g.pulls {
if strings.Contains(pull.Title, path) && pull.Base.Ref == branch {
logger.Info(ctx, fmt.Sprintf("don't skip %s since pr exist %s", path, pull.URL)) //todo
tVersion := getVersions(pull.Head.Ref) //Надо взять просто из названия ветки последнюю версию
@ -347,6 +351,7 @@ func (g *Gitea) RequestUpdate(ctx context.Context, branch string, path string, m
}
logger.Info(ctx, fmt.Sprintf("Old pr %s successful delete", pull.Head.Ref))
} else {
logger.Debugf(ctx, "The existing PR is relevant")
return nil
}
prExist = true
@ -427,10 +432,6 @@ func GetPulls(ctx context.Context, url, owner, repo, token string) ([]*giteaPull
buf, _ := io.ReadAll(rsp.Body)
if len(buf) == 0 {
break
}
switch rsp.StatusCode {
case http.StatusOK:
if err = json.Unmarshal(buf, &pulls); err != nil {
@ -446,7 +447,9 @@ func GetPulls(ctx context.Context, url, owner, repo, token string) ([]*giteaPull
return nil, fmt.Errorf("unknown error: %s", buf)
}
fmt.Println(len(pullsAll))
if len(pulls) == 0 {
break
}
}
return pullsAll, nil