#8 add gitlab #13

Closed
kgorbunov wants to merge 93 commits from kgorbunov/pkgdash:master into master
2 changed files with 40 additions and 3 deletions
Showing only changes of commit 7e6ebcbe89 - Show all commits

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()
}