2016-12-27 16:14:02 +00:00
|
|
|
// Copyright 2016 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package gitea
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2020-02-05 07:59:55 +00:00
|
|
|
// ListForksOptions options for listing repository's forks
|
|
|
|
type ListForksOptions struct {
|
|
|
|
ListOptions
|
|
|
|
}
|
|
|
|
|
2016-12-27 16:14:02 +00:00
|
|
|
// ListForks list a repository's forks
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) ListForks(user string, repo string, opt ListForksOptions) ([]*Repository, *Response, error) {
|
2021-03-21 20:20:32 +00:00
|
|
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2020-02-05 07:59:55 +00:00
|
|
|
opt.setDefaults()
|
|
|
|
forks := make([]*Repository, opt.PageSize)
|
2020-09-14 03:37:09 +01:00
|
|
|
resp, err := c.getParsedResponse("GET",
|
2020-02-05 07:59:55 +00:00
|
|
|
fmt.Sprintf("/repos/%s/%s/forks?%s", user, repo, opt.getURLQuery().Encode()),
|
|
|
|
nil, nil, &forks)
|
2020-09-14 03:37:09 +01:00
|
|
|
return forks, resp, err
|
2016-12-27 16:14:02 +00:00
|
|
|
}
|
|
|
|
|
2019-10-13 02:34:01 +01:00
|
|
|
// CreateForkOption options for creating a fork
|
|
|
|
type CreateForkOption struct {
|
|
|
|
// organization name, if forking into an organization
|
|
|
|
Organization *string `json:"organization"`
|
2022-04-26 20:04:20 +01:00
|
|
|
// name of the forked repository
|
|
|
|
Name *string `json:"name"`
|
2019-10-13 02:34:01 +01:00
|
|
|
}
|
|
|
|
|
2016-12-27 16:14:02 +00:00
|
|
|
// CreateFork create a fork of a repository
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) CreateFork(user, repo string, form CreateForkOption) (*Repository, *Response, error) {
|
2021-03-21 20:20:32 +00:00
|
|
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2016-12-27 16:14:02 +00:00
|
|
|
body, err := json.Marshal(form)
|
|
|
|
if err != nil {
|
2020-09-14 03:37:09 +01:00
|
|
|
return nil, nil, err
|
2016-12-27 16:14:02 +00:00
|
|
|
}
|
|
|
|
fork := new(Repository)
|
2020-09-14 03:37:09 +01:00
|
|
|
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/forks", user, repo), jsonHeader, bytes.NewReader(body), &fork)
|
|
|
|
return fork, resp, err
|
2016-12-27 16:14:02 +00:00
|
|
|
}
|