aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/google/go-github/github/repos.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/google/go-github/github/repos.go')
-rw-r--r--vendor/github.com/google/go-github/github/repos.go132
1 files changed, 76 insertions, 56 deletions
diff --git a/vendor/github.com/google/go-github/github/repos.go b/vendor/github.com/google/go-github/github/repos.go
index e3fe26f..aa9b6ac 100644
--- a/vendor/github.com/google/go-github/github/repos.go
+++ b/vendor/github.com/google/go-github/github/repos.go
@@ -7,7 +7,6 @@ package github
import (
"context"
- "encoding/json"
"fmt"
"strings"
)
@@ -20,7 +19,7 @@ type RepositoriesService service
// Repository represents a GitHub repository.
type Repository struct {
- ID *int `json:"id,omitempty"`
+ ID *int64 `json:"id,omitempty"`
Owner *User `json:"owner,omitempty"`
Name *string `json:"name,omitempty"`
FullName *string `json:"full_name,omitempty"`
@@ -39,7 +38,7 @@ type Repository struct {
SSHURL *string `json:"ssh_url,omitempty"`
SVNURL *string `json:"svn_url,omitempty"`
Language *string `json:"language,omitempty"`
- Fork *bool `json:"fork"`
+ Fork *bool `json:"fork,omitempty"`
ForksCount *int `json:"forks_count,omitempty"`
NetworkCount *int `json:"network_count,omitempty"`
OpenIssuesCount *int `json:"open_issues_count,omitempty"`
@@ -61,16 +60,18 @@ type Repository struct {
License *License `json:"license,omitempty"`
// Additional mutable fields when creating and editing a repository
- Private *bool `json:"private"`
- HasIssues *bool `json:"has_issues"`
- HasWiki *bool `json:"has_wiki"`
- HasPages *bool `json:"has_pages"`
- HasDownloads *bool `json:"has_downloads"`
+ Private *bool `json:"private,omitempty"`
+ HasIssues *bool `json:"has_issues,omitempty"`
+ HasWiki *bool `json:"has_wiki,omitempty"`
+ HasPages *bool `json:"has_pages,omitempty"`
+ HasProjects *bool `json:"has_projects,omitempty"`
+ HasDownloads *bool `json:"has_downloads,omitempty"`
LicenseTemplate *string `json:"license_template,omitempty"`
GitignoreTemplate *string `json:"gitignore_template,omitempty"`
+ Archived *bool `json:"archived,omitempty"`
// Creating an organization repository. Required for non-owners.
- TeamID *int `json:"team_id"`
+ TeamID *int64 `json:"team_id,omitempty"`
// API URLs
URL *string `json:"url,omitempty"`
@@ -231,7 +232,7 @@ func (s *RepositoriesService) ListByOrg(ctx context.Context, org string, opt *Re
// RepositoriesService.ListAll method.
type RepositoryListAllOptions struct {
// ID of the last repository seen
- Since int `url:"since,omitempty"`
+ Since int64 `url:"since,omitempty"`
}
// ListAll lists all GitHub repositories in the order that they were created.
@@ -333,7 +334,7 @@ func (s *RepositoriesService) GetCodeOfConduct(ctx context.Context, owner, repo
// GetByID fetches a repository.
//
// Note: GetByID uses the undocumented GitHub API endpoint /repositories/:id.
-func (s *RepositoriesService) GetByID(ctx context.Context, id int) (*Repository, *Response, error) {
+func (s *RepositoriesService) GetByID(ctx context.Context, id int64) (*Repository, *Response, error) {
u := fmt.Sprintf("repositories/%d", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -388,7 +389,7 @@ func (s *RepositoriesService) Delete(ctx context.Context, owner, repo string) (*
// Contributor represents a repository contributor
type Contributor struct {
Login *string `json:"login,omitempty"`
- ID *int `json:"id,omitempty"`
+ ID *int64 `json:"id,omitempty"`
AvatarURL *string `json:"avatar_url,omitempty"`
GravatarID *string `json:"gravatar_id,omitempty"`
URL *string `json:"url,omitempty"`
@@ -403,7 +404,7 @@ type Contributor struct {
EventsURL *string `json:"events_url,omitempty"`
ReceivedEventsURL *string `json:"received_events_url,omitempty"`
Type *string `json:"type,omitempty"`
- SiteAdmin *bool `json:"site_admin"`
+ SiteAdmin *bool `json:"site_admin,omitempty"`
Contributions *int `json:"contributions,omitempty"`
}
@@ -481,6 +482,8 @@ func (s *RepositoriesService) ListTeams(ctx context.Context, owner string, repo
return nil, nil, err
}
+ req.Header.Set("Accept", mediaTypeNestedTeamsPreview)
+
var teams []*Team
resp, err := s.client.Do(ctx, req, &teams)
if err != nil {
@@ -568,41 +571,16 @@ type PullRequestReviewsEnforcement struct {
// enforcement of a protected branch. It is separate from PullRequestReviewsEnforcement above
// because the request structure is different from the response structure.
type PullRequestReviewsEnforcementRequest struct {
- // Specifies which users and teams should be allowed to dismiss pull request reviews. Can be nil to disable the restrictions.
- DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions"`
+ // Specifies which users and teams should be allowed to dismiss pull request reviews.
+ // User and team dismissal restrictions are only available for
+ // organization-owned repositories. Must be nil for personal repositories.
+ DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions,omitempty"`
// Specifies if approved reviews can be dismissed automatically, when a new commit is pushed. (Required)
DismissStaleReviews bool `json:"dismiss_stale_reviews"`
// RequireCodeOwnerReviews specifies if an approved review is required in pull requests including files with a designated code owner.
RequireCodeOwnerReviews bool `json:"require_code_owner_reviews"`
}
-// MarshalJSON implements the json.Marshaler interface.
-// Converts nil value of PullRequestReviewsEnforcementRequest.DismissalRestrictionsRequest to empty array
-func (req PullRequestReviewsEnforcementRequest) MarshalJSON() ([]byte, error) {
- if req.DismissalRestrictionsRequest == nil {
- newReq := struct {
- R []interface{} `json:"dismissal_restrictions"`
- D bool `json:"dismiss_stale_reviews"`
- O bool `json:"require_code_owner_reviews"`
- }{
- R: []interface{}{},
- D: req.DismissStaleReviews,
- O: req.RequireCodeOwnerReviews,
- }
- return json.Marshal(newReq)
- }
- newReq := struct {
- R *DismissalRestrictionsRequest `json:"dismissal_restrictions"`
- D bool `json:"dismiss_stale_reviews"`
- O bool `json:"require_code_owner_reviews"`
- }{
- R: req.DismissalRestrictionsRequest,
- D: req.DismissStaleReviews,
- O: req.RequireCodeOwnerReviews,
- }
- return json.Marshal(newReq)
-}
-
// PullRequestReviewsEnforcementUpdate represents request to patch the pull request review
// enforcement of a protected branch. It is separate from PullRequestReviewsEnforcementRequest above
// because the patch request does not require all fields to be initialized.
@@ -653,11 +631,12 @@ type DismissalRestrictions struct {
// restriction to allows only specific users or teams to dimiss pull request reviews. It is
// separate from DismissalRestrictions above because the request structure is
// different from the response structure.
+// Note: Both Users and Teams must be nil, or both must be non-nil.
type DismissalRestrictionsRequest struct {
- // The list of user logins who can dismiss pull request reviews. (Required; use []string{} instead of nil for empty list.)
- Users []string `json:"users"`
- // The list of team slugs which can dismiss pull request reviews. (Required; use []string{} instead of nil for empty list.)
- Teams []string `json:"teams"`
+ // The list of user logins who can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
+ Users *[]string `json:"users,omitempty"`
+ // The list of team slugs which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
+ Teams *[]string `json:"teams,omitempty"`
}
// ListBranches lists branches for the specified repository.
@@ -981,15 +960,15 @@ func (s *RepositoriesService) RemoveAdminEnforcement(ctx context.Context, owner,
return s.client.Do(ctx, req, nil)
}
-// Topics represents a collection of repository topics.
-type Topics struct {
- Names []string `json:"names,omitempty"`
+// repositoryTopics represents a collection of repository topics.
+type repositoryTopics struct {
+ Names []string `json:"names"`
}
// ListAllTopics lists topics for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#list-all-topics-for-a-repository
-func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo string) (*Topics, *Response, error) {
+func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo string) ([]string, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/topics", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
@@ -999,21 +978,27 @@ func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo str
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeTopicsPreview)
- topics := new(Topics)
+ topics := new(repositoryTopics)
resp, err := s.client.Do(ctx, req, topics)
if err != nil {
return nil, resp, err
}
- return topics, resp, nil
+ return topics.Names, resp, nil
}
// ReplaceAllTopics replaces topics for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository
-func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo string, topics *Topics) (*Topics, *Response, error) {
+func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo string, topics []string) ([]string, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/topics", owner, repo)
- req, err := s.client.NewRequest("PUT", u, topics)
+ t := &repositoryTopics{
+ Names: topics,
+ }
+ if t.Names == nil {
+ t.Names = []string{}
+ }
+ req, err := s.client.NewRequest("PUT", u, t)
if err != nil {
return nil, nil, err
}
@@ -1021,11 +1006,46 @@ func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo
// TODO: remove custom Accept header when this API fully launches.
req.Header.Set("Accept", mediaTypeTopicsPreview)
- t := new(Topics)
+ t = new(repositoryTopics)
resp, err := s.client.Do(ctx, req, t)
if err != nil {
return nil, resp, err
}
- return t, resp, nil
+ return t.Names, resp, nil
+}
+
+// TransferRequest represents a request to transfer a repository.
+type TransferRequest struct {
+ NewOwner string `json:"new_owner"`
+ TeamID []int64 `json:"team_id,omitempty"`
+}
+
+// Transfer transfers a repository from one account or organization to another.
+//
+// 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 has now scheduled the transfer of the repository 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/#transfer-a-repository
+func (s *RepositoriesService) Transfer(ctx context.Context, owner, repo string, transfer TransferRequest) (*Repository, *Response, error) {
+ u := fmt.Sprintf("repos/%v/%v/transfer", owner, repo)
+
+ req, err := s.client.NewRequest("POST", u, &transfer)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ // TODO: remove custom Accept header when this API fully launches.
+ req.Header.Set("Accept", mediaTypeRepositoryTransferPreview)
+
+ r := new(Repository)
+ resp, err := s.client.Do(ctx, req, r)
+ if err != nil {
+ return nil, resp, err
+ }
+
+ return r, resp, nil
}