1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11
12 "encoding/json"
13 )
14
15
16
17 type RepositoryListForksOptions struct {
18
19
20 Sort string `url:"sort,omitempty"`
21
22 ListOptions
23 }
24
25
26
27
28 func (s *RepositoriesService) ListForks(ctx context.Context, owner, repo string, opts *RepositoryListForksOptions) ([]*Repository, *Response, error) {
29 u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
30 u, err := addOptions(u, opts)
31 if err != nil {
32 return nil, nil, err
33 }
34
35 req, err := s.client.NewRequest("GET", u, nil)
36 if err != nil {
37 return nil, nil, err
38 }
39
40
41 req.Header.Set("Accept", mediaTypeTopicsPreview)
42
43 var repos []*Repository
44 resp, err := s.client.Do(ctx, req, &repos)
45 if err != nil {
46 return nil, resp, err
47 }
48
49 return repos, resp, nil
50 }
51
52
53
54 type RepositoryCreateForkOptions struct {
55
56 Organization string `url:"organization,omitempty"`
57 }
58
59
60
61
62
63
64
65
66
67
68
69 func (s *RepositoriesService) CreateFork(ctx context.Context, owner, repo string, opts *RepositoryCreateForkOptions) (*Repository, *Response, error) {
70 u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
71 u, err := addOptions(u, opts)
72 if err != nil {
73 return nil, nil, err
74 }
75
76 req, err := s.client.NewRequest("POST", u, nil)
77 if err != nil {
78 return nil, nil, err
79 }
80
81 fork := new(Repository)
82 resp, err := s.client.Do(ctx, req, fork)
83 if err != nil {
84
85 if aerr, ok := err.(*AcceptedError); ok {
86 if err := json.Unmarshal(aerr.Raw, fork); err != nil {
87 return fork, resp, err
88 }
89
90 return fork, resp, err
91 }
92 return nil, resp, err
93 }
94
95 return fork, resp, nil
96 }
97
View as plain text