gitea

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const (
	// DefaultDomain specifies the default domain used as the backend.
	DefaultDomain = "gitea.com"
	// ProviderID is the provider ID for Gitea.
	ProviderID = gitprovider.ProviderID("gitea")
)

Variables

This section is empty.

Functions

func NewClient

func NewClient(token string, optFns ...gitprovider.ClientOption) (gitprovider.Client, error)

NewClient creates a new gitprovider.Client instance for Gitea API endpoints.

Gitea Selfhosted can be used if you specify the domain using WithDomain.

Types

type BranchClient

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

BranchClient operates on the branch for a specific repository.

func (*BranchClient) Create

func (c *BranchClient) Create(ctx context.Context, branch, sha string) error

Create creates a branch with the given specifications. Creating a branch from a commit is noy supported by Gitea, the sha refers to the branch to create from. see: https://github.com/go-gitea/gitea/issues/22139

type Client

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

Client is an interface that allows talking to a Git provider.

func (*Client) HasTokenPermission

func (c *Client) HasTokenPermission(ctx context.Context, permission gitprovider.TokenPermission) (bool, error)

HasTokenPermission returns true if the given token has the given permissions.

func (*Client) OrgRepositories

func (c *Client) OrgRepositories() gitprovider.OrgRepositoriesClient

OrgRepositories returns the OrgRepositoriesClient handling sets of repositories in an organization.

func (*Client) Organizations

func (c *Client) Organizations() gitprovider.OrganizationsClient

Organizations returns the OrganizationsClient handling sets of organizations.

func (*Client) ProviderID

func (c *Client) ProviderID() gitprovider.ProviderID

ProviderID returns the provider ID "gitea". This field is set at client creation time, and can't be changed.

func (*Client) Raw

func (c *Client) Raw() interface{}

Raw returns the Gitea client (code.gitea.io/sdk/gitea *Client) used under the hood for accessing Gitea.

func (*Client) SupportedDomain

func (c *Client) SupportedDomain() string

SupportedDomain returns the domain endpoint for this client, e.g. "gitea.com", "gitea.dev.com" or "my-custom-git-server.com:6443". This allows a higher-level user to know what Client to use for what endpoints. This field is set at client creation time, and can't be changed.

func (*Client) UserRepositories

func (c *Client) UserRepositories() gitprovider.UserRepositoriesClient

UserRepositories returns the UserRepositoriesClient handling sets of repositories for a user.

type CommitClient

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

CommitClient operates on the commits for a specific repository.

func (*CommitClient) Create

func (c *CommitClient) Create(ctx context.Context, branch string, message string, files []gitprovider.CommitFile) (gitprovider.Commit, error)

Create creates a commit with the given specifications. This method creates a commit with a single file. TODO: fix when gitea supports creating commits with multiple files

func (*CommitClient) ListPage

func (c *CommitClient) ListPage(ctx context.Context, branch string, perPage, page int) ([]gitprovider.Commit, error)

ListPage lists all repository commits of the given page and page size. ListPage returns all available repository commits using multiple paginated requests if needed.

type DeployKeyClient

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

DeployKeyClient operates on the access deploy key list for a specific repository.

func (*DeployKeyClient) Create

Create creates a deploy key with the given specifications.

ErrAlreadyExists will be returned if the resource already exists.

func (*DeployKeyClient) Get

Get returns the repository at the given path.

ErrNotFound is returned if the resource does not exist.

func (*DeployKeyClient) List

List lists all repository deploy keys of the given deploy key type.

List returns all available repository deploy keys for the given type, using multiple paginated requests if needed.

func (*DeployKeyClient) Reconcile

Reconcile makes sure the given desired state (req) becomes the actual state in the backing Git provider.

If req doesn't exist under the hood, it is created (actionTaken == true). If req doesn't equal the actual state, the resource will be deleted and recreated (actionTaken == true). If req is already the actual state, this is a no-op (actionTaken == false).

type FileClient

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

