helper

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtoTypeAGit   = "agit"
	ProtoTypeGerrit = "gerrit"
)

Proto types

View Source
const (
	SSHVariantAuto = iota
	SSHVariantSimple
	SSHVariantSSH
	SSHVariantPlink
	SSHVariantPutty
	SSHVariantTortoisePlink
)

Define constants for SSH variant types.

Variables

View Source
var (
	UserEmailPattern = regexp.MustCompile(`^(.*?)\s*<([^@\s]+)@(\S*)>$`)
	EmailPattern     = regexp.MustCompile(`^<?([^@\s]+)@(\S+)>?$`)
)

Email patterns

View Source
var (
	// NormalArgsPattern matches args which do not need to be quoted.
	NormalArgsPattern = regexp.MustCompile(`^[0-9a-zA-Z:/%,.@+=_-]+$`)
)

Functions

func GetGitPushCommandPipe

func GetGitPushCommandPipe(proto ProtoHelper) ([]byte, error)

GetGitPushCommandPipe reads JSON from STDIN, pipe it to the helper, and output the result in JSON.

func GetLoginFromEmail

func GetLoginFromEmail(email string) string

GetLoginFromEmail gets login name from email address.

func GetProxyFromGitConfig added in v0.7.6

func GetProxyFromGitConfig() (*url.URL, error)

GetProxyFromGitConfig returns http proxy url through http.proxy

func ReplaceMacros added in v0.7.7

func ReplaceMacros(s string, macros map[string]string) string

ReplaceMacros replaces macros in string.

Types

type AGitProtoHelper

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

AGitProtoHelper implements helper for AGit server.

func NewAGitProtoHelper

func NewAGitProtoHelper(sshInfo *SSHInfo) *AGitProtoHelper

NewAGitProtoHelper returns AGitProtoHelper object.

func (AGitProtoHelper) GetDownloadRef

func (v AGitProtoHelper) GetDownloadRef(id, patch string) (string, error)

GetDownloadRef returns reference name of the specific code review.

func (AGitProtoHelper) GetGitPushCommand

func (v AGitProtoHelper) GetGitPushCommand(o *config.UploadOptions) (*GitPushCommand, error)

GetGitPushCommand reads upload options and returns git push command.

func (AGitProtoHelper) GetSSHInfo

func (v AGitProtoHelper) GetSSHInfo() *SSHInfo

GetSSHInfo returns SSHInfo object.

func (AGitProtoHelper) GetType

func (v AGitProtoHelper) GetType() string

GetType returns remote server type.

type DefaultProtoHelper

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

DefaultProtoHelper implements helper for unknown remote service.

func NewDefaultProtoHelper

func NewDefaultProtoHelper(sshInfo *SSHInfo) *DefaultProtoHelper

NewDefaultProtoHelper returns DefaultProtoHelper object.

func (DefaultProtoHelper) GetDownloadRef

func (v DefaultProtoHelper) GetDownloadRef(cr, patch string) (string, error)

GetDownloadRef returns reference name of the specific code review.

func (DefaultProtoHelper) GetGitPushCommand

func (v DefaultProtoHelper) GetGitPushCommand(o *config.UploadOptions) (*GitPushCommand, error)

GetGitPushCommand reads upload options and returns git push command.

func (DefaultProtoHelper) GetSSHInfo

func (v DefaultProtoHelper) GetSSHInfo() *SSHInfo

GetSSHInfo returns SSHInfo object.

func (DefaultProtoHelper) GetType

func (v DefaultProtoHelper) GetType() string

GetType returns remote server type.

type ExternalProtoHelper

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

ExternalProtoHelper implements helper for unknown remote service.

func NewExternalProtoHelper

func NewExternalProtoHelper(sshInfo *SSHInfo) *ExternalProtoHelper

NewExternalProtoHelper returns ExternalProtoHelper object.

func (ExternalProtoHelper) GetDownloadRef

func (v ExternalProtoHelper) GetDownloadRef(cr, patch string) (string, error)

GetDownloadRef returns reference name of the specific code review.

func (ExternalProtoHelper) GetGitPushCommand

func (v ExternalProtoHelper) GetGitPushCommand(o *config.UploadOptions) (*GitPushCommand, error)

GetGitPushCommand reads upload options and returns git push command.

func (ExternalProtoHelper) GetSSHInfo

func (v ExternalProtoHelper) GetSSHInfo() *SSHInfo

GetSSHInfo returns SSHInfo object.

func (ExternalProtoHelper) GetType

func (v ExternalProtoHelper) GetType() string

GetType returns remote server type.

func (*ExternalProtoHelper) Program

func (v *ExternalProtoHelper) Program() string

Program is program name of remote helper.

type GerritProtoHelper

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

GerritProtoHelper wraps helper for gerrit server.

func NewGerritProtoHelper

func NewGerritProtoHelper(sshInfo *SSHInfo) *GerritProtoHelper

NewGerritProtoHelper returns GerritProtoHelper object.

