scmhelpers

package
v3.4.9 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: Apache-2.0 Imports: 28 Imported by: 52

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsLabel

func ContainsLabel(labels []*scm.Label, label string) bool

ContainsLabel returns true if the given labels contains the given label name

func DiscoverGitKind

func DiscoverGitKind(jxClient versioned.Interface, namespace, gitServerURL string) (string, error)

DiscoverGitKind discovers the git kind for the given git server from the SourceRepository resources. If no jxClient is provided it is lazily created

func FindPullRequestFromEnvironment

func FindPullRequestFromEnvironment() (int, error)

FindPullRequestFromEnvironment returns the PullRequest number by looking for common Jenkins X environment variables

func GetPasswordFromSourceURL

func GetPasswordFromSourceURL(sourceURL string) (string, error)

GetPasswordFromSourceURL returns password from the git URL

func IsScmNotFound

func IsScmNotFound(err error) bool

func IsScmResponseNotFound added in v3.0.50

func IsScmResponseNotFound(res *scm.Response) bool

func NewScmClient

func NewScmClient(kind, gitServerURL, token string, ignoreMissingToken bool) (*scm.Client, string, error)

NewScmClient creates a new Scm client for the given git kind, server URL and token. If no token is supplied we default it

func ParsePullRequestURL added in v3.0.10

func ParsePullRequestURL(url string) (*scm.PullRequest, error)

ParsePullRequestURL parses the PullRequest from the string

Types

type CreateRepository

type CreateRepository struct {
	GitServer       string
	GitKind         string
	Owner           string
	Repository      string
	CurrentUsername string
	GitPublic       bool
}

func (*CreateRepository) ConfirmValues

func (r *CreateRepository) ConfirmValues(i input.Interface, batch bool) error

ConfirmValues confirms to the user the values to be used to create the new git repository if using batch mode lets just validate the values are supplied or fail

func (*CreateRepository) CreateRepository

func (r *CreateRepository) CreateRepository(scmClient *scm.Client) (*scm.Repository, error)

CreateRepository creates the git repository if it does not already exist

func (*CreateRepository) FullName

func (r *CreateRepository) FullName() string

type Factory

type Factory struct {
	GitKind                   string
	GitServerURL              string
	GitUsername               string
	GitToken                  string
	IgnoreMissingToken        bool
	NoWriteGitCredentialsFile bool
	ScmClient                 *scm.Client

	// Input specifies the input to use if we are not using batch mode so that we can lazily populate
	// the git user and token if it cannot be discovered automatically
	Input input.Interface

	// GitCredentialFile allows faking for easier testing
	GitCredentialFile string
}

Factory helper for discovering the git source URL and token

func (*Factory) AddFlags

func (o *Factory) AddFlags(cmd *cobra.Command)

AddFlags adds CLI arguments to configure the parameters

func (*Factory) Create

func (o *Factory) Create() (*scm.Client, error)

Create creates an ScmClient

func (*Factory) CreateAuthenticatedURL

func (o *Factory) CreateAuthenticatedURL(cloneURL string) (string, error)

CreateAuthenticatedURL creates the Git repository URL with the username and password encoded for HTTPS based URLs

func (*Factory) FindGitToken

func (o *Factory) FindGitToken() error

FindGitToken ensures the GitToken is populated

func (*Factory) GetUsername

func (o *Factory) GetUsername() (string, error)

GetUsername gets the current user name from the ScmClient if its not explicitly configured

type Options

type Options struct {
	Dir                string
	FullRepositoryName string
	Owner              string
	Repository         string
	Branch             string
	ScmClient          *scm.Client
	GitServerURL       string
	SourceURL          string
	GitKind            string
	GitToken           string
	Namespace          string
	DiscoverFromGit    bool
	PreferUpstream     bool
	IgnoreMissingToken bool
	JXClient           versioned.Interface
	GitURL             *giturl.GitRepository
	GitClient          gitclient.Interface
	CommandRunner      cmdrunner.CommandRunner
}

Options helper for discovering the git source URL and token

func (*Options) AddFlags

func (o *Options) AddFlags(cmd *cobra.Command)

AddFlags adds CLI arguments to configure the parameters

func (*Options) GetBranch added in v3.0.38

func (o *Options) GetBranch() (string, error)

GetBranch returns the configured branch or discovers it from git

func (*Options) Validate

func (o *Options) Validate() error

Validate validates the inputs are valid and a ScmClient can be created

type PullRequestOptions

type PullRequestOptions struct {
	Options

	// Number the Pull Request number
	Number int

	// IgnoreMissingPullRequest does not return an error if no pull request could be found
	IgnoreMissingPullRequest bool
}

func (*PullRequestOptions) AddFlags

func (o *PullRequestOptions) AddFlags(cmd *cobra.Command)

AddFlags adds CLI flags

func (*PullRequestOptions) DiscoverPullRequest

func (o *PullRequestOptions) DiscoverPullRequest() (*scm.PullRequest, error)

DiscoverPullRequest discovers the pull request for the current number

func (*PullRequestOptions) Validate

func (o *PullRequestOptions) Validate() error

Validate validates the inputs are valid

Jump to

Keyboard shortcuts

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