Documentation ¶
Overview ¶
Package gitea provides Go bindings for the Gitea API.
Usage ¶
Construct a new Client, and then you can use the services to access different parts of the API. For example:
client := gitea.NewClient(nil) // get info about a repository repo, err := client.Repositories.Get("redson", "gitea-bindings-go") fmt.Println("Description:", repo.Description)
The default instance is Codeberg, if you want to use another, do something like:
instanceURL := url.Parse("https://gittea.dev/api/v1/") client := gitea.NewClient(&gitea.ClientOptions{ baseURL: instanceURL, })
Authentication ¶
Authentication is the same as changing the instance but now what you provide is a token, for example:
client := gitea.NewClient(&gitea.ClientOptions{ Token: "foo", })
For more info, see the examples at https://codeberg.org/redson/gitea-bindings-go/src/branch/main/example.
Index ¶
- Constants
- Variables
- type Client
- type ClientOptions
- type CreateRepositoryOpts
- type GPGEmail
- type GPGKey
- type GeneralAPISettings
- type GeneralAttachmentSettings
- type GeneralRepoSettings
- type GeneralUISettings
- type MarkdownAsHTMLOpts
- type MiscellaneousService
- type PostError
- type Repo
- type RepoPerms
- type RepoSearchOpts
- type RepoSearchResult
- type RepoService
- type SSHKey
- type SearchService
- type SettingsService
- func (s *SettingsService) GetAPISettings() (*GeneralAPISettings, error)
- func (s *SettingsService) GetAttachmentSettings() (*GeneralAttachmentSettings, error)
- func (s *SettingsService) GetRepositoriesSettings() (*GeneralRepoSettings, error)
- func (s *SettingsService) GetUISettings() (*GeneralUISettings, error)
- type User
- type UserEmail
- type UserSearchOpts
- type UserSearchResult
- type UserSettings
- type UsersService
- func (s *UsersService) EditSettings(opts *UserSettings) (*UserSettings, error)
- func (s *UsersService) Get(user string) (*User, error)
- func (s *UsersService) GetGPGKey(id int64) (*GPGKey, error)
- func (s *UsersService) GetKey(id int64) (*SSHKey, error)
- func (s *UsersService) GetSettings() (*UserSettings, error)
- func (s *UsersService) ListEmails() ([]*UserEmail, error)
- func (s *UsersService) ListFollowers(user string) ([]*User, error)
- func (s *UsersService) ListFollowing(user string) ([]*User, error)
- func (s *UsersService) ListGPGKeys(user string) ([]*GPGKey, error)
- func (s *UsersService) ListKeys(user string) ([]*SSHKey, error)
- func (s *UsersService) ListRepos(user string) ([]*Repo, error)
- type Version
Constants ¶
const ( // Use the default repository trust model for this installation. TrustDefault trust_model = "default" // Trust Signatures by collaborators. // Valid signatures by collaborators of this repository will be marked "trusted" - (whether they match the committer or not). // Otherwise, valid signatures will be marked "untrusted" if the signature matches the committer and "unmatched" if not. TrustCollaborator = "collaborator" // Trust signatures that match committers (This matches GitHub and will force Gitea signed commits to have Gitea as committer) // Valid signatures will only be marked "trusted" if they match the committer, otherwise they will be marked "unmatched". // This will force Gitea to be the committer on signed commits with the actual committer marked as Co-authored-by: and Co-committed-by: trailer in the commit. // The default Gitea key must match a User in the database. TrustCommitter = "committer" // Trust Signatures by collaborators which matches the committer // Valid signatures by collaborators of this repository will be marked "trusted" if they match the committer. //Otherwise, valid signatures will be marked "untrusted" if the signature matches the committer and "unmatched" otherwise. // This will force Gitea to be marked as the committer on signed commits with the actual committer marked as Co-Authored-By: and Co-Committed-By: trailer in the commit. // The default Gitea key must match a User in the database. TrustCollaboratorcommitter = "collaboratorcommitter" )
Variables ¶
var (
ErrRepoInfoMissing error = errors.New("repo owner or repo name is missing.")
)
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Repositories *RepoService Users *UsersService Miscellaneous *MiscellaneousService Settings *SettingsService Search *SearchService // contains filtered or unexported fields }
func NewClient ¶
func NewClient(opts *ClientOptions) *Client
NewClient returns a new Gitea API client. provided, a new http.Client will be used. To use API methods which require authentication, provide an ClientOptions.token that will perform the authentication.
type CreateRepositoryOpts ¶
type CreateRepositoryOpts struct { // Whether the repository should be auto-initialized? AutoInit bool `json:"auto_init,omitempty"` // DefaultBranch of the repository (used when initializes and in template) DefaultBranch string `json:"default_branch,omitempty"` // Description of the repository to create Description string `json:"description,omitempty"` // Gitignores to use Gitignores string `json:"gitignores,omitempty"` // Label-Set to use IssueLabels string `json:"issue_labels,omitempty"` // License to use License string `json:"license,omitempty"` // Good repository names use short, memorable and unique keywords. Name string `json:"name"` // Only the owner or the organization members if they have rights, will be able to see it. Private bool `json:"private,omitempty"` //Readme of the repository to create. Readme string `json:"readme,omitempty"` // A repository to use as template for this one. Template string `json:"template,omitempty"` // Signature trust model TrustModel trust_model `json:"trust_model,omitempty"` }
type GPGKey ¶
type GPGKey struct { ID int64 `json:"id,omitempty"` PrimaryKeyID string `json:"primary_key_id,omitempty"` KeyID string `json:"key_id,omitempty"` PublicKey string `json:"public_key,omitempty"` Emails []GPGEmail `json:"emails,omitempty"` Subkeys []GPGKey `json:"subkeys,omitempty"` CanSign bool `json:"can_sign,omitempty"` CanEncryptComms bool `json:"can_encrypt_comms,omitempty"` CanEncryptStorage bool `json:"can_encrypt_storage,omitempty"` CanCertify bool `json:"can_certify,omitempty"` Verified bool `json:"verified,omitempty"` CreatedAt string `json:"created_at,omitempty"` ExpiresAt string `json:"expires_at,omitempty"` }
type GeneralAPISettings ¶
type GeneralAPISettings struct { DefaultGitTreesPerPage int64 `json:"default_git_trees_per_page"` DefaultMaxBlobSize int64 `json:"default_max_blob_size"` DefaultPagingNum int64 `json:"default_paging_num"` MaxResponseItems int64 `json:"max_response_items"` }
GeneralAPISettings contains global api settings exposed by it
type GeneralAttachmentSettings ¶
type GeneralAttachmentSettings struct { AllowedTypes string `json:"allowed_types"` Enabled bool `json:"enabled"` MaxFiles int64 `json:"max_files"` MaxSize int64 `json:"max_size"` }
GeneralAttachmentSettings contains global Attachment settings exposed by API
type GeneralRepoSettings ¶
type GeneralRepoSettings struct { HttpGitDisabled bool `json:"http_git_disabled"` LfsDisabled bool `json:"lfs_disabled"` MigrationsDisabled bool `json:"migrations_disabled"` StarsDisabled bool `json:"stars_disabled"` TimeTrackingDisabled bool `json:"time_tracking_disabled"` }
GeneralRepoSettings contains global repository settings exposed by API
type GeneralUISettings ¶
type GeneralUISettings struct { AllowedReactions []string `json:"allowed_reactions"` CustomEmojis []string `json:"custom_emojis"` DefaultTheme string `json:"default_theme"` }
GeneralUISettings contains global ui settings exposed by API
type MarkdownAsHTMLOpts ¶
type MiscellaneousService ¶
type MiscellaneousService service
func (*MiscellaneousService) GetVersion ¶
func (s *MiscellaneousService) GetVersion() (*Version, error)
Returns the version of the gitea application.
func (*MiscellaneousService) MarkdownAsHTML ¶
func (s *MiscellaneousService) MarkdownAsHTML(opts *MarkdownAsHTMLOpts) (string, error)
MarkdownAsHTML Render a markdown document as HTML. If error returns an empty string and the error.
func (*MiscellaneousService) RawMarkdownAsHTML ¶
func (s *MiscellaneousService) RawMarkdownAsHTML(markdown string) (string, error)
RawMarkdownAsHTML Render raw markdown as HTML. If error returns an empty string and the error.
type Repo ¶
type Repo struct { Name string `json:"name,omitempty"` FullName string `json:"full_name,omitempty"` Description string `json:"description,omitempty"` HtmlURL string `json:"html_url,omitempty"` SSHURL string `json:"ssh_url,omitempty"` CloneURL string `json:"clone_url,omitempty"` OriginalURL string `json:"original_url,omitempty"` Website string `json:"website,omitempty"` DefaultBranch string `json:"default_branch,omitempty"` CreatedAt string `json:"created_at,omitempty"` UpdatedAt string `json:"updated_at,omitempty"` DefaultMergeStyle string `json:"default_merge_style,omitempty"` AvatarURL string `json:"avatar_url,omitempty"` MirrorInterval string `json:"mirror_interval,omitempty"` MirrorUpdated string `json:"mirror_updated"` IsEmpty bool `json:"empty,omitempty"` IsPrivate bool `json:"private,omitempty"` IsFork bool `json:"fork,omitempty"` IsTemplate bool `json:"template,omitempty"` IsParent bool `json:"parent,omitempty"` IsMirror bool `json:"mirror,omitempty"` IsArchived bool `json:"archived,omitempty"` HasIssues bool `json:"has_issues,omitempty"` HasWiki bool `json:"has_wiki,omitempty"` HasPullRequests bool `json:"has_pull_requests,omitempty"` HasProjects bool `json:"has_projects,omitempty"` IgnoreWhiteCon bool `json:"ignore_whitespace_conflicts,omitempty"` // Ignore whitespace conflicts AllowMergeCommits bool `json:"allow_merge_commits,omitempty"` AllowRebase bool `json:"allow_rebase,omitempty"` AllowReblaseExpli bool `json:"allow_rebase_explicit,omitempty"` AllowSquashMerge bool `json:"allow_squash_merge,omitempty"` Size int64 `json:"size,omitempty"` ID int64 `json:"id,omitempty"` StarsCount int64 `json:"stars_count,omitempty"` ForksCount int64 `json:"forks_count,omitempty"` WatchersCount int64 `json:"watchers_count,omitempty"` OpenIssuesCount int64 `json:"open_issues_count,omitempty"` OpenPRCounter int64 `json:"open_pr_counter,omitempty"` ReleaseCounter int64 `json:"release_counter,omitempty"` Owner User `json:"owner,omitempty"` Permissions RepoPerms `json:"permissions,omitempty"` }
type RepoSearchOpts ¶
type RepoSearchOpts struct { // Keyword Keyword string `json:"q"` // Limit search to repositories with keyword as topic Topic bool `json:"topic"` // include search of keyword within repository description IncludeDesc bool `json:"includeDesc"` // search only for repos that the user with the given id owns or contributes to Uid int64 `json:"uid"` // repo owner to prioritize in the results PriorityOwnerID int64 `json:"priority_owner_id"` // search only for repos that belong to the given team id TeamID int64 `json:"team_id"` // search only for repos that the user with the given id has starred StarredBy int64 `json:"starredBy"` // include private repositories this user has access to (defaults to true) Private bool `json:"private"` // show only pubic, private or all repositories (defaults to all) IsPrivate bool `json:"is_private"` // Include template repositories this user has access to (defaults to true) Template bool `json:"template"` // show only archived, non-archived or all repositories (defaults to all) Archived bool `json:"archived"` // type of repository to search for. Supported values are "fork", "source", "mirror" and "collaborative" Mode string `json:"mode"` // if uid is given, search only for repos that the user owns Exclusive bool `json:"exclusive"` // sort repos by attribute. Supported values are "alpha", "created", "updated", "size", and "id". Default is "alpha" Sort string `json:"sort"` // sort order, either "asc" (ascending) or "desc" (descending). Default is "asc", ignored if "sort" is not specified. Order string `json:"order"` // page number of results to return (1-based) Page int `json:"page"` // page size of results Limit int `json:"limit"` }
type RepoSearchResult ¶
type RepoService ¶
type RepoService service
func (*RepoService) CreateRepository ¶
func (s *RepoService) CreateRepository(opts *CreateRepositoryOpts) (*Repo, error)
Create a new repository for the authenticated user.
func (*RepoService) DeleteRepository ¶
func (s *RepoService) DeleteRepository(repoOwner string, repoName string) error
type SearchService ¶
type SearchService service
func (*SearchService) Repositories ¶
func (s *SearchService) Repositories(opts RepoSearchOpts) (*RepoSearchResult, error)
Search for repositories. if error, returns nil and the error.
func (*SearchService) Users ¶
func (s *SearchService) Users(opts UserSearchOpts) (*UserSearchResult, error)
Search for users. if error, returns nil and the error.
type SettingsService ¶
type SettingsService service
func (*SettingsService) GetAPISettings ¶
func (s *SettingsService) GetAPISettings() (*GeneralAPISettings, error)
Get instance's global settings for API.
func (*SettingsService) GetAttachmentSettings ¶
func (s *SettingsService) GetAttachmentSettings() (*GeneralAttachmentSettings, error)
Get intance's global settings for Attachment
func (*SettingsService) GetRepositoriesSettings ¶
func (s *SettingsService) GetRepositoriesSettings() (*GeneralRepoSettings, error)
Get intance's global settings for repositorioes
func (*SettingsService) GetUISettings ¶
func (s *SettingsService) GetUISettings() (*GeneralUISettings, error)
Get intance's global settings for UI.
type User ¶
type User struct { ID int64 `json:"id,omitempty"` Login string `json:"login,omitempty"` Full_Name string `json:"full_name,omitempty"` Email string `json:"email,omitempty"` AvatarURL string `json:"avatar_url,omitempty"` Language string `json:"language,omitempty"` IsAdmin bool `json:"is_admin,omitempty"` LastLogin string `json:"last_login,omitempty"` Created string `json:"created,omitempty"` IsRestricted bool `json:"restricted,omitempty"` IsActive bool `json:"active,omitempty"` ProhibitLogin bool `json:"prohibit_login,omitempty"` Location string `json:"location,omitempty"` Website string `json:"website,omitempty"` Description string `json:"description,omitempty"` Visibility string `json:"visibility,omitempty"` FollowersCount int64 `json:"followers_count,omitempty"` FollowingCount int64 `json:"following_count,omitempty"` StarredRepos int64 `json:"starred_repos_count,omitempty"` Username string `json:"username,omitempty"` }
type UserSearchOpts ¶
type UserSearchResult ¶
type UserSettings ¶
type UserSettings struct { FullName string `json:"full_name,omitempty"` Website string `json:"website,omitempty"` Description string `json:"description,omitempty"` Location string `json:"location,omitempty"` Language string `json:"language,omitempty"` Theme string `json:"theme,omitempty"` DiffViewStyle string `json:"diff_view_style,omitempty"` HideEmail bool `json:"hide_email,omitempty"` HideActivity bool `json:"hide_activity,omitempty"` }
type UsersService ¶
type UsersService service
func (*UsersService) EditSettings ¶
func (s *UsersService) EditSettings(opts *UserSettings) (*UserSettings, error)
EditSettings update the authenticated user settings. If a error occurs, it returns nil and the error.
func (*UsersService) Get ¶
func (s *UsersService) Get(user string) (*User, error)
Get information about the authenticated (or specified) user
func (*UsersService) GetGPGKey ¶
func (s *UsersService) GetGPGKey(id int64) (*GPGKey, error)
GetGPGKey gets details for a single GPG key. Requires authentication.
func (*UsersService) GetKey ¶
func (s *UsersService) GetKey(id int64) (*SSHKey, error)
GetKey gets details for a single SSH key. Requires authentication.
func (*UsersService) GetSettings ¶
func (s *UsersService) GetSettings() (*UserSettings, error)
GetSettings Get the authenticated user settings. If a error occurs, it returns nil and the error.
func (*UsersService) ListEmails ¶
func (s *UsersService) ListEmails() ([]*UserEmail, error)
List the authenticated user's email addresses
func (*UsersService) ListFollowers ¶
func (s *UsersService) ListFollowers(user string) ([]*User, error)
List the autenticated(or specified) user's followers
func (*UsersService) ListFollowing ¶
func (s *UsersService) ListFollowing(user string) ([]*User, error)
List the users that the autenticated(or specified) user is following
func (*UsersService) ListGPGKeys ¶
func (s *UsersService) ListGPGKeys(user string) ([]*GPGKey, error)
ListGPGKeys list the public GPG keys for a user. If you pass a empty string, will fetch keys for the authenticated user.