Help us shape the future of Go! Take the 2026 Go Developer Survey

git

package
v1.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2025 License: Apache-2.0 Imports: 41 Imported by: 12

Documentation

Index

Constants

View Source
const (
	HTTP_URL_PROTOCOL            = "http://"
	HTTPS_URL_PROTOCOL           = "https://"
	BITBUCKET_CLONE_BASE_URL     = "https://bitbucket.org/"
	BITBUCKET_GITOPS_DIR         = "bitbucketGitOps"
	BITBUCKET_COMMIT_TIME_LAYOUT = "2001-01-01T10:00:00+00:00"
)
View Source
const PushErrorMessage = "failed to push some refs"

Variables

View Source
var BitbucketRepoNotFoundError = fmt.Errorf("404 Not Found")

Functions

func CreateGitlabClient

func CreateGitlabClient(host, token string, tlsConfig *tls.Config) (*gitlab.Client, error)

func GetGitConfigAll added in v1.8.0

func GetGitConfigAll(gitOpsConfigReadService config.GitOpsConfigReadService) ([]*bean.GitConfig, error)

func IsRepoNotFound added in v0.7.3

func IsRepoNotFound(err error) bool

func SanitiseCustomGitRepoURL

func SanitiseCustomGitRepoURL(activeGitOpsConfig *apiGitOpsBean.GitOpsConfigDto, gitRepoURL string) (sanitisedGitRepoURL string)

SanitiseCustomGitRepoURL - It will sanitise the user given repository url based on GitOps provider

Case BITBUCKET_PROVIDER:

  • The clone URL format https://<user-name>@bitbucket.org/<workspace-name>/<repo-name>.git
  • Here the <user-name> can differ from user to user. SanitiseCustomGitRepoURL will return the repo url in format : https://bitbucket.org/<workspace-name>/<repo-name>.git

Case AZURE_DEVOPS_PROVIDER:

  • The clone URL format https://<organisation-name>@dev.azure.com/<organisation-name>/<project-name>/_git/<repo-name>
  • Here the <user-name> can differ from user to user. SanitiseCustomGitRepoURL will return the repo url in format : https://dev.azure.com/<organisation-name>/<project-name>/_git/<repo-name>

Types

type ChartConfig

type ChartConfig struct {
	ChartName      string
	ChartLocation  string
	FileName       string //filename
	FileContent    string
	ReleaseMessage string
	ChartRepoName  string
	TargetRevision string
	// UseDefaultBranch will override the TargetRevision and use the default branch of the repo
	// This is currently implemented for the bitbucket client only.
	// This is used to create the first commit on default branch.
	UseDefaultBranch bool
	UserName         string
	UserEmailId      string
	// contains filtered or unexported fields
}

func (*ChartConfig) GetBitBucketBaseDir added in v0.7.2

func (c *ChartConfig) GetBitBucketBaseDir() string

func (*ChartConfig) SetBitBucketBaseDir added in v0.7.2

func (c *ChartConfig) SetBitBucketBaseDir(dir string)

type ClientHelperObject added in v1.8.0

type ClientHelperObject struct {
	Config *bean.GitConfig
}

type DetailedErrorGitOpsConfigActions

type DetailedErrorGitOpsConfigActions struct {
	SuccessfulStages []string         `json:"successfulStages"`
	StageErrorMap    map[string]error `json:"stageErrorMap"`
	ValidatedOn      time.Time        `json:"validatedOn"`
	DeleteRepoFailed bool             `json:"deleteRepoFailed"`
}

type GitAzureClient

type GitAzureClient struct {
	// contains filtered or unexported fields
}

func NewGitAzureClient

func NewGitAzureClient(token string, host string, project string, logger *zap.SugaredLogger, gitOpsHelper *GitOpsHelper, tlsConfig *tls.Config) (GitAzureClient, error)

func (GitAzureClient) CommitValues

func (impl GitAzureClient) CommitValues(ctx context.Context, config *ChartConfig, gitOpsConfig *bean2.GitOpsConfigDto, publishStatusConflictError bool) (commitHash string, commitTime time.Time, err error)

