vcs

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PipelineSourceMergeRequestEvent is the GitLab pipeline source for pipelines
	// created by a merge request.
	PipelineSourceMergeRequestEvent = "merge_request_event"
	// PipelineSourceExternal is the GitLab pipeline source for pipelines created
	// implicitly by the commit status API. TFBuddy produces these whenever it
	// posts a status without a pipeline ID to attach it to.
	PipelineSourceExternal = "external"
	// CommitStatusPrefix prefixes every commit status TFBuddy publishes, which is
	// how TFBuddy's own statuses are told apart from a project's CI jobs.
	CommitStatusPrefix = "TFC/"
)

Variables

This section is empty.

Functions

func DescribePipeline added in v0.6.0

func DescribePipeline(p ProjectPipeline) string

DescribePipeline renders a pipeline for a merge request comment, as a markdown link when GitLab supplied a URL and as plain text when it did not.

func IsGlobalAutoMergeEnabled added in v0.3.0

func IsGlobalAutoMergeEnabled(cfg config.Config) bool

func IsTFBuddyCommitStatus added in v0.6.0

func IsTFBuddyCommitStatus(s CommitJobStatus) bool

IsTFBuddyCommitStatus reports whether a commit status was published by TFBuddy rather than by the project's CI.

Types

type Commit

type Commit interface {
	GetSHA() string
}

type CommitJobStatus added in v0.6.0

type CommitJobStatus interface {
	GetName() string
	GetStatus() string
	GetPipelineID() int
	GetAllowFailure() bool
}

CommitJobStatus is a single entry in a commit's status list: either a real CI job or an external status posted through the commit status API (which is how TFBuddy publishes its own TFC/* statuses).

type CommitState added in v0.8.0

type CommitState string

CommitState is the provider-agnostic state of a TFBuddy commit status. GitLab maps these onto gogitlab.BuildStateValue. The set is deliberately limited to the values GitLab's commit status API accepts:

values: %w[pending running success failed canceled skipped]
const (
	CommitStatePending  CommitState = "pending"
	CommitStateRunning  CommitState = "running"
	CommitStateSuccess  CommitState = "success"
	CommitStateFailed   CommitState = "failed"
	CommitStateCanceled CommitState = "canceled"
	CommitStateSkipped  CommitState = "skipped"
)

type CommitStatus

type CommitStatus interface {
	Info() string
}

type CommitStatusOptions

type CommitStatusOptions interface {
	GetName() string
	GetContext() string
	GetTargetURL() string
	GetDescription() string
	GetState() string
	GetPipelineID() int
}

type DetailedMR

type DetailedMR interface {
	HasConflicts() bool
	// IsDraft reports whether the merge request is a Draft, which GitLab and
	// GitHub both refuse to merge.
	IsDraft() bool
	MR
	GetWebURL() string
	GetTitle() string
	GetState() string
}

type GitClient

