gitea

package
v3.1.21 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package gitea provides a Go SDK for the Gitea API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code    string         `json:"code"`
	Message string         `json:"message"`
	Status  int            `json:"status"`
	Details map[string]any `json:"details,omitempty"`
}

APIError represents an API error response

func (*APIError) Error

func (e *APIError) Error() string

type Attachment

type Attachment struct {
	ID            int64     `json:"id"`
	Name          string    `json:"name"`
	Size          int64     `json:"size"`
	DownloadCount int64     `json:"download_count"`
	DownloadURL   string    `json:"browser_download_url"`
	CreatedAt     time.Time `json:"created_at"`
}

Attachment represents a release asset

type ChunkedUpload

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

ChunkedUpload handles large file uploads

func (*ChunkedUpload) Cancel

func (cu *ChunkedUpload) Cancel(ctx context.Context) error

Cancel cancels the upload

func (*ChunkedUpload) GetSession

func (cu *ChunkedUpload) GetSession() *UploadSession

GetSession returns the current session

func (*ChunkedUpload) Upload

func (cu *ChunkedUpload) Upload(ctx context.Context, reader io.Reader, size int64) (*UploadResult, error)

Upload uploads the file from the reader

type ChunkedUploadOptions

type ChunkedUploadOptions struct {
	FileName       string
	ChunkSize      int64
	Parallel       int
	VerifyChecksum bool
	OnProgress     ProgressFunc
}

ChunkedUploadOptions configures a chunked upload

type Client

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

Client is a Gitea API client

func NewClient

func NewClient(baseURL string, opts ...ClientOption) (*Client, error)

NewClient creates a new Gitea API client

func (*Client) CreateChunkedUpload

func (c *Client) CreateChunkedUpload(ctx context.Context, owner, repo string, releaseID int64, opts ChunkedUploadOptions) (*ChunkedUpload, error)

CreateChunkedUpload starts a new chunked upload session

func (*Client) GetCurrentUser

func (c *Client) GetCurrentUser(ctx context.Context) (*User, error)

GetCurrentUser returns the authenticated user

func (*Client) GetRelease

func (c *Client) GetRelease(ctx context.Context, owner, repo, tag string) (*Release, error)

GetRelease returns a release by tag name

func (*Client) GetRepository

func (c *Client) GetRepository(ctx context.Context, owner, repo string) (*Repository, error)

GetRepository returns a repository by owner and name

func (*Client) GetVersion

func (c *Client) GetVersion(ctx context.Context) (string, error)

GetVersion returns the Gitea server version

func (*Client) ListReleases

func (c *Client) ListReleases(ctx context.Context, owner, repo string) ([]*Release, error)

ListReleases returns all releases for a repository

func (*Client) UploadReleaseAsset

func (c *Client) UploadReleaseAsset(ctx context.Context, owner, repo string, releaseID int64, fileName string, reader io.Reader, size int64, opts ...UploadOption) (*UploadResult, error)

UploadReleaseAsset is a convenience method for uploading a release asset

type ClientOption

type ClientOption func(*Client)

ClientOption is a function that configures the client

func SetHTTPClient

func SetHTTPClient(client *http.Client) ClientOption

SetHTTPClient sets a custom HTTP client

func SetToken

func SetToken(token string) ClientOption

SetToken sets the API token

func SetUserAgent

func SetUserAgent(ua string) ClientOption

SetUserAgent sets a custom user agent

type Progress

type Progress struct {
	BytesDone   int64
	BytesTotal  int64
	ChunksDone  int64
	ChunksTotal int64
	Percent     float64
	Speed       float64 // bytes per second
	ETA         time.Duration
}

Progress represents upload progress

type ProgressFunc

type ProgressFunc func(Progress)

ProgressFunc is called with progress updates

type Release

type Release struct {
	ID          int64        `json:"id"`
	TagName     string       `json:"tag_name"`
	Name        string       `json:"name"`
	Body        string       `json:"body"`
	Draft       bool         `json:"draft"`
	Prerelease  bool         `json:"prerelease"`
	PublishedAt time.Time    `json:"published_at"`
	Assets      []Attachment `json:"assets"`
}

Release represents a Gitea release

type Repository

type Repository struct {
	ID            int64  `json:"id"`
	Owner         *User  `json:"owner"`
	Name          string `json:"name"`
	FullName      string `json:"full_name"`
	Description   string `json:"description"`
	Private       bool   `json:"private"`
	Fork          bool   `json:"fork"`
	DefaultBranch string `json:"default_branch"`
	Stars         int    `json:"stars_count"`
	Forks         int    `json:"forks_count"`
	CloneURL      string `json:"clone_url"`
	HTMLURL       string `json:"html_url"`
}

Repository represents a Gitea repository

type UploadOption

type UploadOption func(*ChunkedUploadOptions)

UploadOption configures an upload

func WithChecksum

func WithChecksum(verify bool) UploadOption

WithChecksum enables checksum verification

func WithChunkSize

func WithChunkSize(size int64) UploadOption

WithChunkSize sets the chunk size

func WithParallel

func WithParallel(n int) UploadOption

WithParallel sets the number of parallel uploads

func WithProgress

func WithProgress(fn ProgressFunc) UploadOption

WithProgress sets the progress callback

type UploadResult

type UploadResult struct {
	ID               int64  `json:"id"`
	Name             string `json:"name"`
	Size             int64  `json:"size"`
	DownloadURL      string `json:"browser_download_url"`
	ChecksumVerified bool   `json:"checksum_verified"`
}

UploadResult represents the result of a completed upload

type UploadSession

type UploadSession struct {
	ID             string    `json:"id"`
	FileName       string    `json:"file_name"`
	FileSize       int64     `json:"file_size"`
	ChunkSize      int64     `json:"chunk_size"`
	TotalChunks    int64     `json:"total_chunks"`
	ChunksReceived int64     `json:"chunks_received"`
	Status         string    `json:"status"`
	ExpiresAt      time.Time `json:"expires_at"`
	Checksum       string    `json:"checksum,omitempty"`
}

UploadSession represents a chunked upload session

type User

type User struct {
	ID        int64  `json:"id"`
	Login     string `json:"login"`
	FullName  string `json:"full_name"`
	Email     string `json:"email"`
	AvatarURL string `json:"avatar_url"`
	IsAdmin   bool   `json:"is_admin"`
}

User represents a Gitea user

Source Files

  • client.go
  • upload.go

Jump to

Keyboard shortcuts

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