package gitea import ( "context" "encoding/json" "fmt" ) type PushMirror struct { ID int `json:"id"` RemoteName string `json:"remote_name"` RemoteAddress string `json:"remote_address"` Interval string `json:"interval"` SyncOnCommit bool `json:"sync_on_commit"` } type AddPushMirrorArgs struct { RemoteAddress string `json:"remote_address"` RemoteUsername string `json:"remote_username,omitempty"` RemotePassword string `json:"remote_password,omitempty"` Interval string `json:"interval,omitempty"` SyncOnCommit bool `json:"sync_on_commit,omitempty"` } func (c *Client) AddPushMirror(ctx context.Context, owner, repo string, args AddPushMirrorArgs) (*PushMirror, error) { path := fmt.Sprintf("/api/v1/repos/%s/%s/push_mirrors", owner, repo) body, err := json.Marshal(args) if err != nil { return nil, err } resp, status, err := c.PostJSON(ctx, path, body) if err != nil { return nil, err } if err := MapStatus(status, resp); err != nil { return nil, err } var m PushMirror if err := json.Unmarshal(resp, &m); err != nil { return nil, err } return &m, nil } func (c *Client) ListPushMirrors(ctx context.Context, owner, repo string) ([]PushMirror, error) { path := fmt.Sprintf("/api/v1/repos/%s/%s/push_mirrors", owner, repo) resp, status, err := c.GetJSON(ctx, path) if err != nil { return nil, err } if err := MapStatus(status, resp); err != nil { return nil, err } var mirrors []PushMirror if err := json.Unmarshal(resp, &mirrors); err != nil { return nil, err } return mirrors, nil } func (c *Client) DeletePushMirror(ctx context.Context, owner, repo, mirrorName string) error { path := fmt.Sprintf("/api/v1/repos/%s/%s/push_mirrors/%s", owner, repo, mirrorName) resp, status, err := c.DeleteJSON(ctx, path) if err != nil { return err } if status == 204 { return nil } return MapStatus(status, resp) }