#8 after create PR, delete local branch.

This commit is contained in:
Gorbunov Kirill Andreevich 2024-04-02 18:44:17 +03:00
parent 9a657f6c21
commit 7e6ebcbe89
2 changed files with 40 additions and 3 deletions

View File

@ -146,7 +146,6 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
}
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))
return g.RequestUpdate(ctx, branch, path, mod)
@ -278,6 +277,13 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
return fmt.Errorf("unknown error: %s", buf)
}
logger.Info(ctx, fmt.Sprintf("PR create for %s-%s", path, mod.Version))
repo, err = git.PlainOpenWithOptions(".", &git.PlainOpenOptions{DetectDotGit: true})
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to open repo: %v", err))
}
if err = wtree.Checkout(&git.CheckoutOptions{
Hash: headRef.Hash(),
Branch: headRef.Name(),
@ -293,8 +299,6 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
logger.Error(ctx, fmt.Sprintf("Delete local branch error: %s", err))
}
logger.Info(ctx, fmt.Sprintf("PR create for %s-%s", path, mod.Version))
return nil
}
@ -469,3 +473,28 @@ func GetPulls(ctx context.Context, url, owner, repo, token string) ([]*giteaPull
return pullsAll, nil
}
func deleteLocalBranch() {
ctx := context.Background()
repo, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{DetectDotGit: true})
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to open repo: %v", err))
}
refIter, err := repo.Branches() //получение веток
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to get branches: %v", err))
}
for {
ref, err := refIter.Next()
if err != nil {
break
}
if strings.HasPrefix(ref.Name().Short(), "pkgdash/") {
err = repo.DeleteBranch(ref.Name().Short())
logger.Fatal(ctx, fmt.Sprintf("Delete error: %s", err))
}
}
refIter.Close()
}

View File

@ -0,0 +1,8 @@
package gitea
import "testing"
func Test_deleteLocalBranch(t *testing.T) {
_ = t
deleteLocalBranch()
}