FileClient operates on the branch for a specific repository.

func (*FileClient) Get

func (c *FileClient) Get(ctx context.Context, path, branch string, optFns ...gitprovider.FilesGetOption) ([]*gitprovider.CommitFile, error)

Get fetches and returns the contents of a file or multiple files in a directory from a given branch and path. If a file path is given, the contents of the file are returned If a directory path is given, the contents of the files in the path's root are returned

type OrgRepositoriesClient

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

OrgRepositoriesClient operates on repositories the user has access to.

func (*OrgRepositoriesClient) Create

Create creates a repository for the given organization, with the data and options.

ErrAlreadyExists will be returned if the resource already exists.

func (*OrgRepositoriesClient) Get

Get returns the repository at the given path.

ErrNotFound is returned if the resource does not exist.

Example
// Create a new client
ctx := context.Background()
c, err := gitea.NewClient(os.Getenv("GITEA_ACCESS_TOKEN"), gitprovider.WithDomain(gitea.DefaultDomain))
checkErr(err)

// Parse the URL into an OrgRepositoryRef
ref, err := gitprovider.ParseOrgRepositoryURL("https://gitea.com/gitea/go-sdk")
checkErr(err)

// Get public information about the flux repository.
repo, err := c.OrgRepositories().Get(ctx, *ref)
checkErr(err)

// Use .Get() to aquire a high-level gitprovider.OrganizationInfo struct
repoInfo := repo.Get()
// Cast the internal object to a *gogitea.Repository to access custom data
internalRepo := repo.APIObject().(*gogitea.Repository)

fmt.Printf("Description: %s. Homepage: %s", *repoInfo.Description, internalRepo.HTMLURL)
Output:

Description: Gitea: Golang SDK. Homepage: https://gitea.com/gitea/go-sdk

func (*OrgRepositoriesClient) List

List all repositories in the given organization.

List returns all available repositories, using multiple paginated requests if needed.

func (*OrgRepositoriesClient) Reconcile

Reconcile makes sure the given desired state (req) becomes the actual state in the backing Git provider.

If req doesn't exist under the hood, it is created (actionTaken == true). If req doesn't equal the actual state, the resource will be updated (actionTaken == true). If req is already the actual state, this is a no-op (actionTaken == false).

type OrganizationsClient

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

OrganizationsClient operates on organizations the user has access to.

func (*OrganizationsClient) Children

Children returns the immediate child-organizations for the specific OrganizationRef o. The OrganizationRef may point to any existing sub-organization.

This is not supported in Gitea.

Children returns all available organizations, using multiple paginated requests if needed.

func (*OrganizationsClient) Get

Get a specific organization the user has access to. This can't refer to a sub-organization in Gitea, as those aren't supported.

ErrNotFound is returned if the resource does not exist.

Example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	gogitea "code.gitea.io/sdk/gitea"
	"github.com/fluxcd/go-git-providers/gitea"
	"github.com/fluxcd/go-git-providers/gitprovider"
)

// checkErr is used for examples in this repository.
func checkErr(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	// Create a new client
	ctx := context.Background()
	c, err := gitea.NewClient(os.Getenv("GITEA_ACCESS_TOKEN"), gitprovider.WithDomain(gitea.DefaultDomain))
	checkErr(err)

	// Get public information about the gitea organization

	org, err := c.Organizations().Get(ctx, gitprovider.OrganizationRef{
		Domain:       gitea.DefaultDomain,
		Organization: "gitea",
	})
	checkErr(err)

	// Use .Get() to aquire a high-level gitprovider.OrganizationInfo struct
	orgInfo := org.Get()
	// Cast the internal object to a *gogitea.Organization to access custom data
	internalOrg := org.APIObject().(*gogitea.Organization)

	fmt.Printf("Name: %s. Location: %s.", *orgInfo.Name, internalOrg.Location)
}
Output:

Name: gitea. Location: Git Universe.

func (*OrganizationsClient) List

List all top-level organizations the specific user has access to.