func (GitAzureClient) CreateFirstCommitOnHead added in v1.8.0

func (impl GitAzureClient) CreateFirstCommitOnHead(ctx context.Context, config *bean2.GitOpsConfigDto) (string, error)

func (GitAzureClient) CreateReadme

func (impl GitAzureClient) CreateReadme(ctx context.Context, config *bean2.GitOpsConfigDto) (string, error)

func (GitAzureClient) CreateRepository

func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.GitOpsConfigDto) (url string, isNew bool, isEmpty bool, detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions)

func (GitAzureClient) DeleteRepository

func (impl GitAzureClient) DeleteRepository(config *bean2.GitOpsConfigDto) (err error)

func (GitAzureClient) GetRepoUrl

func (impl GitAzureClient) GetRepoUrl(config *bean2.GitOpsConfigDto) (repoUrl string, isRepoEmpty bool, err error)

type GitBitbucketClient

type GitBitbucketClient struct {
	// contains filtered or unexported fields
}

func NewGitBitbucketClient

func NewGitBitbucketClient(username, token, host string, logger *zap.SugaredLogger, gitOpsHelper *GitOpsHelper, tlsConfig *tls.Config) GitBitbucketClient

func (GitBitbucketClient) CommitValues

func (impl GitBitbucketClient) CommitValues(ctx context.Context, config *ChartConfig, gitOpsConfig *bean2.GitOpsConfigDto, publishStatusConflictError bool) (commitHash string, commitTime time.Time, err error)

func (GitBitbucketClient) CreateFirstCommitOnHead added in v1.8.0

func (impl GitBitbucketClient) CreateFirstCommitOnHead(ctx context.Context, config *bean2.GitOpsConfigDto) (string, error)

func (GitBitbucketClient) CreateReadme

func (impl GitBitbucketClient) CreateReadme(ctx context.Context, config *bean2.GitOpsConfigDto) (string, error)

func (GitBitbucketClient) CreateRepository

func (impl GitBitbucketClient) CreateRepository(ctx context.Context, config *bean2.GitOpsConfigDto) (url string, isNew bool, isEmpty bool, detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions)

func (GitBitbucketClient) DeleteRepository

func (impl GitBitbucketClient) DeleteRepository(config *bean2.GitOpsConfigDto) (err error)

func (GitBitbucketClient) GetRepoUrl

func (impl GitBitbucketClient) GetRepoUrl(config *bean2.GitOpsConfigDto) (repoUrl string, isRepoEmpty bool, err error)

type GitFactory

type GitFactory struct {
	Client       GitOpsClient
	GitOpsHelper *GitOpsHelper

	ClientHelperMap map[string]*ClientHelperObject
	// contains filtered or unexported fields
}

func NewGitFactory

func NewGitFactory(logger *zap.SugaredLogger, gitOpsConfigReadService config.GitOpsConfigReadService) (*GitFactory, error)

func (*GitFactory) GetGitLabGroupPath

func (factory *GitFactory) GetGitLabGroupPath(gitOpsConfig *gitOps.GitOpsConfigDto) (string, error)

func (*GitFactory) NewClientForValidation

func (factory *GitFactory) NewClientForValidation(gitOpsConfig *gitOps.GitOpsConfigDto) (GitOpsClient, *GitOpsHelper, error)

func (*GitFactory) Reload

func (factory *GitFactory) Reload(gitOpsConfigReadService config.GitOpsConfigReadService) (err error)

type GitHubClient

type GitHubClient struct {
	// contains filtered or unexported fields
}

func NewGithubClient

func NewGithubClient(host string, token string, org string, logger *zap.SugaredLogger,
	gitOpsHelper *GitOpsHelper, tlsConfig *tls.Config) (GitHubClient, error)

func (GitHubClient) CommitValues

func (impl GitHubClient) CommitValues(ctx context.Context, config *ChartConfig, gitOpsConfig *bean2.GitOpsConfigDto, publishStatusConflictErrorMetrics bool) (commitHash string, commitTime time.Time, err error)

