gitlab

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const IssueType = "issue"

Variables

View Source
var (
	ErrServerNotConfigured = errors.New("No configuration for this server")
	ErrParseProjectPath    = errors.New("Unable to parse project path")
)
View Source
var (
	ErrNoRepository = errors.New("Not a git repository (or any of the parent directories)")
	ErrNoUpstream   = errors.New("No upstream for this repository")
	ErrDetachedHead = errors.New("No branch detected: detached HEAD")
)
View Source
var (
	ErrNoPipelines = errors.New("No pipelines found for this commit on this ref")
)
View Source
var UserAgent = "jramsay/Lab 0.0.1"

TODO Use LDFLags to set the version

Functions

func AccessTokenForHost

func AccessTokenForHost(h string) string

AccessTokenForHost returns the access token for the host from the git-lab config file

func ExitCodeFromStatus

func ExitCodeFromStatus(status string) (c int)

func FindStringSubmatchMap

func FindStringSubmatchMap(r *regexp.Regexp, s string) map[string]string

func GlyphFromStatus

func GlyphFromStatus(status string) (g string)

func IsCommit

func IsCommit(sha string) bool

IsCommit returns true if the provided sha references a commit, and returns false for all other input.

func JobIsFinished

func JobIsFinished(p *Project, ID int) (bool, error)

func JobsStatus

func JobsStatus(jobs []*Job) (s string)

func Lint

func Lint(p *Project, c string) ([]string, error)

func NewClient

func NewClient(h string) (*gitlab.Client, error)

NewClient does not return a Client from this package, but a go-gitlab.Client to make it confusing

func OidForRef

func OidForRef(revision string) (string, error)

func RefForSymbolicRef

func RefForSymbolicRef(symbol string) (string, error)

RefForSymbolicRef returns the ref for the provided symbolic ref, typically HEAD.

func RemoteForHEAD

func RemoteForHEAD() (string, error)

RemoteForHEAD returns the short remote name for the current local branch.

func RemoteForRef

func RemoteForRef(ref string) (string, error)

RemoteForRef returns the short remote name for the local ref provided in the format of `refs/heads/feature-branch`.

func RevParseAbbrev

func RevParseAbbrev(rev string) (string, error)

func StreamIssues

func StreamIssues(project *Project, opts *IssuesStreamOpts, r IssuesReader, w IssuesWriter, progress chan int) (int, error)

func StreamProjects

func StreamProjects(host string, opts StreamProjectsOpts, projChan chan *gitlab.Project) error

Stream projects will list the projects from the GitLab API and stream these through the channel, allowing for pagination request not slowing down the data processing pipeline

func SummarizeCommitStatuses

func SummarizeCommitStatuses(statuses []*gitlab.CommitStatus) (s string)

func SummarizeJobsByStage

func SummarizeJobsByStage(jobs []*g.Job) map[string]string

func UrlForRemote

func UrlForRemote(remote string) (string, error)

Types

type Client

type Client struct {
	Host *Host
}

type Commit

type Commit struct {
	gitlab.Commit
	RetrievedAt *time.Time `json:"retrieved_at"`
}

type CommitReader

type CommitReader interface {
	GetCommit(*Project, int) (*Commit, error)
}

type Host

type Host struct {
	Host        string
	AccessToken string
}

type Issue

type Issue struct {
	gitlab.Issue
}

func (*Issue) Type

func (i *Issue) Type() string

type IssueReader

type IssueReader interface {
	GetIssue(p *Project, id int) (*Issue, error)
}

type IssueWriter

type IssueWriter interface {
	UpdateIssue(p *Project, i *Issue) error
}

type IssuesReader

type IssuesReader interface {
	GetIssuesStream(p *Project, opts *IssuesStreamOpts, readChan chan *Issue) error
	CountIssues(p *Project, opts *IssuesStreamOpts) int
}

type IssuesReaderWriter

type IssuesReaderWriter interface {
	IssuesWriter
	IssuesReader
}

type IssuesStreamOpts

type IssuesStreamOpts struct {
	UpdatedAfter *time.Time
}

type IssuesWriter