List returns all available organizations, using multiple paginated requests if needed.

type PullRequestClient

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

PullRequestClient operates on the pull requests for a specific repository.

func (*PullRequestClient) Create

func (c *PullRequestClient) Create(ctx context.Context, title, branch, baseBranch, description string) (gitprovider.PullRequest, error)

Create creates a pull request with the given specifications.

func (*PullRequestClient) Edit

Edit modifies an existing PR. Please refer to "EditOptions" for details on which data can be edited.

func (*PullRequestClient) Get

Get retrieves an existing pull request by number

func (*PullRequestClient) List

List lists all pull requests in the repository

func (*PullRequestClient) Merge

func (c *PullRequestClient) Merge(ctx context.Context, number int, mergeMethod gitprovider.MergeMethod, message string) error

Merge merges a pull request with the given specifications. Supported merge methods are: MergeMethodMerge and MergeMethodSquash

type TeamAccessClient

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

TeamAccessClient operates on the teams list for a specific repository.

func (*TeamAccessClient) Create

Create adds a given team to the repo's team access control list.

ErrAlreadyExists will be returned if the resource already exists.

func (*TeamAccessClient) Get

Get a team within the specific organization.

name may include slashes, but must not be an empty string. Teams are sub-groups in GitLab.

ErrNotFound is returned if the resource does not exist.

TeamAccess.APIObject will be nil, because there's no underlying Gitea struct.

func (*TeamAccessClient) List

List lists the team access control list for this repository.

List returns all available team access lists, using multiple paginated requests if needed.

func (*TeamAccessClient) Reconcile

Reconcile makes sure the given desired state (req) becomes the actual state in the backing Git provider.

If req doesn't exist under the hood, it is created (actionTaken == true). If req doesn't equal the actual state, the resource will be deleted and recreated (actionTaken == true). If req is already the actual state, this is a no-op (actionTaken == false).

type TeamsClient

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

TeamsClient handles teams organization-wide.

func (*TeamsClient) Get

func (c *TeamsClient) Get(ctx context.Context, teamName string) (gitprovider.Team, error)

Get a team within the specific organization.

teamName may include slashes, to point to e.g. subgroups in GitLab. teamName must not be an empty string.

ErrNotFound is returned if the resource does not exist.

func (*TeamsClient) List

func (c *TeamsClient) List(ctx context.Context) ([]gitprovider.Team, error)

List all teams (recursively, in terms of subgroups) within the specific organization.

List returns all available organizations, using multiple paginated requests if needed.

type TreeClient

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

TreeClient operates on the trees in a specific repository.

func (*TreeClient) Get

func (c *TreeClient) Get(ctx context.Context, sha string, recursive bool) (*gitprovider.TreeInfo, error)

Get returns a tree

func (*TreeClient) List

func (c *TreeClient) List(ctx context.Context, sha string, path string, recursive bool) ([]*gitprovider.TreeEntry, error)

List files (blob) in a tree, sha is represented by the branch name

type UserRepositoriesClient

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

UserRepositoriesClient operates on repositories the user has access to.

func (*UserRepositoriesClient) Create

Create creates a repository for the given organization, with the data and options

ErrAlreadyExists will be returned if the resource already exists.

func (*UserRepositoriesClient) Get

Get returns the repository at the given path.

ErrNotFound is returned if the resource does not exist.

func (*UserRepositoriesClient) GetUserLogin added in v0.19.0

GetUserLogin returns the authenticated user

func (*UserRepositoriesClient) List

List all repositories in the given organization.

List returns all available repositories, using multiple paginated requests if needed.

func (*UserRepositoriesClient) Reconcile

Reconcile makes sure the given desired state (req) becomes the actual state in the backing Git provider.

If req doesn't exist under the hood, it is created (actionTaken == true). If req doesn't equal the actual state, the resource will be updated (actionTaken == true). If req is already the actual state, this is a no-op (actionTaken == false).

Jump to

Keyboard shortcuts

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