func (GerritProtoHelper) GetDownloadRef

func (v GerritProtoHelper) GetDownloadRef(cr, patch string) (string, error)

GetDownloadRef returns reference name of the specific code review.

func (GerritProtoHelper) GetGitPushCommand

func (v GerritProtoHelper) GetGitPushCommand(o *config.UploadOptions) (*GitPushCommand, error)

GetGitPushCommand reads upload options and returns git push command.

func (GerritProtoHelper) GetSSHInfo

func (v GerritProtoHelper) GetSSHInfo() *SSHInfo

GetSSHInfo returns SSHInfo object.

func (GerritProtoHelper) GetType

func (v GerritProtoHelper) GetType() string

GetType returns remote server type.

type GitPushCommand

type GitPushCommand struct {
	Cmd       string   `json:"cmd,omitempty"`
	Args      []string `json:"args,omitempty"`
	Env       []string `json:"env,omitempty"`
	GitConfig []string `json:"gitconfig,omitempty"`
}

GitPushCommand holds command and args for git command.

type ProtoHelper

type ProtoHelper interface {
	GetType() string
	GetSSHInfo() *SSHInfo
	GetGitPushCommand(*config.UploadOptions) (*GitPushCommand, error)
	GetDownloadRef(string, string) (string, error)
}

ProtoHelper defines interface for proto helper.

func NewProtoHelper

func NewProtoHelper(sshInfo *SSHInfo) ProtoHelper

NewProtoHelper returns proto helper for specific proto type.

type SSHCmd

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

SSHCmd is composor for SSH command.

func NewSSHCmd

func NewSSHCmd() *SSHCmd

NewSSHCmd returns SSHCmd by inspecting environments like `GIT_SSH_COMMAND`.

func (*SSHCmd) Args

func (v *SSHCmd) Args() []string

Args returns default ssh arguments.

func (*SSHCmd) Command

func (v *SSHCmd) Command(host string, port int, envs []string) ([]string, []string)

Command returns command and environments used for ssh connection.

func (*SSHCmd) SSH

func (v *SSHCmd) SSH() string

SSH returns ssh program name.

func (*SSHCmd) Variant

func (v *SSHCmd) Variant() int

Variant indicates ssh variant type.

type SSHInfo

type SSHInfo struct {
	// PushURL gives the URL prefix of the repository to push.
	// Macro "<email>" and "<login>" can be used as the user part of PushURL.
	PushURL string `json:"pushurl,omitempty"`

	// If PushURL is not defined, will try to compose a SSH URL for push
	// using the host, port and user provided. Macro "{email}" and "{login}"
	// can be used in the user part.
	Host string `json:"host,omitempty"`
	Port int    `json:"port,omitempty"`
	User string `json:"user,omitempty"`

	// Proto type and version for the protocol, such as "gerrit", "agit", etc.
	ProtoType    string `json:"type,omitempty"`
	ProtoVersion int    `json:"version,omitempty"`

	// ReviewRefPattern is used to compose the refname for the the specifc code review.
	// Macro {id}, {patch}, {id:left:N}, {id:right:N} can be used in this pattern.
	ReviewRefPattern string `json:"review_ref,omitempty"`

	Expire int64 `json:"-"`
}

SSHInfo stands for Smart Submit Handler information. Hold data returned from ssh_info API

func (SSHInfo) GetReviewRef added in v0.7.7

func (v SSHInfo) GetReviewRef(id, patch string) (string, error)

GetReviewRef gets review ref from ReviewRefPattern.

func (SSHInfo) ToJSON

func (v SSHInfo) ToJSON() string

ToJSON encodes ssh_info to JSON.

func (SSHInfo) Validate added in v0.7.8

func (v SSHInfo) Validate() error

Validate checks format of SSHInfo.

type SSHInfoQuery

type SSHInfoQuery struct {
	CacheFile string

	Changed bool
	// contains filtered or unexported fields
}

SSHInfoQuery wraps cache to accelerate query of ssh_info API.

func NewSSHInfoQuery

func NewSSHInfoQuery(cacheFile string) *SSHInfoQuery

NewSSHInfoQuery creates new query object. file is name of the cache.

func (SSHInfoQuery) GetSSHInfo

func (v SSHInfoQuery) GetSSHInfo(address string, useCache bool) (*SSHInfo, error)

GetSSHInfo queries ssh_info for address.

type ShellCmd

type ShellCmd struct {
	Cmd  string
	Args []string
}

ShellCmd is used to parse shell command.

func NewShellCmd

func NewShellCmd(cmd string, withArgs bool) *ShellCmd

NewShellCmd creates ShellCmd object from command line.

func NewShellCmdFromArgs

func NewShellCmdFromArgs(args ...string) *ShellCmd

NewShellCmdFromArgs creates ShellCmd from command args.

func (ShellCmd) QuoteCommand

func (v ShellCmd) QuoteCommand() string

QuoteCommand quotes command args which has space.

Jump to

Keyboard shortcuts

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