type GitClient interface {
	SupportsAggregateAutoMerge() bool
	GetAuthenticatedAccountName(ctx context.Context) (string, error)
	GetMergeRequestApprovals(ctx context.Context, id int, project string) (MRApproved, error)
	CreateMergeRequestComment(ctx context.Context, id int, fullPath string, comment string) error
	CreateMergeRequestCommentWithID(ctx context.Context, id int, fullPath string, comment string) (int64, error)
	UpdateMergeRequestComment(ctx context.Context, id int, noteID int64, fullPath string, comment string) error
	CreateMergeRequestDiscussion(ctx context.Context, mrID int, fullPath string, comment string) (MRDiscussionNotes, error)
	GetMergeRequest(context.Context, int, string) (DetailedMR, error)
	GetRepoFile(context.Context, string, string, string) ([]byte, error)
	// ListRepoDirectories returns every directory below dir at ref, recursively,
	// as paths relative to the repo root. A dir that does not exist at ref yields
	// no paths rather than an error.
	ListRepoDirectories(ctx context.Context, project, dir, ref string) ([]string, error)
	GetMergeRequestModifiedFiles(ctx context.Context, mrIID int, projectID string) ([]string, error)
	CloneMergeRequest(context.Context, string, MR, string) (GitRepo, error)
	UpdateMergeRequestDiscussionNote(ctx context.Context, mrIID, noteID int, project, discussionID, comment string) (MRNote, error)
	ResolveMergeRequestDiscussion(context.Context, string, int, string) error
	ResolveMergeRequestDiscussions(ctx context.Context, project string, mrIID int, workspace, action string) error
	AddMergeRequestDiscussionReply(ctx context.Context, mrIID int, project, discussionID, comment string) (MRNote, error)
	SetCommitStatus(ctx context.Context, projectWithNS string, commitSHA string, status CommitStatusOptions) (CommitStatus, error)
	SetWorkspaceStatus(ctx context.Context, status WorkspaceStatus) error
	GetPipelinesForCommit(ctx context.Context, projectWithNS string, commitSHA string) ([]ProjectPipeline, error)
	GetCommitJobStatuses(ctx context.Context, projectWithNS string, commitSHA string) ([]CommitJobStatus, error)
	GetProjectSettings(ctx context.Context, projectWithNS string) (ProjectSettings, error)
	GetOldRunUrls(ctx context.Context, mrIID int, project string, rootCommentID int, workspace string, action string) (string, error)
	MergeMR(ctx context.Context, mrIID int, project string) error
	MergeMRAtSHA(ctx context.Context, mrIID int, project, expectedSHA string) error
}

type GitRepo

type GitRepo interface {
	FetchUpstreamBranch(string) error
	GetMergeBase(oldest, newest string) (string, error)
	GetModifiedFileNamesBetweenCommits(oldest, newest string) ([]string, error)
	GetLocalDirectory() string
}

type MR

type MR interface {
	MRBranches
	GetAuthor() MRAuthor
	GetInternalID() int
}

type MRApproved

type MRApproved interface {
	IsApproved() bool
}

type MRAttributes

type MRAttributes interface {
	GetNote() string
	GetType() string
	MRDiscussion
}

type MRAuthor

type MRAuthor interface {
	GetUsername() string
}

type MRBranches

type MRBranches interface {
	GetSourceBranch() string
	GetTargetBranch() string
}

type MRCommentEvent

type MRCommentEvent interface {
	GetProject() Project
	GetMR() MR
	GetAttributes() MRAttributes
	GetLastCommit() Commit
}

type MRDiscussion

type MRDiscussion interface {
	GetDiscussionID() string
}

type MRDiscussionNotes

type MRDiscussionNotes interface {
	GetMRNotes() []MRNote
	MRDiscussion
}

type MRNote

type MRNote interface {
	GetNoteID() int64
}

type Project

type Project interface {
	GetPathWithNamespace() string
}

type ProjectPipeline

type ProjectPipeline interface {
	GetSource() string
	GetID() int
	GetStatus() string
	// GetWebURL returns the pipeline's browser URL, which may be empty.
	GetWebURL() string
}

func SelectPipelineForCommit added in v0.6.0

func SelectPipelineForCommit(pipelines []ProjectPipeline) ProjectPipeline

SelectPipelineForCommit returns the pipeline that represents CI for a commit: the merge request pipeline when the commit has one, otherwise the newest pipeline. It returns nil for an empty list.

GitLab lists pipelines newest first (order_by=id, sort=desc by default), so the fallback is the head of the list.

type ProjectSettings added in v0.6.0

type ProjectSettings interface {
	OnlyAllowMergeIfPipelineSucceeds() bool
}

ProjectSettings exposes the repository settings TFBuddy reads to decide how strict to be, rather than duplicating them in TFBuddy's own configuration.

type WorkspaceStatus added in v0.8.0

type WorkspaceStatus struct {
	Project         string // path with namespace
	CommitSHA       string
	MergeRequestIID int
	Workspace       string
	Action          string // "plan" or "apply"
	State           CommitState
	Description     string // optional; falls back to a per-state default
	TargetURL       string // optional; the TFC run URL once one exists
}

WorkspaceStatus is one TFC/<action>/<workspace> commit status. It carries everything a VCS needs to place the status on the right pipeline without exposing provider types to callers in pkg/tfc_trigger.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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