type IssuesWriter interface {
	UpdateIssuesStream(done chan struct{}, p *Project, writeWrite chan *Issue) error
}

type Job

type Job struct {
	ID         int
	Name       string
	Stage      string
	Status     string
	FinishedAt *time.Time
}

func FetchPipelineJobsByCommit

func FetchPipelineJobsByCommit(p *Project, r *Repository) ([]Job, error)

func ListPipelineJobs

func ListPipelineJobs(p *Project, ID int) ([]Job, error)

type Pipeline

type Pipeline struct {
	ID     int
	Status string
	URL    string
	Jobs   []*Job
	Stages []*PipelineStage
}

func FetchLastPipelineByCommit

func FetchLastPipelineByCommit(p *Project, r *Repository) (*Pipeline, error)

func FetchPipeline

func FetchPipeline(p *Project, ID int) (*Pipeline, error)

func (*Pipeline) FindJob

func (p *Pipeline) FindJob(name string) *Job

type PipelineStage

type PipelineStage struct {
	Name   string
	Status string
	Jobs   []*Job
}

func (*PipelineStage) StatusDescription

func (s *PipelineStage) StatusDescription() string

type Project

type Project struct {
	Name        string
	Namespace   string
	Host        string
	AccessToken string
	// contains filtered or unexported fields
}

func NewProjectForRepository

func NewProjectForRepository(repo *Repository) (*Project, error)

func NewProjectFromContext

func NewProjectFromContext() (*Project, error)

func NewProjectFromOptions

func NewProjectFromOptions(host string, projectID string) (*Project, error)

Returns a new Project from the supplied host and project id. The project id must be a human readable string (gitlab-org/gitaly) to match the web url and clone url. WARNING: client will not be set! A refactor is coming!!!

func NewProjectFromRemote

func NewProjectFromRemote(remoteURL string) (*Project, error)

func NewProjectFromURL

func NewProjectFromURL(url *url.URL) (*Project, error)

func (*Project) FullPath

func (p *Project) FullPath() string

func (*Project) ID

func (p *Project) ID() string

Returns a string containing a project id that can be used for API requests.

type Repository

type Repository struct {
	Remote string
	Branch string
	HEAD   string

	*git.Repository
	// contains filtered or unexported fields
}

Repository allows for interaction with a Git repository. Retrieving data from the repository is done by shelling out to the `git` command. Which means `git` must be correctly installed and can be found in $PATH.

func NewRepository

func NewRepository(opts ...RepositoryOption) *Repository

NewRepository creates a Repository, without analyzing the context its being constructed in.

func (*Repository) Checkout

func (r *Repository) Checkout(ref string) error

Checkout

func (*Repository) ConfigGet

func (r *Repository) ConfigGet(option string) string

func (*Repository) ConfigGetAll

func (r *Repository) ConfigGetAll(option string) (lines []string)

func (*Repository) Fetch

func (r *Repository) Fetch(ref string) error

func (*Repository) GetProject

func (r *Repository) GetProject() (*Project, error)

GetProject will determine the GitLab project associated based on the current checkout. It does so by detecting the upstream tracking branch of the current HEAD. ErrNoUpstream will be returned as error, when there's no upstream set.

func (*Repository) RefExist

func (r *Repository) RefExist(ref string) bool

type RepositoryOption

type RepositoryOption func(*Repository)

func WithBranch

func WithBranch(ref string) RepositoryOption

WithBranch overrides the branch to be used, instead of loading from context It does not modify the local git repository

func WithHEAD

func WithHEAD(commitID string) RepositoryOption

WithHEAD overrides sets the value HEAD would dereference to, for the repository struct to the passed value It does not modify the git repository

func WithRemote

func WithRemote(remote string) RepositoryOption

WithRemote sets the remote to use for the requests to the name passed

type StreamProjectsOpts

type StreamProjectsOpts struct {
	Owned   *bool
	Starred *bool
}

type TraceReader

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

func NewTraceReader

func NewTraceReader(p *Project, ID int) *TraceReader

func (*TraceReader) Error

func (t *TraceReader) Error() string

func (*TraceReader) Read

func (t *TraceReader) Read(buffer []byte) (int, error)

Jump to

Keyboard shortcuts

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