Documentation
¶
Overview ¶
Package forge provides a platform-agnostic abstraction over git forges (GitLab, GitHub, Gitea/Forgejo). Every write operation (release creation, badge update, file commit, MR/PR creation) goes through this interface so StageFreight works identically regardless of where the repo is hosted.
Index ¶
- Variables
- func BaseURL(remoteURL string) string
- type APIError
- type Asset
- type CommitFileOptions
- type CommitFilesOptions
- type CommitResult
- type FileAction
- type Forge
- type GitHubForge
- func (g *GitHubForge) AddReleaseLink(ctx context.Context, releaseID string, link ReleaseLink) error
- func (g *GitHubForge) BranchHeadSHA(ctx context.Context, branch string) (string, error)
- func (g *GitHubForge) CancelPipeline(ctx context.Context, pipelineID string) error
- func (g *GitHubForge) CommitFile(ctx context.Context, opts CommitFileOptions) error
- func (g *GitHubForge) CommitFiles(ctx context.Context, opts CommitFilesOptions) (*CommitResult, error)
- func (g *GitHubForge) CreateMR(ctx context.Context, opts MROptions) (*MR, error)
- func (g *GitHubForge) CreateRelease(ctx context.Context, opts ReleaseOptions) (*Release, error)
- func (g *GitHubForge) CreateTag(ctx context.Context, tagName, ref string) error
- func (g *GitHubForge) DeleteRelease(ctx context.Context, tagName string) error
- func (g *GitHubForge) DeleteTag(ctx context.Context, tagName string) error
- func (g *GitHubForge) DownloadJobArtifact(ctx context.Context, ref, jobName, artifactPath string) ([]byte, error)
- func (g *GitHubForge) ListReleases(ctx context.Context) ([]ReleaseInfo, error)
- func (g *GitHubForge) Provider() Provider
- func (g *GitHubForge) UploadAsset(ctx context.Context, releaseID string, asset Asset) error
- type GitLabForge
- func (g *GitLabForge) AddReleaseLink(ctx context.Context, releaseID string, link ReleaseLink) error
- func (g *GitLabForge) BranchHeadSHA(ctx context.Context, branch string) (string, error)
- func (g *GitLabForge) CancelPipeline(ctx context.Context, pipelineID string) error
- func (g *GitLabForge) CommitFile(ctx context.Context, opts CommitFileOptions) error
- func (g *GitLabForge) CommitFiles(ctx context.Context, opts CommitFilesOptions) (*CommitResult, error)
- func (g *GitLabForge) CreateMR(ctx context.Context, opts MROptions) (*MR, error)
- func (g *GitLabForge) CreateRelease(ctx context.Context, opts ReleaseOptions) (*Release, error)
- func (g *GitLabForge) CreateTag(ctx context.Context, tagName, ref string) error
- func (g *GitLabForge) DeleteRelease(ctx context.Context, tagName string) error
- func (g *GitLabForge) DeleteTag(ctx context.Context, tagName string) error
- func (g *GitLabForge) DownloadJobArtifact(ctx context.Context, ref, jobName, artifactPath string) ([]byte, error)
- func (g *GitLabForge) ListReleases(ctx context.Context) ([]ReleaseInfo, error)
- func (g *GitLabForge) Provider() Provider
- func (g *GitLabForge) UploadAsset(ctx context.Context, releaseID string, asset Asset) error
- type GiteaForge
- func (g *GiteaForge) AddReleaseLink(ctx context.Context, releaseID string, link ReleaseLink) error
- func (g *GiteaForge) BranchHeadSHA(ctx context.Context, branch string) (string, error)
- func (g *GiteaForge) CancelPipeline(ctx context.Context, pipelineID string) error
- func (g *GiteaForge) CommitFile(ctx context.Context, opts CommitFileOptions) error
- func (g *GiteaForge) CommitFiles(ctx context.Context, opts CommitFilesOptions) (*CommitResult, error)
- func (g *GiteaForge) CreateMR(ctx context.Context, opts MROptions) (*MR, error)
- func (g *GiteaForge) CreateRelease(ctx context.Context, opts ReleaseOptions) (*Release, error)
- func (g *GiteaForge) CreateTag(ctx context.Context, tagName, ref string) error
- func (g *GiteaForge) DeleteRelease(ctx context.Context, tagName string) error
- func (g *GiteaForge) DeleteTag(ctx context.Context, tagName string) error
- func (g *GiteaForge) DownloadJobArtifact(ctx context.Context, ref, jobName, artifactPath string) ([]byte, error)
- func (g *GiteaForge) ListReleases(ctx context.Context) ([]ReleaseInfo, error)
- func (g *GiteaForge) Provider() Provider
- func (g *GiteaForge) UploadAsset(ctx context.Context, releaseID string, asset Asset) error
- type MR
- type MROptions
- type Provider
- type Release
- type ReleaseInfo
- type ReleaseLink
- type ReleaseOptions
Constants ¶
This section is empty.
Variables ¶
var ErrBranchMoved = errors.New("target branch moved during commit")
ErrBranchMoved is returned when the target branch has moved since the expected SHA.
var ErrNotSupported = errors.New("operation not supported by this forge")
ErrNotSupported is returned when a forge does not support a particular operation.
Functions ¶
func BaseURL ¶
BaseURL extracts the forge base URL from a git remote URL. Handles SSH (git@host:path) and HTTPS (https://host/path) formats.
Types ¶
type Asset ¶
type Asset struct {
Name string // display name
FilePath string // local file to upload
MIMEType string // e.g., "application/json"
}
Asset is a file to attach to a release.
type CommitFileOptions ¶
type CommitFileOptions struct {
Branch string
Path string // file path in repo
Content []byte
Message string
}
CommitFileOptions configures a file commit via forge API.
type CommitFilesOptions ¶
type CommitFilesOptions struct {
Branch string
Message string
Files []FileAction
ExpectedSHA string // optional: fail if branch head != this SHA
}
CommitFilesOptions configures a multi-file atomic commit via forge API.
type CommitResult ¶
type CommitResult struct {
SHA string
}
CommitResult holds the result of a forge commit operation.
type FileAction ¶
type FileAction struct {
Path string
Content []byte // nil for deletes
Delete bool // true = delete this file
}
FileAction describes a single file operation within a multi-file commit.
type Forge ¶
type Forge interface {
// Provider returns which platform this forge represents.
Provider() Provider
// CreateRelease creates a release/tag on the forge.
CreateRelease(ctx context.Context, opts ReleaseOptions) (*Release, error)
// UploadAsset attaches a file to an existing release.
UploadAsset(ctx context.Context, releaseID string, asset Asset) error
// AddReleaseLink adds a URL link to a release (e.g., registry image links).
AddReleaseLink(ctx context.Context, releaseID string, link ReleaseLink) error
// CommitFile creates or updates a file in the repo via the forge API.
// Used for badge SVG updates without a local clone.
CommitFile(ctx context.Context, opts CommitFileOptions) error
// CommitFiles creates or updates multiple files in a single atomic commit
// via the forge API. Used by the commit subsystem for CI push.
CommitFiles(ctx context.Context, opts CommitFilesOptions) (*CommitResult, error)
// BranchHeadSHA returns the current HEAD SHA of a branch via the forge API.
BranchHeadSHA(ctx context.Context, branch string) (string, error)
// CreateMR opens a merge/pull request.
CreateMR(ctx context.Context, opts MROptions) (*MR, error)
// CancelPipeline cancels the currently running pipeline (best-effort cleanup
// after deps pushes a repaired commit). Returns nil if the provider doesn't
// support pipeline cancellation.
CancelPipeline(ctx context.Context, pipelineID string) error
// ListReleases returns all releases, newest first.
ListReleases(ctx context.Context) ([]ReleaseInfo, error)
// DeleteRelease removes a release by its tag name.
DeleteRelease(ctx context.Context, tagName string) error
// CreateTag creates a lightweight git tag pointing at a ref.
// Used for rolling tag aliases (e.g., "latest") that are not releases.
CreateTag(ctx context.Context, tagName, ref string) error
// DeleteTag deletes a git tag.
DeleteTag(ctx context.Context, tagName string) error
// DownloadJobArtifact fetches a single file from the latest successful job's
// artifacts for the given ref. Returns the raw file bytes.
// Returns os.ErrNotExist (or equivalent) if no artifacts found.
// Implementations may return ErrNotSupported if the forge doesn't support this.
DownloadJobArtifact(ctx context.Context, ref, jobName, artifactPath string) ([]byte, error)
}
Forge is the interface every platform implements.
type GitHubForge ¶
type GitHubForge struct {
BaseURL string // "https://api.github.com" or "https://ghes.example.com/api/v3"
Token string
Owner string
Repo string
}
GitHubForge implements the Forge interface for GitHub and GitHub Enterprise.
func NewGitHub ¶
func NewGitHub(baseURL string) *GitHubForge
NewGitHub creates a GitHub forge client. Token is resolved from env: GITHUB_TOKEN, GH_TOKEN. Owner/Repo is resolved from env: GITHUB_REPOSITORY (owner/repo).
func (*GitHubForge) AddReleaseLink ¶
func (g *GitHubForge) AddReleaseLink(ctx context.Context, releaseID string, link ReleaseLink) error
func (*GitHubForge) BranchHeadSHA ¶
func (*GitHubForge) CancelPipeline ¶
func (g *GitHubForge) CancelPipeline(ctx context.Context, pipelineID string) error
func (*GitHubForge) CommitFile ¶
func (g *GitHubForge) CommitFile(ctx context.Context, opts CommitFileOptions) error
func (*GitHubForge) CommitFiles ¶
func (g *GitHubForge) CommitFiles(ctx context.Context, opts CommitFilesOptions) (*CommitResult, error)
func (*GitHubForge) CreateRelease ¶
func (g *GitHubForge) CreateRelease(ctx context.Context, opts ReleaseOptions) (*Release, error)
func (*GitHubForge) CreateTag ¶ added in v0.3.2
func (g *GitHubForge) CreateTag(ctx context.Context, tagName, ref string) error
func (*GitHubForge) DeleteRelease ¶
func (g *GitHubForge) DeleteRelease(ctx context.Context, tagName string) error
func (*GitHubForge) DeleteTag ¶ added in v0.3.2
func (g *GitHubForge) DeleteTag(ctx context.Context, tagName string) error
func (*GitHubForge) DownloadJobArtifact ¶
func (*GitHubForge) ListReleases ¶
func (g *GitHubForge) ListReleases(ctx context.Context) ([]ReleaseInfo, error)
func (*GitHubForge) Provider ¶
func (g *GitHubForge) Provider() Provider
func (*GitHubForge) UploadAsset ¶
type GitLabForge ¶
type GitLabForge struct {
BaseURL string // e.g., "https://gitlab.prplanit.com"
Token string // private token or job token
ProjectID string // numeric ID or "group/project" URL-encoded path
// contains filtered or unexported fields
}
GitLabForge implements the Forge interface for GitLab instances.
func NewGitLab ¶
func NewGitLab(baseURL string) *GitLabForge
NewGitLab creates a GitLab forge client. Token is resolved from env: GITLAB_TOKEN, CI_JOB_TOKEN. ProjectID is resolved from env: CI_PROJECT_ID, CI_PROJECT_PATH.
func (*GitLabForge) AddReleaseLink ¶
func (g *GitLabForge) AddReleaseLink(ctx context.Context, releaseID string, link ReleaseLink) error
func (*GitLabForge) BranchHeadSHA ¶
func (*GitLabForge) CancelPipeline ¶
func (g *GitLabForge) CancelPipeline(ctx context.Context, pipelineID string) error
func (*GitLabForge) CommitFile ¶
func (g *GitLabForge) CommitFile(ctx context.Context, opts CommitFileOptions) error
func (*GitLabForge) CommitFiles ¶
func (g *GitLabForge) CommitFiles(ctx context.Context, opts CommitFilesOptions) (*CommitResult, error)
func (*GitLabForge) CreateRelease ¶
func (g *GitLabForge) CreateRelease(ctx context.Context, opts ReleaseOptions) (*Release, error)
func (*GitLabForge) CreateTag ¶ added in v0.3.2
func (g *GitLabForge) CreateTag(ctx context.Context, tagName, ref string) error
func (*GitLabForge) DeleteRelease ¶
func (g *GitLabForge) DeleteRelease(ctx context.Context, tagName string) error
func (*GitLabForge) DeleteTag ¶ added in v0.3.2
func (g *GitLabForge) DeleteTag(ctx context.Context, tagName string) error
func (*GitLabForge) DownloadJobArtifact ¶
func (*GitLabForge) ListReleases ¶
func (g *GitLabForge) ListReleases(ctx context.Context) ([]ReleaseInfo, error)
func (*GitLabForge) Provider ¶
func (g *GitLabForge) Provider() Provider
func (*GitLabForge) UploadAsset ¶
type GiteaForge ¶
type GiteaForge struct {
BaseURL string // e.g., "https://codeberg.org"
Token string
Owner string
Repo string
}
GiteaForge implements the Forge interface for Gitea and Forgejo instances.
func NewGitea ¶
func NewGitea(baseURL string) *GiteaForge
NewGitea creates a Gitea/Forgejo forge client. Token is resolved from env: GITEA_TOKEN, FORGEJO_TOKEN. Owner/Repo is resolved from env: CI_REPO (Woodpecker CI) or GITHUB_REPOSITORY (Gitea Actions, which uses GitHub-compatible vars).
func (*GiteaForge) AddReleaseLink ¶
func (g *GiteaForge) AddReleaseLink(ctx context.Context, releaseID string, link ReleaseLink) error
func (*GiteaForge) BranchHeadSHA ¶
func (*GiteaForge) CancelPipeline ¶
func (g *GiteaForge) CancelPipeline(ctx context.Context, pipelineID string) error
func (*GiteaForge) CommitFile ¶
func (g *GiteaForge) CommitFile(ctx context.Context, opts CommitFileOptions) error
func (*GiteaForge) CommitFiles ¶
func (g *GiteaForge) CommitFiles(ctx context.Context, opts CommitFilesOptions) (*CommitResult, error)
func (*GiteaForge) CreateRelease ¶
func (g *GiteaForge) CreateRelease(ctx context.Context, opts ReleaseOptions) (*Release, error)
func (*GiteaForge) CreateTag ¶ added in v0.3.2
func (g *GiteaForge) CreateTag(ctx context.Context, tagName, ref string) error
func (*GiteaForge) DeleteRelease ¶
func (g *GiteaForge) DeleteRelease(ctx context.Context, tagName string) error
func (*GiteaForge) DeleteTag ¶ added in v0.3.2
func (g *GiteaForge) DeleteTag(ctx context.Context, tagName string) error
func (*GiteaForge) DownloadJobArtifact ¶
func (*GiteaForge) ListReleases ¶
func (g *GiteaForge) ListReleases(ctx context.Context) ([]ReleaseInfo, error)
func (*GiteaForge) Provider ¶
func (g *GiteaForge) Provider() Provider
func (*GiteaForge) UploadAsset ¶
type MROptions ¶
type MROptions struct {
Title string
Description string
SourceBranch string
TargetBranch string
Draft bool
}
MROptions configures a merge/pull request.
type Provider ¶
type Provider string
Provider identifies a git forge platform.
func DetectProvider ¶
DetectProvider determines the forge platform from a git remote URL.
type ReleaseInfo ¶
type ReleaseInfo struct {
ID string // platform-specific ID (numeric for GitHub/Gitea, tag_name for GitLab)
TagName string
CreatedAt time.Time
}
ReleaseInfo describes an existing release on a forge.
type ReleaseLink ¶
type ReleaseLink struct {
Name string // display name (e.g., "Docker Hub 1.3.0")
URL string // target URL
LinkType string // "image", "package", "other"
}
ReleaseLink is a URL to embed in a release (e.g., registry image link).
type ReleaseOptions ¶
type ReleaseOptions struct {
TagName string
Ref string // commit SHA, branch, or tag to create the release from (required by GitLab when tag doesn't exist)
Name string
Description string // markdown body (release notes)
Draft bool
Prerelease bool
}
ReleaseOptions configures a new release.