1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package github
- import (
- "context"
- "fmt"
- )
- type RepositoryListForksOptions struct {
-
-
- Sort string `url:"sort,omitempty"`
- ListOptions
- }
- func (s *RepositoriesService) ListForks(ctx context.Context, owner, repo string, opt *RepositoryListForksOptions) ([]*Repository, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
- u, err := addOptions(u, opt)
- if err != nil {
- return nil, nil, err
- }
- req, err := s.client.NewRequest("GET", u, nil)
- if err != nil {
- return nil, nil, err
- }
-
- req.Header.Set("Accept", mediaTypeTopicsPreview)
- var repos []*Repository
- resp, err := s.client.Do(ctx, req, &repos)
- if err != nil {
- return nil, resp, err
- }
- return repos, resp, nil
- }
- type RepositoryCreateForkOptions struct {
-
- Organization string `url:"organization,omitempty"`
- }
- func (s *RepositoriesService) CreateFork(ctx context.Context, owner, repo string, opt *RepositoryCreateForkOptions) (*Repository, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/forks", owner, repo)
- u, err := addOptions(u, opt)
- if err != nil {
- return nil, nil, err
- }
- req, err := s.client.NewRequest("POST", u, nil)
- if err != nil {
- return nil, nil, err
- }
- fork := new(Repository)
- resp, err := s.client.Do(ctx, req, fork)
- if _, ok := err.(*AcceptedError); ok {
- return fork, resp, err
- }
- if err != nil {
- return nil, resp, err
- }
- return fork, resp, nil
- }
|