Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions internal/util/GitCliUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (impl *GitCliUtil) Init(rootDir string, remoteUrl string, isBare bool) erro
}

func (impl *GitCliUtil) Clone(rootDir string, remoteUrl string, username string, password string) (response, errMsg string, err error) {
impl.logger.Infow("input", rootDir, remoteUrl, username)
impl.logger.Infow("git clone request", "rootDir", rootDir, "remoteUrl", remoteUrl, "username", username)
err = impl.Init(rootDir, remoteUrl, false)
if err != nil {
return "", "", err
Expand All @@ -111,24 +111,30 @@ func (impl *GitCliUtil) Clone(rootDir string, remoteUrl string, username string,
if err == nil && errMsg == "" {
impl.logger.Warn("git fetch completed, pulling master branch data from remote origin")
response, errMsg, err = impl.ListBranch(rootDir, username, password)
if err != nil {
impl.logger.Errorw("error on git pull", "response", response, "errMsg", errMsg, "err", err)
return response, errMsg, err
}
branches := strings.Split(response, "\n")
impl.logger.Info(branches)
impl.logger.Infow("total branch available in git repo", "branches", branches)
branch := ""
for _, item := range branches {
if strings.TrimSpace(item) == "origin/master" {
branch = Branch_Master
}
}
if len(branch) == 0 && len(branches) > 0 {
//if git repo has some branch take pull of the first branch, but eventually proxy chart will push into master branch
if len(branch) == 0 && branches != nil && len(branches[0]) > 0 {
branch = strings.ReplaceAll(branches[0], "origin/", "")
} else if len(branch) == 0 {
// only fetch will work, as we don't have any branch for pull
return "", "", nil
}
if branch == "" {
impl.logger.Warnw("no branch found in git repo", "remoteUrl", remoteUrl, "response", response)
return response, "", nil
}
response, errMsg, err = impl.Pull(rootDir, username, password, branch)
if err != nil {
impl.logger.Errorw("error on git pull", "branch", branch, "err", err)
return "", "", err
return response, errMsg, err
}
}
return response, errMsg, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,13 @@ func (impl AppStoreDeploymentServiceImpl) UpdateInstalledApp(ctx context.Context
err = impl.appStoreDeploymentArgoCdService.UpdateRequirementDependencies(environment, installedAppVersion, installAppVersionRequest, appStoreAppVersion)
if err != nil {
impl.logger.Errorw("error while commit required dependencies to git", "error", err)
return nil, err
noTargetFound, _ := impl.appStoreDeploymentArgoCdService.ParseGitRepoErrorResponse(err)
if noTargetFound {
//if by mistake no content found while updating git repo, do auto fix
installAppVersionRequest, err = impl.appStoreDeploymentArgoCdService.OnUpdateRepoInInstalledApp(ctx, installAppVersionRequest)
} else {
return nil, err
}
}
}
installAppVersionRequest.Id = installedAppVersion.Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"github.com/ghodss/yaml"
"github.com/go-pg/pg"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/google/go-github/github"
"github.com/microsoft/azure-devops-go-api/azuredevops"
"github.com/xanzy/go-gitlab"
"go.uber.org/zap"
"net/http"
"strings"
Expand All @@ -38,6 +41,7 @@ type AppStoreDeploymentArgoCdService interface {
OnUpdateRepoInInstalledApp(ctx context.Context, installAppVersionRequest *appStoreBean.InstallAppVersionDTO) (*appStoreBean.InstallAppVersionDTO, error)
UpdateRequirementDependencies(environment *clusterRepository.Environment, installedAppVersion *repository.InstalledAppVersions, installAppVersionRequest *appStoreBean.InstallAppVersionDTO, appStoreAppVersion *appStoreDiscoverRepository.AppStoreApplicationVersion) error
UpdateInstalledApp(ctx context.Context, installAppVersionRequest *appStoreBean.InstallAppVersionDTO, environment *clusterRepository.Environment, installedAppVersion *repository.InstalledAppVersions) (*appStoreBean.InstallAppVersionDTO, error)
ParseGitRepoErrorResponse(err error) (bool, error)
}

type AppStoreDeploymentArgoCdServiceImpl struct {
Expand Down Expand Up @@ -385,7 +389,13 @@ func (impl AppStoreDeploymentArgoCdServiceImpl) UpdateInstalledApp(ctx context.C
installAppVersionRequest, err := impl.updateValuesYaml(environment, installedAppVersion, installAppVersionRequest)
if err != nil {
impl.Logger.Errorw("error while commit values to git", "error", err)
return nil, err
noTargetFound, _ := impl.ParseGitRepoErrorResponse(err)
if noTargetFound {
//if by mistake no content found while updating git repo, do auto fix
installAppVersionRequest, err = impl.OnUpdateRepoInInstalledApp(ctx, installAppVersionRequest)
} else {
return nil, err
}
}
installAppVersionRequest.Environment = environment

Expand Down Expand Up @@ -463,3 +473,27 @@ func (impl AppStoreDeploymentArgoCdServiceImpl) updateValuesYaml(environment *cl
installAppVersionRequest.GitHash = commitHash
return installAppVersionRequest, nil
}

func (impl AppStoreDeploymentArgoCdServiceImpl) ParseGitRepoErrorResponse(err error) (bool, error) {
//update values yaml in chart
noTargetFound := false
if err != nil {
if errorResponse, ok := err.(*github.ErrorResponse); ok && errorResponse.Response.StatusCode == http.StatusNotFound {
impl.Logger.Errorw("no content found while updating git repo on github, do auto fix", "error", err)
noTargetFound = true
}
if errorResponse, ok := err.(azuredevops.WrappedError); ok && *errorResponse.StatusCode == http.StatusNotFound {
impl.Logger.Errorw("no content found while updating git repo on azure, do auto fix", "error", err)
noTargetFound = true
}
if errorResponse, ok := err.(*gitlab.ErrorResponse); ok && errorResponse.Response.StatusCode == http.StatusNotFound {
impl.Logger.Errorw("no content found while updating git repo gitlab, do auto fix", "error", err)
noTargetFound = true
}
if err.Error() == util.BITBUCKET_REPO_NOT_FOUND_ERROR {
impl.Logger.Errorw("no content found while updating git repo bitbucket, do auto fix", "error", err)
noTargetFound = true
}
}
return noTargetFound, err
}