Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit 0b35be3

Browse files
committed
Functions for forks
1 parent d628d07 commit 0b35be3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

gitea/fork.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2016 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package gitea
6+
7+
import (
8+
"bytes"
9+
"encoding/json"
10+
"fmt"
11+
)
12+
13+
// ListForks list a repository's forks
14+
func (c *Client) ListForks(user, repo string) ([]*Repository, error) {
15+
forks := make([]*Repository, 10)
16+
err := c.getParsedResponse("GET",
17+
fmt.Sprintf("/repos/%s/%s/forks", user, repo),
18+
nil, nil, &forks)
19+
return forks, err
20+
}
21+
22+
// CreateForkOption options for creating a fork
23+
type CreateForkOption struct {
24+
Organization *string `json:"organization"`
25+
}
26+
27+
// CreateFork create a fork of a repository
28+
func (c *Client) CreateFork(user, repo string, form CreateForkOption) (*Repository, error) {
29+
body, err := json.Marshal(form)
30+
if err != nil {
31+
return nil, err
32+
}
33+
fork := new(Repository)
34+
err = c.getParsedResponse("POST",
35+
fmt.Sprintf("/repos/%s/%s/forks", user, repo),
36+
jsonHeader, bytes.NewReader(body), &fork)
37+
return fork, err
38+
}

0 commit comments

Comments
 (0)