2017-02-07 21:33:23 +00:00
|
|
|
// Copyright 2013 The go-github AUTHORS. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package github
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
)
|
2017-02-07 21:33:23 +00:00
|
|
|
|
|
|
|
// RepositoryListForksOptions specifies the optional parameters to the
|
|
|
|
// RepositoriesService.ListForks method.
|
|
|
|
type RepositoryListForksOptions struct {
|
2017-04-11 15:10:46 +00:00
|
|
|
// How to sort the forks list. Possible values are: newest, oldest,
|
|
|
|
// watchers. Default is "newest".
|
2017-02-07 21:33:23 +00:00
|
|
|
Sort string `url:"sort,omitempty"`
|
|
|
|
|
|
|
|
ListOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListForks lists the forks of the specified repository.
|
|
|
|
//
|
2017-04-11 15:10:46 +00:00
|
|
|
// GitHub API docs: https://developer.github.com/v3/repos/forks/#list-forks
|
|
|
|
func (s *RepositoriesService) ListForks(ctx context.Context, owner, repo string, opt *RepositoryListForksOptions) ([]*Repository, *Response, error) {
|
2017-02-07 21:33:23 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
var repos []*Repository
|
|
|
|
resp, err := s.client.Do(ctx, req, &repos)
|
2017-02-07 21:33:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
return repos, resp, nil
|
2017-02-07 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RepositoryCreateForkOptions specifies the optional parameters to the
|
|
|
|
// RepositoriesService.CreateFork method.
|
|
|
|
type RepositoryCreateForkOptions struct {
|
|
|
|
// The organization to fork the repository into.
|
|
|
|
Organization string `url:"organization,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateFork creates a fork of the specified repository.
|
|
|
|
//
|
|
|
|
// This method might return an *AcceptedError and a status code of
|
|
|
|
// 202. This is because this is the status that GitHub returns to signify that
|
|
|
|
// it is now computing creating the fork in a background task.
|
|
|
|
// A follow up request, after a delay of a second or so, should result
|
|
|
|
// in a successful request.
|
|
|
|
//
|
|
|
|
// GitHub API docs: https://developer.github.com/v3/repos/forks/#create-a-fork
|
2017-04-11 15:10:46 +00:00
|
|
|
func (s *RepositoriesService) CreateFork(ctx context.Context, owner, repo string, opt *RepositoryCreateForkOptions) (*Repository, *Response, error) {
|
2017-02-07 21:33:23 +00:00
|
|
|
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)
|
2017-04-11 15:10:46 +00:00
|
|
|
resp, err := s.client.Do(ctx, req, fork)
|
2017-02-07 21:33:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
return fork, resp, nil
|
2017-02-07 21:33:23 +00:00
|
|
|
}
|