func (GitHubClient) CreateFirstCommitOnHead added in v1.8.0

func (impl GitHubClient) CreateFirstCommitOnHead(ctx context.Context, config *bean2.GitOpsConfigDto) (string, error)

func (GitHubClient) CreateReadme

func (impl GitHubClient) CreateReadme(ctx context.Context, config *bean2.GitOpsConfigDto) (string, error)

func (GitHubClient) CreateRepository

func (impl GitHubClient) CreateRepository(ctx context.Context, config *bean2.GitOpsConfigDto) (url string, isNew bool, isEmpty bool, detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions)

func (GitHubClient) DeleteRepository

func (impl GitHubClient) DeleteRepository(config *bean2.GitOpsConfigDto) error

func (GitHubClient) GetRepoUrl

func (impl GitHubClient) GetRepoUrl(config *bean2.GitOpsConfigDto) (repoUrl string, isRepoEmpty bool, err error)

type GitLabClient

type GitLabClient struct {
	// contains filtered or unexported fields
}

func (GitLabClient) CommitValues

func (impl GitLabClient) CommitValues(ctx context.Context, config *ChartConfig, gitOpsConfig *bean2.GitOpsConfigDto, publishStatusConflictError bool) (commitHash string, commitTime time.Time, err error)

func (GitLabClient) CreateFirstCommitOnHead added in v1.8.0

func (impl GitLabClient) CreateFirstCommitOnHead(ctx context.Context, config *bean2.GitOpsConfigDto) (string, error)

func (GitLabClient) CreateReadme

func (impl GitLabClient) CreateReadme(ctx context.Context, config *bean2.GitOpsConfigDto) (string, error)

func (GitLabClient) CreateRepository

func (impl GitLabClient) CreateRepository(ctx context.Context, config *bean2.GitOpsConfigDto) (url string, isNew bool, isEmpty bool, detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions)

func (GitLabClient) DeleteProject

func (impl GitLabClient) DeleteProject(projectName string) (err error)

func (GitLabClient) DeleteRepository

func (impl GitLabClient) DeleteRepository(config *bean2.GitOpsConfigDto) (err error)

func (GitLabClient) GetRepoUrl

func (impl GitLabClient) GetRepoUrl(config *bean2.GitOpsConfigDto) (repoUrl string, isRepoEmpty bool, err error)

type GitOperationService

type GitOperationService interface {
	CreateGitRepositoryForDevtronApp(ctx context.Context, gitOpsRepoName string, targetRevision string, userId int32) (chartGitAttribute *commonBean.ChartGitAttribute, err error)
	// CreateFirstCommitOnHead - creates the first commit on the head of the git repository (mostly empty).
	// To register the git repository in ArgoCD, there should be a commit HEAD on the default branch.
	CreateFirstCommitOnHead(ctx context.Context, gitOpsRepoName string, userId int32) error
	GitPull(clonedDir string, repoUrl string, targetRevision string) error

	CommitValues(ctx context.Context, chartGitAttr *ChartConfig) (commitHash string, commitTime time.Time, err error)
	PushChartToGitRepo(ctx context.Context, gitOpsRepoName, chartLocation, tempReferenceTemplateDir, repoUrl, targetRevision string, userId int32) (err error)
	CloneChartForHelmApp(helmAppName, gitRepoUrl, targetRevision string) (string, error)
	PushChartToGitOpsRepoForHelmApp(ctx context.Context, pushChartToGitRequest *bean.PushChartToGitRequestDTO, valuesConfig *ChartConfig) (*commonBean.ChartGitAttribute, string, error)

	CreateRepository(ctx context.Context, dto *apiBean.GitOpsConfigDto, userId int32) (string, bool, bool, error)

	GetClonedDir(ctx context.Context, chartDir, repoUrl, targetRevision string) (string, error)
	ReloadGitOpsProvider() error
	UpdateGitHostUrlByProvider(request *apiBean.GitOpsConfigDto) error
	GetRepoUrlWithUserName(url string) (string, error)
}

