#19 #20
@ -33,6 +33,7 @@ type Gitea struct {
|
|||||||
PRBody string
|
PRBody string
|
||||||
Repository string
|
Repository string
|
||||||
Owner string
|
Owner string
|
||||||
|
pulls []*giteaPull
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGitea(cfg configcli.Config) *Gitea {
|
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))
|
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 {
|
if err != nil && err != ErrPRNotExist {
|
||||||
logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err))
|
logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err))
|
||||||
return 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))
|
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) {
|
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))
|
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 {
|
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))
|
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 {
|
||||||
if err != nil {
|
g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Token)
|
||||||
logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err))
|
if err != nil {
|
||||||
return err
|
logger.Error(ctx, fmt.Sprintf("GetPulls error: %s", err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prExist := false
|
prExist := false
|
||||||
for _, pull := range pulls {
|
for _, pull := range g.pulls {
|
||||||
if strings.Contains(pull.Title, path) && pull.Base.Ref == branch {
|
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
|
logger.Info(ctx, fmt.Sprintf("don't skip %s since pr exist %s", path, pull.URL)) //todo
|
||||||
tVersion := getVersions(pull.Head.Ref) //Надо взять просто из названия ветки последнюю версию
|
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))
|
logger.Info(ctx, fmt.Sprintf("Old pr %s successful delete", pull.Head.Ref))
|
||||||
} else {
|
} else {
|
||||||
|
logger.Debugf(ctx, "The existing PR is relevant")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
prExist = true
|
prExist = true
|
||||||
@ -427,10 +432,6 @@ func GetPulls(ctx context.Context, url, owner, repo, token string) ([]*giteaPull
|
|||||||
|
|
||||||
buf, _ := io.ReadAll(rsp.Body)
|
buf, _ := io.ReadAll(rsp.Body)
|
||||||
|
|
||||||
if len(buf) == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
switch rsp.StatusCode {
|
switch rsp.StatusCode {
|
||||||
case http.StatusOK:
|
case http.StatusOK:
|
||||||
if err = json.Unmarshal(buf, &pulls); err != nil {
|
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)
|
return nil, fmt.Errorf("unknown error: %s", buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(len(pullsAll))
|
if len(pulls) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pullsAll, nil
|
return pullsAll, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user