58 lines
1.7 KiB
Go
58 lines
1.7 KiB
Go
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
// Package gitea provides a thin wrapper around the Gitea Go SDK
|
|
// for managing repositories, issues, and pull requests on a Gitea instance.
|
|
//
|
|
// Authentication is resolved from config file, environment variables, or flag overrides:
|
|
//
|
|
// 1. ~/.core/config.yaml keys: gitea.token, gitea.url
|
|
// 2. GITEA_TOKEN + GITEA_URL environment variables (override config file)
|
|
// 3. Flag overrides via core gitea config --url/--token (highest priority)
|
|
package gitea
|
|
|
|
import (
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
"dappco.re/go/core/log"
|
|
)
|
|
|
|
// Client wraps the Gitea SDK client with config-based auth.
|
|
type Client struct {
|
|
api *gitea.Client
|
|
url string
|
|
token string
|
|
}
|
|
|
|
// New creates a new Gitea API client for the given URL and token.
|
|
// Usage: New(...)
|
|
func New(url, token string) (*Client, error) {
|
|
api, err := gitea.NewClient(url, gitea.SetToken(token))
|
|
if err != nil {
|
|
return nil, log.E("gitea.New", "failed to create client", err)
|
|
}
|
|
|
|
return &Client{api: api, url: url, token: token}, nil
|
|
}
|
|
|
|
// API exposes the underlying SDK client for direct access.
|
|
// Usage: API(...)
|
|
func (c *Client) API() *gitea.Client { return c.api }
|
|
|
|
// URL returns the Gitea instance URL.
|
|
// Usage: URL(...)
|
|
func (c *Client) URL() string { return c.url }
|
|
|
|
// Token returns the Gitea API token.
|
|
// Usage: Token(...)
|
|
func (c *Client) Token() string { return c.token }
|
|
|
|
// GetCurrentUser returns the authenticated user's information.
|
|
// Usage: GetCurrentUser(...)
|
|
func (c *Client) GetCurrentUser() (*gitea.User, error) {
|
|
user, _, err := c.api.GetMyUserInfo()
|
|
if err != nil {
|
|
return nil, log.E("gitea.GetCurrentUser", "failed to get current user", err)
|
|
}
|
|
|
|
return user, nil
|
|
}
|