type GitOperationServiceImpl

type GitOperationServiceImpl struct {
	// contains filtered or unexported fields
}

func NewGitOperationServiceImpl

func NewGitOperationServiceImpl(logger *zap.SugaredLogger, gitFactory *GitFactory,
	gitOpsConfigReadService config.GitOpsConfigReadService,
	chartTemplateService util.ChartTemplateService,
	envVariables *globalUtil.EnvironmentVariables) *GitOperationServiceImpl

func (*GitOperationServiceImpl) CloneChartForHelmApp added in v1.8.0

func (impl *GitOperationServiceImpl) CloneChartForHelmApp(helmAppName, gitRepoUrl, targetRevision string) (string, error)

func (*GitOperationServiceImpl) CommitValues

func (impl *GitOperationServiceImpl) CommitValues(ctx context.Context, chartGitAttr *ChartConfig) (commitHash string, commitTime time.Time, err error)

func (*GitOperationServiceImpl) CreateFirstCommitOnHead added in v1.8.0

func (impl *GitOperationServiceImpl) CreateFirstCommitOnHead(ctx context.Context, gitOpsRepoName string, userId int32) error

func (*GitOperationServiceImpl) CreateGitRepositoryForDevtronApp added in v0.7.1

func (impl *GitOperationServiceImpl) CreateGitRepositoryForDevtronApp(ctx context.Context, gitOpsRepoName string, targetRevision string, userId int32) (chartGitAttribute *commonBean.ChartGitAttribute, err error)

func (*GitOperationServiceImpl) CreateRepository

func (impl *GitOperationServiceImpl) CreateRepository(ctx context.Context, dto *apiBean.GitOpsConfigDto, userId int32) (string, bool, bool, error)

func (*GitOperationServiceImpl) GetClonedDir

func (impl *GitOperationServiceImpl) GetClonedDir(ctx context.Context, chartDir, repoUrl, targetRevision string) (string, error)

func (*GitOperationServiceImpl) GetRepoUrlWithUserName added in v1.0.0

func (impl *GitOperationServiceImpl) GetRepoUrlWithUserName(url string) (string, error)

func (*GitOperationServiceImpl) GitPull

func (impl *GitOperationServiceImpl) GitPull(clonedDir string, repoUrl string, targetRevision string) error

func (*GitOperationServiceImpl) PushChartToGitOpsRepoForHelmApp

func (impl *GitOperationServiceImpl) PushChartToGitOpsRepoForHelmApp(ctx context.Context, pushChartToGitRequest *bean.PushChartToGitRequestDTO, valuesConfig *ChartConfig) (*commonBean.ChartGitAttribute, string, error)

PushChartToGitOpsRepoForHelmApp pushes built chart to GitOps repo (Specific implementation for Helm Apps) TODO refactoring: Make a common method for both PushChartToGitRepo and PushChartToGitOpsRepoForHelmApp

func (*GitOperationServiceImpl) PushChartToGitRepo

func (impl *GitOperationServiceImpl) PushChartToGitRepo(ctx context.Context, gitOpsRepoName, chartLocation, tempReferenceTemplateDir, repoUrl, targetRevision string, userId int32) (err error)

func (*GitOperationServiceImpl) ReloadGitOpsProvider

func (impl *GitOperationServiceImpl) ReloadGitOpsProvider() error

func (*GitOperationServiceImpl) UpdateGitHostUrlByProvider

func (impl *GitOperationServiceImpl) UpdateGitHostUrlByProvider(request *apiBean.GitOpsConfigDto) error

type GitOpsClient

