diff --git a/cmd/pkgdashcli/main.go b/cmd/pkgdashcli/main.go index 7590d47..7ee7a1e 100644 --- a/cmd/pkgdashcli/main.go +++ b/cmd/pkgdashcli/main.go @@ -204,6 +204,7 @@ func main() { if err != nil { logger.Fatalf(ctx, "failed to create pr: %v", err) } + logger.Infof(ctx, "PR create for %s - %s", pathMod, mod.Version) } } diff --git a/internal/source/gitea/gitea.go b/internal/source/gitea/gitea.go index ce60f97..0913055 100644 --- a/internal/source/gitea/gitea.go +++ b/internal/source/gitea/gitea.go @@ -99,7 +99,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod if err != nil { break } - if ref.Name().String() == branch { //todo вот тут возможно нужно переделать + if strings.Contains(ref.Name().String(), branch) { //todo вот тут возможно нужно переделать headRef = ref break } @@ -131,20 +131,25 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod } buf, _ = io.ReadAll(rsp.Body) - if rsp.StatusCode != http.StatusOK { + + switch rsp.StatusCode { + case http.StatusOK: + if err = json.Unmarshal(buf, &pulls); err != nil { + logger.Fatalf(ctx, "failed to decode response %s err: %v", buf, err) + } // записываем ответ от гита по пулл реквестам, видимо существующим + // перебираем наши модификации и если они уже есть в гите удаляем их из mods + + for _, pull := range pulls { + if strings.Contains(pull.Title, path) && pull.Base.Ref == branch { + logger.Infof(ctx, "skip %s as pr already exists %s", path, pull.URL) + return ErrPRExist + } // хотим проверить есть ли пулл реквест для этой ветки, если есть то выходим + } + case http.StatusNotFound: + logger.Infof(ctx, "PL is not exist for %s", g.Repository) + default: return fmt.Errorf("unknown error: %s", buf) - } - if err = json.Unmarshal(buf, &pulls); err != nil { - logger.Fatalf(ctx, "failed to decode response %s err: %v", buf, err) - } // записываем ответ от гита по пулл реквестам, видимо существующим - // перебираем наши модификации и если они уже есть в гите удаляем их из mods - - for _, pull := range pulls { - if strings.Contains(pull.Title, path) && pull.Base.Ref == branch { - logger.Infof(ctx, "skip %s as pr already exists %s", path, pull.URL) - return ErrPRExist - } // хотим проверить есть ли пулл реквест для этой ветки, если есть то выходим } logger.Infof(ctx, "update %s from %s to %s", path, mod.Module.Version, mod.Version) @@ -226,7 +231,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod } */ - refspec := gitconfig.RefSpec(fmt.Sprintf("+refs/heads/pkgdash/go_modules/%s-%s:refs/heads/pkgdash/go_modules/%s-%s", path, mod.Version, path, mod.Module.Version)) //todo как будто нужно переделать + refspec := gitconfig.RefSpec(fmt.Sprintf("+refs/heads/pkgdash/go_modules/%s-%s:refs/heads/pkgdash/go_modules/%s-%s", path, mod.Version, path, mod.Version)) //todo как будто нужно переделать logger.Infof(ctx, "try to push refspec %s", refspec) @@ -252,9 +257,9 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod } body := map[string]string{ - "base": branch, + "base": "refs/heads/develop", "body": wBody.String(), - "head": fmt.Sprintf("pkgdash-1/go_modules/%s-%s", path, mod.Version), + "head": fmt.Sprintf("pkgdash/go_modules/%s-%s", path, mod.Version), "title": wTitle.String(), } logger.Infof(ctx, "raw body: %#+v", body)