#8 Checkout, auth. #16

Closed
kgorbunov wants to merge 104 commits from kgorbunov:dev into master
3 changed files with 36 additions and 10 deletions
Showing only changes of commit c0887adf99 - Show all commits

View File

@ -35,6 +35,7 @@ type Gitea struct {
Repository string
Owner string
pulls []*giteaPull
baseRef *plumbing.Reference
}
func NewGitea(cfg configcli.Config) *Gitea {
@ -111,12 +112,15 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
logger.Fatal(ctx, fmt.Sprintf("failed to fetch repo : %v", err))
} //обновляем репозиторий
var headRef, baseRef *plumbing.Reference // вроде ссылка на гит
var headRef *plumbing.Reference // вроде ссылка на гит
baseRef, err = repo.Head()
if g.baseRef == nil {
g.baseRef, err = repo.Head()
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("Error head: %s", err))
}
}
refIter, err := repo.Branches() //получение веток
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to get branches: %v", err))
@ -145,7 +149,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to get worktree: %v", err))
}
defer checkout(wtree, *baseRef)
defer checkout(wtree, *g.baseRef)
g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password)
if err != nil {

View File

@ -34,6 +34,7 @@ type Github struct {
Repository string
Owner string
pulls []*githubPull
baseRef *plumbing.Reference
}
func NewGithub(cfg configcli.Config) *Github {
@ -111,6 +112,14 @@ func (g *Github) RequestOpen(ctx context.Context, branch string, path string, mo
} //обновляем репозиторий
var headRef *plumbing.Reference // вроде ссылка на гит
if g.baseRef == nil {
g.baseRef, err = repo.Head()
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("Error head: %s", err))
}
}
refIter, err := repo.Branches() //получение веток
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to get branches: %v", err))
@ -139,6 +148,7 @@ func (g *Github) RequestOpen(ctx context.Context, branch string, path string, mo
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to get worktree: %v", err))
}
defer checkout(wtree, *g.baseRef)
g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password)
if err != nil {
@ -365,3 +375,12 @@ func GetPulls(ctx context.Context, url, owner, repo, password string) ([]*github
return pullsAll, nil
}
func checkout(w *git.Worktree, ref plumbing.Reference) {
ctx := context.Background()
logger.Debug(ctx, fmt.Sprintf("Checkout: %s", ref.Name().Short()))
if err := w.Checkout(&git.CheckoutOptions{Hash: ref.Hash()}); err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to reset: %v", err))
}
}

View File

@ -36,6 +36,7 @@ type Gitlab struct {
RepositoryId string
Owner string
pulls []*gitlabPull
baseRef *plumbing.Reference
}
func NewGitlab(cfg configcli.Config) *Gitlab {
@ -108,11 +109,13 @@ func (g *Gitlab) RequestOpen(ctx context.Context, branch string, path string, mo
logger.Fatal(ctx, fmt.Sprintf("failed to fetch repo : %v", err))
} //обновляем репозиторий
var headRef, baseRef *plumbing.Reference // вроде ссылка на гит
var headRef *plumbing.Reference // вроде ссылка на гит
baseRef, err = repo.Head()
if g.baseRef == nil {
g.baseRef, err = repo.Head()
if err != nil {
logger.Error(ctx, fmt.Sprintf("Error head: %s", err))
logger.Fatal(ctx, fmt.Sprintf("Error head: %s", err))
}
}
refIter, err := repo.Branches() //получение веток
@ -142,7 +145,7 @@ func (g *Gitlab) RequestOpen(ctx context.Context, branch string, path string, mo
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to get worktree: %v", err))
}
defer checkout(wtree, *baseRef)
defer checkout(wtree, *g.baseRef)
g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password)
if err != nil {