type GitOpsClient interface {
	CreateRepository(ctx context.Context, config *gitOps.GitOpsConfigDto) (url string, isNew bool, isEmpty bool, detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions)
	CommitValues(ctx context.Context, config *ChartConfig, gitOpsConfig *gitOps.GitOpsConfigDto, publishStatusConflictError bool) (commitHash string, commitTime time.Time, err error)
	GetRepoUrl(config *gitOps.GitOpsConfigDto) (repoUrl string, isRepoEmpty bool, err error)
	DeleteRepository(config *gitOps.GitOpsConfigDto) error
	CreateReadme(ctx context.Context, config *gitOps.GitOpsConfigDto) (string, error)
	// CreateFirstCommitOnHead creates a commit on the HEAD of the repository, used for initializing the repository.
	// It is used when the repository is empty and needs an initial commit.
	CreateFirstCommitOnHead(ctx context.Context, config *gitOps.GitOpsConfigDto) (string, error)
}

func NewGitLabClient

func NewGitLabClient(config *bean.GitConfig, logger *zap.SugaredLogger, gitOpsHelper *GitOpsHelper, tlsConfig *tls.Config) (GitOpsClient, error)

func NewGitOpsClient

func NewGitOpsClient(config *bean.GitConfig, logger *zap.SugaredLogger, gitOpsHelper *GitOpsHelper) (GitOpsClient, error)

type GitOpsHelper

type GitOpsHelper struct {
	Auth *git.BasicAuth
	// contains filtered or unexported fields
}

GitOpsHelper GitOps Helper maintains the auth creds in state and is used by implementation of git client implementations and GitFactory

func NewGitOpsHelperImpl

func NewGitOpsHelperImpl(auth *git.BasicAuth, logger *zap.SugaredLogger, tlsConfig *bean.TLSConfig, isTlsEnabled bool) (*GitOpsHelper, error)

func (*GitOpsHelper) Clone

func (impl *GitOpsHelper) Clone(url, targetDir, targetRevision string) (clonedDir string, err error)

func (*GitOpsHelper) CommitAndPushAllChanges

func (impl *GitOpsHelper) CommitAndPushAllChanges(ctx context.Context, repoRoot, targetRevision, commitMsg, name, emailId string) (commitHash string, err error)

func (*GitOpsHelper) GetCloneDirectory

func (impl *GitOpsHelper) GetCloneDirectory(targetDir string) (clonedDir string)

func (*GitOpsHelper) Pull

func (impl *GitOpsHelper) Pull(repoRoot, targetRevision string) (err error)

func (*GitOpsHelper) SetAuth

func (impl *GitOpsHelper) SetAuth(auth *git.BasicAuth)

type UnimplementedGitOpsClient added in v1.8.0

type UnimplementedGitOpsClient struct{}

func (*UnimplementedGitOpsClient) CommitValues added in v1.8.0

func (u *UnimplementedGitOpsClient) CommitValues(ctx context.Context, config *ChartConfig, gitOpsConfig *gitOps.GitOpsConfigDto, publishStatusConflictError bool) (commitHash string, commitTime time.Time, err error)

func (*UnimplementedGitOpsClient) CreateFirstCommitOnHead added in v1.8.0

func (u *UnimplementedGitOpsClient) CreateFirstCommitOnHead(ctx context.Context, config *gitOps.GitOpsConfigDto) (string, error)

func (*UnimplementedGitOpsClient) CreateReadme added in v1.8.0

func (u *UnimplementedGitOpsClient) CreateReadme(ctx context.Context, config *gitOps.GitOpsConfigDto) (string, error)

func (*UnimplementedGitOpsClient) CreateRepository added in v1.8.0

func (u *UnimplementedGitOpsClient) CreateRepository(ctx context.Context, config *gitOps.GitOpsConfigDto) (url string, isNew bool, isEmpty bool, detailedErrorGitOpsConfigActions DetailedErrorGitOpsConfigActions)

func (*UnimplementedGitOpsClient) DeleteRepository added in v1.8.0

func (u *UnimplementedGitOpsClient) DeleteRepository(config *gitOps.GitOpsConfigDto) error

func (*UnimplementedGitOpsClient) GetRepoUrl added in v1.8.0

func (u *UnimplementedGitOpsClient) GetRepoUrl(config *gitOps.GitOpsConfigDto) (repoUrl string, isRepoEmpty bool, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL