feat: initial version of the project
This commit is contained in:
commit
5b67d39aba
13 changed files with 1538 additions and 0 deletions
40
internal/api/client.go
Normal file
40
internal/api/client.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"codeberg.org/romaintb/fgj/internal/config"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
*gitea.Client
|
||||
hostname string
|
||||
}
|
||||
|
||||
func NewClient(hostname, token string) (*Client, error) {
|
||||
if hostname == "" {
|
||||
hostname = "codeberg.org"
|
||||
}
|
||||
|
||||
client, err := gitea.NewClient("https://"+hostname, gitea.SetToken(token))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Client{
|
||||
Client: client,
|
||||
hostname: hostname,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewClientFromConfig(cfg *config.Config, hostname string) (*Client, error) {
|
||||
host, err := cfg.GetHost(hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewClient(host.Hostname, host.Token)
|
||||
}
|
||||
|
||||
func (c *Client) Hostname() string {
|
||||
return c.hostname
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue