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 Name string `url:"name,omitempty"`
58 DefaultBranchOnly bool `url:"default_branch_only,omitempty"`
59 }
60
61
62
63
64
65
66
67
68
69
70
71 func (s *RepositoriesService) CreateFork(ctx context.Context, owner, repo string, opts *RepositoryCreateForkOptions) (*Repository, *Response, error) {
72 u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
73 u, err := addOptions(u, opts)
74 if err != nil {
75 return nil, nil, err
76 }
77
78 req, err := s.client.NewRequest("POST", u, nil)
79 if err != nil {
80 return nil, nil, err
81 }
82
83 fork := new(Repository)
84 resp, err := s.client.Do(ctx, req, fork)
85 if err != nil {
86
87 if aerr, ok := err.(*AcceptedError); ok {
88 if err := json.Unmarshal(aerr.Raw, fork); err != nil {
89 return fork, resp, err
90 }
91
92 return fork, resp, err
93 }
94 return nil, resp, err
95 }
96
97 return fork, resp, nil
98 }
99
View as plain text