Documentation
¶
Overview ¶
Package gitoperationslib wraps git forge operations behind a common set of interfaces. Forgejo is the primary backend; GitHub is supported where the two APIs overlap.
Index ¶
- Variables
- func All[T any](ctx context.Context, opts ListOptions, ...) iter.Seq2[T, error]
- func IsForbidden(err error) bool
- func IsNotFound(err error) bool
- func IsUnauthorized(err error) bool
- func NotSupported(backend Backend, operation, reason string) error
- func Ptr[T any](v T) *T
- func StatusCode(err error) int
- type APIError
- type Admin
- type Allowlist
- type Asset
- type Backend
- type Branch
- type BranchProtection
- type BranchProtections
- type Branches
- type Capability
- type Client
- type Comment
- type CreateBranchOptions
- type CreateIssueOptions
- type CreateMilestoneOptions
- type CreateOrgOptions
- type CreatePROptions
- type CreateReleaseOptions
- type CreateRepoOptions
- type CreateReviewOptions
- type CreateTagOptions
- type CreateTeamOptions
- type CreateUserOptions
- type CreateWebhookOptions
- type DeleteUserOptions
- type EditAssetOptions
- type EditIssueOptions
- type EditLabelOptions
- type EditMilestoneOptions
- type EditOrgOptions
- type EditPROptions
- type EditReleaseOptions
- type EditRepoOptions
- type EditTeamOptions
- type EditUserOptions
- type EditWebhookOptions
- type ExternalAssets
- type HookContentType
- type HookEvent
- type HookScope
- type Issue
- type IssueState
- type Issues
- type Label
- type Labels
- type ListIssuesOptions
- type ListOptions
- type ListPROptions
- type MergeMethod
- type MergeOptions
- type Milestone
- type MilestoneState
- type Milestones
- type NotSupportedError
- type Org
- type Orgs
- type OwnerVisibility
- type PRBranch
- type PRState
- type Page
- type PullRequest
- type PullRequests
- type Release
- type Releases
- type Repo
- type Repos
- type Review
- type ReviewEvent
- type ReviewState
- type Tag
- type TagProtection
- type TagProtections
- type Tags
- type Team
- type TeamAccess
- type TeamPermission
- type TeamUnit
- type Teams
- type UnsupportedVersionError
- type User
- type Users
- type Visibility
- type Webhook
- type Webhooks
Constants ¶
This section is empty.
Variables ¶
var AllTeamUnits = []TeamUnit{ TeamUnitCode, TeamUnitIssues, TeamUnitExternalIssues, TeamUnitWiki, TeamUnitExternalWiki, TeamUnitPulls, TeamUnitReleases, TeamUnitProjects, TeamUnitPackages, TeamUnitActions, }
AllTeamUnits lists every TeamUnit.
var ErrNotSupported = errors.New("operation not supported")
ErrNotSupported is matched (via errors.Is) by every error returned when a backend cannot perform an operation, instead of silently degrading.
var ErrOwnerTeam = errors.New("refusing to delete, rename or change the permissions of an owner team")
ErrOwnerTeam is returned when an operation would delete an organisation's owner team, rename it, or change its permissions. Forgejo allows deleting it, which leaves the organisation without owners.
Functions ¶
func All ¶
func All[T any](ctx context.Context, opts ListOptions, fetch func(context.Context, ListOptions) (Page[T], error)) iter.Seq2[T, error]
All iterates over every item of a paginated list, starting at opts.Page. Iteration stops at the first error, which is yielded with a zero item.
for repo, err := range gitoperationslib.All(ctx, opts, func(ctx context.Context, o gitoperationslib.ListOptions) (gitoperationslib.Page[gitoperationslib.Repo], error) {
return client.Repos().List(ctx, "owner", o)
}) { ... }
func IsForbidden ¶
func IsNotFound ¶
func IsUnauthorized ¶
func NotSupported ¶
NotSupported returns a *NotSupportedError.
func StatusCode ¶
StatusCode returns the HTTP status of the first *APIError in err's chain, or 0 if there is none.
Types ¶
type APIError ¶
type APIError struct {
Backend Backend
StatusCode int
Message string
// DocumentationURL is GitHub's documentation_url or Forgejo's url field.
DocumentationURL string
// Details holds GitHub's errors[] entries, flattened to strings.
Details []string
}
APIError is the normalised form of an error response from either backend.
type Admin ¶
Admin manages accounts. Only the Forgejo backend implements it; detect it with a type assertion (client.(gitoperationslib.Admin)) or CapAdmin.
type Allowlist ¶
type Allowlist struct {
Users []string // logins
Teams []string // team names (GitHub: team slugs; organisations only)
}
Allowlist names users and teams exempt from a restriction. On GitHub, rules are rulesets whose exemptions ("bypass actors") can be teams but not individual users, so Users returns ErrNotSupported there.
type Asset ¶
type Asset struct {
ID int64
Name string
Size int64
ContentType string // reported by GitHub only
DownloadCount int64
DownloadURL string // browser download URL
// External marks a Forgejo asset that links to a file hosted elsewhere
// (DownloadURL) instead of an uploaded file.
External bool
CreatedAt time.Time
}
Asset is a file attached to a release.
type BranchProtection ¶
type BranchProtection struct {
ID int64 // GitHub ruleset ID; 0 on Forgejo
// Pattern is a branch name or glob ("main", "release/*"). Rules are
// addressed by it.
Pattern string
RequiredApprovals int
DismissStaleApprovals bool // a new push dismisses earlier approvals
// RequiredStatusChecks lists the status check contexts that must pass.
RequiredStatusChecks []string
// RequireUpToDate requires the branch to be up to date with the base
// before merging (GitHub strict checks; Forgejo blocks outdated
// branches).
RequireUpToDate bool
RequireSignedCommits bool
// ApplyToAdmins enforces the rule for repository administrators too.
ApplyToAdmins bool
// PushAllowlist restricts direct pushes to the listed users and teams;
// nil lets anyone with write access push. An empty Allowlist blocks
// direct pushes entirely (changes then go through pull requests).
PushAllowlist *Allowlist
AllowDeletion bool // Forgejo: not supported (protected branches cannot be deleted)
AllowForcePush bool // Forgejo: not supported
// GitHub only.
RequireLinearHistory bool
RequireConversationResolution bool
// Forgejo only.
MergeAllowlist *Allowlist // who may merge pull requests; nil: anyone with write access
ApprovalsAllowlist *Allowlist // whose approvals count; nil: anyone with write access
BlockOnRejectedReviews bool
BlockOnOfficialReviewRequests bool
ProtectedFilePatterns string // semicolon-separated globs
UnprotectedFilePatterns string
}
BranchProtection is a protection rule for the branches matching Pattern. On GitHub it is a branch ruleset; on Forgejo a branch protection rule.
Zero values are the protected choice: deletion and force pushes are blocked unless explicitly allowed.
type BranchProtections ¶
type BranchProtections interface {
List(ctx context.Context, owner, repo string) ([]BranchProtection, error)
Get(ctx context.Context, owner, repo, pattern string) (*BranchProtection, error)
Create(ctx context.Context, owner, repo string, rule BranchProtection) (*BranchProtection, error)
Update(ctx context.Context, owner, repo, pattern string, rule BranchProtection) (*BranchProtection, error)
Delete(ctx context.Context, owner, repo, pattern string) error
}
BranchProtections manages branch protection rules, addressed by pattern. Update replaces a rule entirely: Get it, change it, then Update.
type Branches ¶
type Branches interface {
// List returns the branches; IsDefault marks the default one.
List(ctx context.Context, owner, repo string, opts ListOptions) (Page[Branch], error)
Get(ctx context.Context, owner, repo, name string) (*Branch, error)
Create(ctx context.Context, owner, repo string, opts CreateBranchOptions) (*Branch, error)
// Rename renames a branch. Open pull requests and protection rules
// follow it.
Rename(ctx context.Context, owner, repo, name, newName string) (*Branch, error)
Delete(ctx context.Context, owner, repo, name string) error
}
Branches manages repository branches. The default branch is changed with Repos().Edit.
type Capability ¶
type Capability uint64
Capability is a bit set of features a Client supports.
const ( CapRepos Capability = 1 << iota CapMirrors CapMigrate CapAdmin CapWebhooks CapSystemWebhooks CapReleases CapPullRequests CapExternalAssets CapBranches CapTags CapBranchProtection CapTagProtection CapIssues )
func (Capability) Has ¶
func (c Capability) Has(want Capability) bool
Has reports whether c includes every capability in want.
func (Capability) String ¶
func (c Capability) String() string
String lists the named capabilities in c, separated by "|".
type Client ¶
type Client interface {
Backend() Backend
Capabilities() Capability
Repos() Repos
Releases() Releases
PullRequests() PullRequests
Webhooks() Webhooks
Branches() Branches
Tags() Tags
BranchProtections() BranchProtections
TagProtections() TagProtections
Issues() Issues
Labels() Labels
Milestones() Milestones
}
Client is the entry point to a forge backend.
Areas a backend may not support are exposed through optional interfaces; check Capabilities, or use a type assertion, before relying on them.
type Comment ¶
type Comment struct {
ID int64
Author string
Body string
HTMLURL string
CreatedAt time.Time
UpdatedAt time.Time
}
Comment is a comment on an issue or pull request.
type CreateBranchOptions ¶
type CreateBranchOptions struct {
Name string // required
// From is the branch, tag or commit SHA to start from; empty means the
// default branch.
From string
}
CreateBranchOptions describes a branch to create.
type CreateIssueOptions ¶
type CreateIssueOptions struct {
Title string // required
Body string
Labels []string // names; they must exist
Assignees []string
Milestone int64 // Milestone.ID; 0 for none
}
CreateIssueOptions describes an issue to open.
type CreateMilestoneOptions ¶
type CreateMilestoneOptions struct {
Title string // required
Description string
DueOn time.Time // zero: none
}
CreateMilestoneOptions describes a milestone to create.
type CreateOrgOptions ¶
type CreateOrgOptions struct {
// Owner is the user who will own the organisation. Empty means the
// authenticated user; another user requires a site-admin token.
Owner string
Name string // required
FullName string
Description string
Website string
Location string
Email string
Visibility OwnerVisibility // zero value: backend default
RepoAdminChangeTeamAccess bool
}
CreateOrgOptions describes an organisation to create.
type CreatePROptions ¶
type CreatePROptions struct {
Title string // required
Body string
Head string // branch with the changes; "user:branch" for a fork
Base string // branch to merge into
// Draft opens the pull request as a draft. On Forgejo this adds the
// "WIP: " prefix to Title unless it already has a draft prefix.
Draft bool
AllowMaintainerEdit *bool // let base maintainers push to the head branch
}
CreatePROptions describes a pull request to open.
type CreateReleaseOptions ¶
type CreateReleaseOptions struct {
TagName string // required
TargetCommitish string
Name string
Body string
Draft bool
Prerelease bool
// GenerateReleaseNotes asks the server to write the notes from merged
// pull requests (GitHub only).
GenerateReleaseNotes bool
// MakeLatest controls whether the release becomes the "latest" one;
// nil means the server decides (GitHub only).
MakeLatest *bool
// HideArchiveLinks hides the generated source archives (Forgejo only).
HideArchiveLinks *bool
}
CreateReleaseOptions describes a release to create.
If TagName does not exist yet, it is created from TargetCommitish (the default branch when empty). For a draft, both backends create the tag only when the draft is published.
type CreateRepoOptions ¶
type CreateRepoOptions struct {
// Owner is the user or organisation that will own the repository; the
// backend determines which. Empty means the authenticated user. Naming a
// user other than the authenticated one requires an admin token (Forgejo)
// and is not supported on GitHub.
Owner string
Name string
Description string
Visibility Visibility // zero value: backend default
DefaultBranch string
Template bool
// AutoInit creates an initial commit, using Gitignores and License if set.
AutoInit bool
// Gitignores lists gitignore template names. GitHub accepts at most one
// and returns ErrNotSupported otherwise.
Gitignores []string
License string // license template name
}
CreateRepoOptions describes a repository to create.
type CreateReviewOptions ¶
type CreateReviewOptions struct {
Event ReviewEvent // required
Body string // required for request_changes and comment
CommitID string // empty: the current head
}
CreateReviewOptions submits a review. Authors cannot approve or request changes on their own pull requests.
type CreateTagOptions ¶
type CreateTagOptions struct {
Name string // required
// Target is the branch, tag or commit SHA to tag; empty means the
// default branch.
Target string
// Message makes an annotated tag; empty makes a lightweight tag.
Message string
}
CreateTagOptions describes a tag to create. To publish a release for a tag, use Releases().Create, which also creates the tag when needed.
type CreateTeamOptions ¶
type CreateTeamOptions struct {
Name string // required
Description string
Access TeamAccess // required
IncludesAllRepos bool
CanCreateOrgRepo bool
}
CreateTeamOptions describes a team to create.
type CreateUserOptions ¶
type CreateUserOptions struct {
Login string // required
Email string // required
Password string
FullName string
// MustChangePassword forces a password change at first sign-in.
// Nil means the Forgejo default, which is true.
MustChangePassword *bool
Visibility OwnerVisibility // zero value: backend default
Restricted bool
// SendNotify emails the user about the new account.
SendNotify bool
}
CreateUserOptions describes a user account to create.
type CreateWebhookOptions ¶
type CreateWebhookOptions struct {
URL string // required
ContentType HookContentType // zero value: json
// Secret signs deliveries (see the webhook package). Strongly
// recommended.
Secret string
Events []HookEvent // required
Active *bool // nil: active
// BranchFilter limits push and branch events to matching branches, as a
// glob such as "{main,release/*}" (Forgejo only).
BranchFilter string
// AuthorizationHeader is sent with every delivery (Forgejo only).
AuthorizationHeader string
}
CreateWebhookOptions describes a webhook to create.
type DeleteUserOptions ¶
type DeleteUserOptions struct {
// Purge also deletes the user's repositories, organisation memberships
// and other content. Without it, deleting a user who still owns
// repositories fails.
Purge bool
}
DeleteUserOptions controls user deletion.
type EditAssetOptions ¶
type EditAssetOptions struct {
Name *string
}
EditAssetOptions changes an asset. Nil fields are left unchanged.
type EditIssueOptions ¶
type EditIssueOptions struct {
Title *string
Body *string
State *IssueState // close or reopen
Labels *[]string
Assignees *[]string
Milestone *int64 // 0 removes the milestone
}
EditIssueOptions changes an issue. Nil fields are left unchanged; non-nil slices replace the current values (an empty slice clears them).
type EditLabelOptions ¶
type EditLabelOptions struct {
Name *string // renames the label
Color *string
Description *string
}
EditLabelOptions changes a label. Nil fields are left unchanged.
type EditMilestoneOptions ¶
type EditMilestoneOptions struct {
Title *string
Description *string
State *MilestoneState // close or reopen
DueOn *time.Time
}
EditMilestoneOptions changes a milestone. Nil fields are left unchanged.
type EditOrgOptions ¶
type EditOrgOptions struct {
FullName *string
Description *string
Website *string
Location *string
Email *string
Visibility *OwnerVisibility
RepoAdminChangeTeamAccess *bool
}
EditOrgOptions changes an organisation. Nil fields are left unchanged.
type EditPROptions ¶
type EditPROptions struct {
Title *string
Body *string
Base *string
// State closes (PRStateClosed) or reopens (PRStateOpen) the pull request.
State *PRState
// Draft converts to or from a draft. Forgejo adds or removes the title
// prefix; GitHub uses its GraphQL API.
Draft *bool
AllowMaintainerEdit *bool
}
EditPROptions changes a pull request. Nil fields are left unchanged.
type EditReleaseOptions ¶
type EditReleaseOptions struct {
TagName *string
TargetCommitish *string
Name *string
Body *string
Draft *bool
Prerelease *bool
MakeLatest *bool // GitHub only
HideArchiveLinks *bool // Forgejo only
}
EditReleaseOptions changes a release. Nil fields are left unchanged. Setting Draft to false publishes a draft.
type EditRepoOptions ¶
type EditRepoOptions struct {
Name *string
Description *string
Website *string
Visibility *Visibility
DefaultBranch *string
Archived *bool
Template *bool
}
EditRepoOptions changes repository settings. Nil fields are left unchanged; use Ptr to set a value.
type EditTeamOptions ¶
type EditTeamOptions struct {
Name *string
Description *string
Access *TeamAccess
IncludesAllRepos *bool
CanCreateOrgRepo *bool
}
EditTeamOptions changes a team. Nil fields are left unchanged.
type EditUserOptions ¶
type EditUserOptions struct {
Email *string
FullName *string
Description *string
Website *string
Location *string
Password *string
MustChangePassword *bool
Visibility *OwnerVisibility
Admin *bool
Active *bool
ProhibitLogin *bool
Restricted *bool
AllowCreateOrganization *bool
MaxRepoCreation *int // -1 means the instance default
}
EditUserOptions changes a user account. Nil fields are left unchanged.
type EditWebhookOptions ¶
type EditWebhookOptions struct {
URL *string
ContentType *HookContentType
Secret *string
Events []HookEvent
Active *bool
BranchFilter *string // Forgejo only
AuthorizationHeader *string // Forgejo only
}
EditWebhookOptions changes a webhook. Nil fields are left unchanged; a non-nil Events replaces the subscription list.
type ExternalAssets ¶
type ExternalAssets interface {
AddExternalAsset(ctx context.Context, owner, repo string, releaseID int64, name, url string) (*Asset, error)
}
ExternalAssets adds release assets that link to files hosted elsewhere. Only the Forgejo backend implements it (CapExternalAssets), on the value returned by Releases():
ext, ok := client.Releases().(gitoperationslib.ExternalAssets)
type HookContentType ¶
type HookContentType string
HookContentType is the encoding of webhook payloads.
const ( HookContentJSON HookContentType = "json" HookContentForm HookContentType = "form" // payload=<json>, URL-encoded )
type HookEvent ¶
type HookEvent string
HookEvent is an event a webhook subscribes to. The constants use GitHub's names and are translated for Forgejo; other values are passed to the server unchanged, for backend-specific events.
const ( HookEventPush HookEvent = "push" HookEventCreate HookEvent = "create" // branch or tag created HookEventDelete HookEvent = "delete" // branch or tag deleted HookEventFork HookEvent = "fork" HookEventRelease HookEvent = "release" HookEventIssues HookEvent = "issues" HookEventIssueComment HookEvent = "issue_comment" HookEventPullRequest HookEvent = "pull_request" HookEventPullRequestReview HookEvent = "pull_request_review" HookEventRepository HookEvent = "repository" HookEventWiki HookEvent = "wiki" // GitHub: gollum )
type HookScope ¶
HookScope selects where webhooks live: a repository, or an organisation when Repo is empty.
type Issue ¶
type Issue struct {
Number int
Title string
Body string
State IssueState
Author string
Labels []string // names
Assignees []string // logins
Milestone *Milestone
Comments int
Locked bool
HTMLURL string
CreatedAt time.Time
UpdatedAt time.Time
ClosedAt time.Time
}
Issue is an issue. Issues and pull requests share one number sequence; label, assignee and milestone methods also work on pull requests.
type IssueState ¶
type IssueState string
IssueState is the state of an issue. IssueStateAll is only meaningful as a List filter.
const ( IssueStateOpen IssueState = "open" IssueStateClosed IssueState = "closed" IssueStateAll IssueState = "all" )
type Issues ¶
type Issues interface {
List(ctx context.Context, owner, repo string, opts ListIssuesOptions) (Page[Issue], error)
Get(ctx context.Context, owner, repo string, number int) (*Issue, error)
Create(ctx context.Context, owner, repo string, opts CreateIssueOptions) (*Issue, error)
Edit(ctx context.Context, owner, repo string, number int, opts EditIssueOptions) (*Issue, error)
// Delete removes an issue permanently (repository admins only; GitHub
// through GraphQL).
Delete(ctx context.Context, owner, repo string, number int) error
AddLabels(ctx context.Context, owner, repo string, number int, labels []string) error
RemoveLabel(ctx context.Context, owner, repo string, number int, label string) error
ListComments(ctx context.Context, owner, repo string, number int, opts ListOptions) (Page[Comment], error)
CreateComment(ctx context.Context, owner, repo string, number int, body string) (*Comment, error)
EditComment(ctx context.Context, owner, repo string, id int64, body string) (*Comment, error)
DeleteComment(ctx context.Context, owner, repo string, id int64) error
}
Issues manages issues and their comments. Label and comment methods also accept pull request numbers.
type Label ¶
type Label struct {
ID int64
Name string
Color string // six hex digits, lower case, without "#"
Description string
}
Label is a repository label.
type Labels ¶
type Labels interface {
List(ctx context.Context, owner, repo string, opts ListOptions) (Page[Label], error)
Get(ctx context.Context, owner, repo, name string) (*Label, error)
Create(ctx context.Context, owner, repo string, label Label) (*Label, error)
Edit(ctx context.Context, owner, repo, name string, opts EditLabelOptions) (*Label, error)
Delete(ctx context.Context, owner, repo, name string) error
}
Labels manages repository labels, addressed by name.
type ListIssuesOptions ¶
type ListIssuesOptions struct {
ListOptions
State IssueState // zero value: open
Labels []string // issues carrying all these labels
}
ListIssuesOptions selects issues to list. Pull requests are never included.
type ListOptions ¶
ListOptions selects one page of a list call. Zero values mean "first page" and "backend default page size".
type ListPROptions ¶
type ListPROptions struct {
ListOptions
State PRState // zero value: open
}
ListPROptions selects pull requests to list.
type MergeMethod ¶
type MergeMethod string
MergeMethod is the strategy used to merge a pull request. Values match Forgejo's "Do" field; the GitHub backend supports only MergeMethodMerge, MergeMethodSquash and MergeMethodRebase.
MergeMethodRebase replays the commits without a merge commit; MergeMethodRebaseMerge rebases and then adds a merge commit; MergeMethodManuallyMerged only marks a pull request whose commits are already in the base branch as merged.
const ( MergeMethodMerge MergeMethod = "merge" MergeMethodRebase MergeMethod = "rebase" MergeMethodRebaseMerge MergeMethod = "rebase-merge" MergeMethodSquash MergeMethod = "squash" MergeMethodFastForwardOnly MergeMethod = "fast-forward-only" MergeMethodManuallyMerged MergeMethod = "manually-merged" )
func (MergeMethod) Valid ¶
func (m MergeMethod) Valid() bool
Valid reports whether m is one of the named merge methods.
type MergeOptions ¶
type MergeOptions struct {
// Method defaults to MergeMethodMerge. GitHub supports only merge,
// squash and rebase.
Method MergeMethod
Title string // merge or squash commit title; empty: server default
Message string // commit message body; empty: server default
// HeadSHA makes the merge fail unless the head branch is still at this
// commit.
HeadSHA string
// DeleteBranch deletes the head branch after a successful merge.
DeleteBranch bool
// WhenChecksSucceed schedules the merge for when status checks pass;
// cancel it with CancelAutoMerge. GitHub (through GraphQL) accepts it
// only in repositories that allow auto-merge, while the pull request
// still waits for a required check, and not together with DeleteBranch.
WhenChecksSucceed bool
}
MergeOptions controls a merge.
type Milestone ¶
type Milestone struct {
// ID addresses the milestone: Forgejo's ID, GitHub's milestone number.
ID int64
Title string
Description string
State MilestoneState
DueOn time.Time // zero if none
OpenIssues int
ClosedIssues int
ClosedAt time.Time
}
Milestone is a repository milestone.
type MilestoneState ¶
type MilestoneState string
MilestoneState is the state of a milestone; MilestoneStateAll is only meaningful as a List filter.
const ( MilestoneStateOpen MilestoneState = "open" MilestoneStateClosed MilestoneState = "closed" MilestoneStateAll MilestoneState = "all" )
type Milestones ¶
type Milestones interface {
List(ctx context.Context, owner, repo string, state MilestoneState, opts ListOptions) (Page[Milestone], error)
Get(ctx context.Context, owner, repo string, id int64) (*Milestone, error)
Create(ctx context.Context, owner, repo string, opts CreateMilestoneOptions) (*Milestone, error)
Edit(ctx context.Context, owner, repo string, id int64, opts EditMilestoneOptions) (*Milestone, error)
Delete(ctx context.Context, owner, repo string, id int64) error
}
Milestones manages repository milestones, addressed by Milestone.ID.
type NotSupportedError ¶
NotSupportedError describes which operation a backend refused.
func (*NotSupportedError) Error ¶
func (e *NotSupportedError) Error() string
func (*NotSupportedError) Is ¶
func (e *NotSupportedError) Is(target error) bool
type Org ¶
type Org struct {
ID int64
Name string
FullName string
Description string
Website string
Location string
Email string
Visibility OwnerVisibility
// RepoAdminChangeTeamAccess lets repository admins change team access.
RepoAdminChangeTeamAccess bool
}
Org is an organisation.
type Orgs ¶
type Orgs interface {
Get(ctx context.Context, name string) (*Org, error)
// List returns the organisations user belongs to. Empty user means the
// authenticated user.
List(ctx context.Context, user string, opts ListOptions) (Page[Org], error)
// ListAll returns every organisation visible to the authenticated user
// (all of them for a site admin).
ListAll(ctx context.Context, opts ListOptions) (Page[Org], error)
Create(ctx context.Context, opts CreateOrgOptions) (*Org, error)
Edit(ctx context.Context, name string, opts EditOrgOptions) (*Org, error)
// Rename changes an organisation's name. The old name keeps redirecting
// to the new one.
Rename(ctx context.Context, name, newName string) error
// Delete removes an organisation. It fails while the organisation still
// owns repositories.
Delete(ctx context.Context, name string) error
Members(ctx context.Context, org string, opts ListOptions) (Page[User], error)
// IsMember reports whether user belongs to org. A user that does not
// exist is reported as not a member.
IsMember(ctx context.Context, org, user string) (bool, error)
// RemoveMember removes user from org and all its teams. Removing the last
// owner fails.
RemoveMember(ctx context.Context, org, user string) error
}
Orgs manages organisations and their membership. Members join an organisation through its teams; there is no direct "add member".
type OwnerVisibility ¶
type OwnerVisibility string
OwnerVisibility is the visibility of a user or organisation profile. The zero value means "use the backend default" in option structs.
const ( OwnerVisibilityPublic OwnerVisibility = "public" // OwnerVisibilityLimited is visible to signed-in users only. OwnerVisibilityLimited OwnerVisibility = "limited" OwnerVisibilityPrivate OwnerVisibility = "private" )
func (OwnerVisibility) Valid ¶
func (v OwnerVisibility) Valid() bool
Valid reports whether v is one of the named owner visibilities.
type PRBranch ¶
type PRBranch struct {
Ref string // branch name
SHA string
Repo string // "owner/name"; differs from the base repository for forks
}
PRBranch is one side of a pull request.
type PRState ¶
type PRState string
PRState is the state of a pull request. PRStateAll is only meaningful as a List filter.
type Page ¶
type Page[T any] struct { Items []T // NextPage is the page number to request next, or 0 if this is the last page. NextPage int }
Page is one page of results.
type PullRequest ¶
type PullRequest struct {
Number int
// Title is returned as the server stores it. On Forgejo a draft is a
// title starting with a work-in-progress prefix ("WIP:" or "[WIP]" by
// default), which therefore appears in Title.
Title string
Body string
State PRState
Draft bool
Author string
Head PRBranch
Base PRBranch
// Mergeable is nil while the server has not computed it yet (GitHub
// computes it in the background).
Mergeable *bool
Merged bool
MergedBy string
MergedAt time.Time
MergeCommitSHA string
HTMLURL string
CreatedAt time.Time
UpdatedAt time.Time
ClosedAt time.Time
}
PullRequest is a pull request.
type PullRequests ¶
type PullRequests interface {
List(ctx context.Context, owner, repo string, opts ListPROptions) (Page[PullRequest], error)
Get(ctx context.Context, owner, repo string, number int) (*PullRequest, error)
// Create opens a pull request. If the server does not honour Draft
// (Forgejo with custom work-in-progress prefixes), the pull request is
// returned together with an error matching ErrNotSupported.
Create(ctx context.Context, owner, repo string, opts CreatePROptions) (*PullRequest, error)
// Edit changes a pull request; see EditPROptions. A Draft change the
// server does not honour is reported as in Create.
Edit(ctx context.Context, owner, repo string, number int, opts EditPROptions) (*PullRequest, error)
// Merge merges a pull request. Drafts cannot be merged. With
// MergeOptions.WhenChecksSucceed the merge is scheduled instead.
Merge(ctx context.Context, owner, repo string, number int, opts MergeOptions) error
// CancelAutoMerge cancels a merge scheduled with WhenChecksSucceed.
CancelAutoMerge(ctx context.Context, owner, repo string, number int) error
IsMerged(ctx context.Context, owner, repo string, number int) (bool, error)
RequestReviewers(ctx context.Context, owner, repo string, number int, users, teams []string) error
RemoveReviewers(ctx context.Context, owner, repo string, number int, users, teams []string) error
ListReviews(ctx context.Context, owner, repo string, number int, opts ListOptions) (Page[Review], error)
CreateReview(ctx context.Context, owner, repo string, number int, opts CreateReviewOptions) (*Review, error)
}
PullRequests manages pull requests and their reviews.
type Release ¶
type Release struct {
ID int64
TagName string
TargetCommitish string // branch or commit the tag is created from
Name string // title
Body string // notes, Markdown
Draft bool
Prerelease bool
Author string // login
HTMLURL string
TarballURL string // source archives generated by the forge
ZipballURL string
CreatedAt time.Time
PublishedAt time.Time // zero for drafts
Assets []Asset
}
Release is a named, tagged point in a repository's history, with notes and attached files (assets).
type Releases ¶
type Releases interface {
List(ctx context.Context, owner, repo string, opts ListOptions) (Page[Release], error)
Get(ctx context.Context, owner, repo string, id int64) (*Release, error)
GetByTag(ctx context.Context, owner, repo, tag string) (*Release, error)
// Latest returns the most recent published release that is not a
// prerelease.
Latest(ctx context.Context, owner, repo string) (*Release, error)
Create(ctx context.Context, owner, repo string, opts CreateReleaseOptions) (*Release, error)
Edit(ctx context.Context, owner, repo string, id int64, opts EditReleaseOptions) (*Release, error)
// Delete removes a release. Its tag is kept.
Delete(ctx context.Context, owner, repo string, id int64) error
ListAssets(ctx context.Context, owner, repo string, releaseID int64, opts ListOptions) (Page[Asset], error)
GetAsset(ctx context.Context, owner, repo string, releaseID, assetID int64) (*Asset, error)
// UploadAsset streams size bytes from r as a new asset called name.
// size must be exact. An empty contentType is guessed from the name's
// extension, falling back to application/octet-stream.
UploadAsset(ctx context.Context, owner, repo string, releaseID int64, name string, r io.Reader, size int64, contentType string) (*Asset, error)
EditAsset(ctx context.Context, owner, repo string, releaseID, assetID int64, opts EditAssetOptions) (*Asset, error)
DeleteAsset(ctx context.Context, owner, repo string, releaseID, assetID int64) error
// DownloadAsset streams an uploaded asset's content; the caller must
// close it. External assets are not downloaded: fetch their DownloadURL.
DownloadAsset(ctx context.Context, owner, repo string, releaseID, assetID int64) (io.ReadCloser, error)
}
Releases manages releases and their assets.
Asset methods take the release ID as well as the asset ID: Forgejo needs both, GitHub ignores the release ID.
type Repo ¶
type Repo struct {
ID int64
Owner string
Name string
FullName string // "owner/name"
Description string
Website string // Forgejo "website", GitHub "homepage"
Visibility Visibility
DefaultBranch string
Fork bool
Mirror bool
Archived bool
Template bool
Empty bool // not reported by GitHub (always false there)
HTMLURL string
CloneURL string
SSHURL string
CreatedAt time.Time
UpdatedAt time.Time
}
Repo is a repository, modelled on the fields Forgejo and GitHub share.
type Repos ¶
type Repos interface {
Get(ctx context.Context, owner, name string) (*Repo, error)
// List returns repositories owned by owner (a user or organisation).
// Empty owner lists every repository the authenticated user can access,
// including those of organisations they belong to.
List(ctx context.Context, owner string, opts ListOptions) (Page[Repo], error)
Create(ctx context.Context, opts CreateRepoOptions) (*Repo, error)
Edit(ctx context.Context, owner, name string, opts EditRepoOptions) (*Repo, error)
Delete(ctx context.Context, owner, name string) error
}
Repos manages repositories.
type Review ¶
type Review struct {
ID int64
Reviewer string
State ReviewState
Body string
CommitID string
HTMLURL string
SubmittedAt time.Time
}
Review is a pull request review.
type ReviewEvent ¶
type ReviewEvent string
ReviewEvent is the verdict submitted with a review.
const ( ReviewEventApprove ReviewEvent = "approve" ReviewEventRequestChanges ReviewEvent = "request_changes" ReviewEventComment ReviewEvent = "comment" )
type ReviewState ¶
type ReviewState string
ReviewState is the outcome of a review.
const ( ReviewApproved ReviewState = "approved" ReviewChangesRequested ReviewState = "changes_requested" ReviewCommented ReviewState = "commented" ReviewPending ReviewState = "pending" // started, not submitted ReviewDismissed ReviewState = "dismissed" // GitHub ReviewRequested ReviewState = "requested" // Forgejo: review requested, not given )
type Tag ¶
type Tag struct {
Name string
SHA string // commit the tag points to (annotated tags are peeled)
// Message is the annotation of an annotated tag; empty for lightweight
// tags. GitHub reports it from Get only, not from List.
Message string
TarballURL string
ZipballURL string
}
Tag is a repository tag.
type TagProtection ¶
TagProtection restricts creating, updating and deleting the tags matching Pattern ("v*") to the users and teams in Allowlist. On GitHub it is a tag ruleset, and an empty Allowlist blocks everyone, administrators included. Forgejo requires at least one allowed user or team.
type TagProtections ¶
type TagProtections interface {
List(ctx context.Context, owner, repo string) ([]TagProtection, error)
Get(ctx context.Context, owner, repo, pattern string) (*TagProtection, error)
Create(ctx context.Context, owner, repo string, rule TagProtection) (*TagProtection, error)
Update(ctx context.Context, owner, repo, pattern string, rule TagProtection) (*TagProtection, error)
Delete(ctx context.Context, owner, repo, pattern string) error
}
TagProtections manages tag protection rules, addressed by pattern.
type Tags ¶
type Tags interface {
List(ctx context.Context, owner, repo string, opts ListOptions) (Page[Tag], error)
Get(ctx context.Context, owner, repo, name string) (*Tag, error)
Create(ctx context.Context, owner, repo string, opts CreateTagOptions) (*Tag, error)
Delete(ctx context.Context, owner, repo, name string) error
}
Tags manages repository tags. Releases are managed with Releases().
type Team ¶
type Team struct {
ID int64
Org string
Name string
Description string
// Permission is the overall level: admin or owner when the team has
// that level on every unit, otherwise derived by the server from Units.
Permission TeamPermission
Units map[TeamUnit]TeamPermission
// IncludesAllRepos gives the team access to every repository of the
// organisation, current and future.
IncludesAllRepos bool
CanCreateOrgRepo bool
}
Team is a team within an organisation.
type TeamAccess ¶
type TeamAccess struct {
Permission TeamPermission
Units map[TeamUnit]TeamPermission
}
TeamAccess sets a team's permissions. Exactly one form applies:
- Permission admin: admin on every unit; Units must be empty.
- Units set: per-unit permissions (none, read or write); Permission must be empty.
- Permission read or write with no Units: that level on every unit.
type TeamPermission ¶
type TeamPermission string
TeamPermission is a team's access level, overall or for one unit.
const ( TeamPermissionNone TeamPermission = "none" TeamPermissionRead TeamPermission = "read" TeamPermissionWrite TeamPermission = "write" TeamPermissionAdmin TeamPermission = "admin" // TeamPermissionOwner is reported for an organisation's owner team; it // cannot be assigned. TeamPermissionOwner TeamPermission = "owner" )
type TeamUnit ¶
type TeamUnit string
TeamUnit is a repository feature a team can be granted access to.
const ( TeamUnitCode TeamUnit = "repo.code" TeamUnitIssues TeamUnit = "repo.issues" TeamUnitExternalIssues TeamUnit = "repo.ext_issues" TeamUnitWiki TeamUnit = "repo.wiki" TeamUnitExternalWiki TeamUnit = "repo.ext_wiki" TeamUnitPulls TeamUnit = "repo.pulls" TeamUnitReleases TeamUnit = "repo.releases" TeamUnitProjects TeamUnit = "repo.projects" TeamUnitPackages TeamUnit = "repo.packages" TeamUnitActions TeamUnit = "repo.actions" )
type Teams ¶
type Teams interface {
List(ctx context.Context, org string, opts ListOptions) (Page[Team], error)
Get(ctx context.Context, id int64) (*Team, error)
// GetByName returns the team of org with exactly that name
// (case-insensitive), or a 404 *APIError.
GetByName(ctx context.Context, org, name string) (*Team, error)
Create(ctx context.Context, org string, opts CreateTeamOptions) (*Team, error)
// Edit changes a team. Renaming the owner team or changing its access
// returns ErrOwnerTeam.
Edit(ctx context.Context, id int64, opts EditTeamOptions) (*Team, error)
// Delete removes a team. Deleting the owner team returns ErrOwnerTeam.
Delete(ctx context.Context, id int64) error
Members(ctx context.Context, id int64, opts ListOptions) (Page[User], error)
IsMember(ctx context.Context, id int64, user string) (bool, error)
// AddMember adds user to the team, which also makes them a member of
// the organisation.
AddMember(ctx context.Context, id int64, user string) error
RemoveMember(ctx context.Context, id int64, user string) error
Repos(ctx context.Context, id int64, opts ListOptions) (Page[Repo], error)
AddRepo(ctx context.Context, id int64, owner, repo string) error
RemoveRepo(ctx context.Context, id int64, owner, repo string) error
}
Teams manages an organisation's teams, their members and repositories. Teams are addressed by ID; use GetByName to look one up.
type UnsupportedVersionError ¶
UnsupportedVersionError is returned when a server is older than the minimum version the library supports.
func (*UnsupportedVersionError) Error ¶
func (e *UnsupportedVersionError) Error() string
type User ¶
type User struct {
ID int64
Login string
FullName string
Email string
Description string
Website string
Location string
Visibility OwnerVisibility
IsAdmin bool
Active bool
Restricted bool
ProhibitLogin bool
HTMLURL string
CreatedAt time.Time
LastLogin time.Time // zero if the user never signed in
}
User is a user account.
type Users ¶
type Users interface {
Get(ctx context.Context, login string) (*User, error)
List(ctx context.Context, opts ListOptions) (Page[User], error)
Create(ctx context.Context, opts CreateUserOptions) (*User, error)
// Edit applies opts. If the server ignores a visibility change (Forgejo
// 15.0.x cannot switch a user back to public), Edit returns the updated
// user together with an error matching ErrNotSupported.
Edit(ctx context.Context, login string, opts EditUserOptions) (*User, error)
// Rename changes a user's login. The old login keeps redirecting to the
// new one, so Get(oldLogin) returns the renamed user.
Rename(ctx context.Context, login, newLogin string) error
Delete(ctx context.Context, login string, opts DeleteUserOptions) error
}
Users manages user accounts. All methods except Get require a site-admin token.
type Visibility ¶
type Visibility string
Visibility is the visibility of a repository. The zero value means "use the backend default" in option structs.
const ( VisibilityPublic Visibility = "public" VisibilityPrivate Visibility = "private" // VisibilityInternal is visible to all members of a GitHub enterprise. // Forgejo repositories only have a private flag, so the Forgejo backend // is expected to return ErrNotSupported for it. [verify in increment 3] VisibilityInternal Visibility = "internal" )
func (Visibility) Valid ¶
func (v Visibility) Valid() bool
Valid reports whether v is one of the named visibilities.
type Webhook ¶
type Webhook struct {
ID int64
URL string
ContentType HookContentType
// Events lists the subscribed events. Forgejo may add finer-grained
// events implied by the requested ones (e.g. issue_assign with issues);
// those keep Forgejo's names.
Events []HookEvent
Active bool
BranchFilter string // Forgejo only
CreatedAt time.Time
UpdatedAt time.Time
}
Webhook is a configured webhook. The secret is never returned.
type Webhooks ¶
type Webhooks interface {
List(ctx context.Context, scope HookScope, opts ListOptions) (Page[Webhook], error)
Get(ctx context.Context, scope HookScope, id int64) (*Webhook, error)
// Create adds a webhook. Forgejo silently drops event names it does not
// know; Create then returns the webhook together with an error.
Create(ctx context.Context, scope HookScope, opts CreateWebhookOptions) (*Webhook, error)
// Edit changes a webhook; dropped events are reported as in Create.
Edit(ctx context.Context, scope HookScope, id int64, opts EditWebhookOptions) (*Webhook, error)
Delete(ctx context.Context, scope HookScope, id int64) error
// Ping asks the server to send a test delivery: a "ping" event on
// GitHub, a "push" of the latest commit on Forgejo (repositories only).
Ping(ctx context.Context, scope HookScope, id int64) error
}
Webhooks manages repository and organisation webhooks. Receiving and verifying deliveries is done by the webhook sub-package.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bitbucket is the Bitbucket Cloud backend (REST API 2.0).
|
Package bitbucket is the Bitbucket Cloud backend (REST API 2.0). |
|
Package forgejo is the Forgejo backend.
|
Package forgejo is the Forgejo backend. |
|
Package github is the GitHub backend, built on google/go-github.
|
Package github is the GitHub backend, built on google/go-github. |
|
internal
|
|
|
bitbucketapi
Package bitbucketapi is the HTTP transport for the Bitbucket Cloud backend (REST API 2.0).
|
Package bitbucketapi is the HTTP transport for the Bitbucket Cloud backend (REST API 2.0). |
|
contracttest
Package contracttest holds behaviour checks shared by every backend's integration tests, so all backends are held to the same contract.
|
Package contracttest holds behaviour checks shared by every backend's integration tests, so all backends are held to the same contract. |
|
forgejoapi
Package forgejoapi is the HTTP transport for the Forgejo backend.
|
Package forgejoapi is the HTTP transport for the Forgejo backend. |
|
Package webhook receives webhook deliveries from Forgejo and GitHub: it verifies their signature, identifies the forge and event, and decodes the common payloads.
|
Package webhook receives webhook deliveries from Forgejo and GitHub: it verifies their signature, identifies the forge and event, and decodes the common payloads. |