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.go130
1 files changed, 103 insertions, 27 deletions
diff --git a/vendor/github.com/google/go-github/github/repos.go b/vendor/github.com/google/go-github/github/repos.go
index 98e4ac5..040cd31 100644
--- a/vendor/github.com/google/go-github/github/repos.go
+++ b/vendor/github.com/google/go-github/github/repos.go
@@ -5,7 +5,10 @@
package github
-import "fmt"
+import (
+ "fmt"
+ "strings"
+)
// RepositoriesService handles communication with the repository related
// methods of the GitHub API.
@@ -46,6 +49,9 @@ type Repository struct {
Source *Repository `json:"source,omitempty"`
Organization *Organization `json:"organization,omitempty"`
Permissions *map[string]bool `json:"permissions,omitempty"`
+ AllowRebaseMerge *bool `json:"allow_rebase_merge,omitempty"`
+ AllowSquashMerge *bool `json:"allow_squash_merge,omitempty"`
+ AllowMergeCommit *bool `json:"allow_merge_commit,omitempty"`
// Only provided when using RepositoriesService.Get while in preview
License *License `json:"license,omitempty"`
@@ -286,7 +292,8 @@ func (s *RepositoriesService) Get(owner, repo string) (*Repository, *Response, e
// TODO: remove custom Accept header when the license support fully launches
// https://developer.github.com/v3/licenses/#get-a-repositorys-license
- req.Header.Set("Accept", mediaTypeLicensesPreview)
+ acceptHeaders := []string{mediaTypeLicensesPreview, mediaTypeSquashPreview}
+ req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
repository := new(Repository)
resp, err := s.client.Do(req, repository)
@@ -330,6 +337,9 @@ func (s *RepositoriesService) Edit(owner, repo string, repository *Repository) (
return nil, nil, err
}
+ // TODO: Remove this preview header after API is fully vetted.
+ req.Header.Add("Accept", mediaTypeSquashPreview)
+
r := new(Repository)
resp, err := s.client.Do(req, r)
if err != nil {
@@ -491,29 +501,54 @@ func (s *RepositoriesService) ListTags(owner string, repo string, opt *ListOptio
// Branch represents a repository branch
type Branch struct {
- Name *string `json:"name,omitempty"`
- Commit *Commit `json:"commit,omitempty"`
- Protection *Protection `json:"protection,omitempty"`
+ Name *string `json:"name,omitempty"`
+ Commit *RepositoryCommit `json:"commit,omitempty"`
+ Protected *bool `json:"protected,omitempty"`
}
-// Protection represents a repository branch's protection
+// Protection represents a repository branch's protection.
type Protection struct {
- Enabled *bool `json:"enabled,omitempty"`
- RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks,omitempty"`
+ RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"`
+ Restrictions *BranchRestrictions `json:"restrictions"`
}
-// RequiredStatusChecks represents the protection status of a individual branch
+// ProtectionRequest represents a request to create/edit a branch's protection.
+type ProtectionRequest struct {
+ RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"`
+ Restrictions *BranchRestrictionsRequest `json:"restrictions"`
+}
+
+// RequiredStatusChecks represents the protection status of a individual branch.
type RequiredStatusChecks struct {
- // Who required status checks apply to.
- // Possible values are:
- // off
- // non_admins
- // everyone
- EnforcementLevel *string `json:"enforcement_level,omitempty"`
- // The list of status checks which are required
+ // Enforce required status checks for repository administrators.
+ IncludeAdmins *bool `json:"include_admins,omitempty"`
+ // Require branches to be up to date before merging.
+ Strict *bool `json:"strict,omitempty"`
+ // The list of status checks to require in order to merge into this
+ // branch.
Contexts *[]string `json:"contexts,omitempty"`
}
+// BranchRestrictions represents the restriction that only certain users or
+// teams may push to a branch.
+type BranchRestrictions struct {
+ // The list of user logins with push access.
+ Users []*User `json:"users,omitempty"`
+ // The list of team slugs with push access.
+ Teams []*Team `json:"teams,omitempty"`
+}
+
+// BranchRestrictionsRequest represents the request to create/edit the
+// restriction that only certain users or teams may push to a branch. It is
+// separate from BranchRestrictions above because the request structure is
+// different from the response structure.
+type BranchRestrictionsRequest struct {
+ // The list of user logins with push access.
+ Users *[]string `json:"users,omitempty"`
+ // The list of team slugs with push access.
+ Teams *[]string `json:"teams,omitempty"`
+}
+
// ListBranches lists branches for the specified repository.
//
// GitHub API docs: http://developer.github.com/v3/repos/#list-branches
@@ -529,6 +564,7 @@ func (s *RepositoriesService) ListBranches(owner string, repo string, opt *ListO
return nil, nil, err
}
+ // TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeProtectedBranchesPreview)
branches := new([]*Branch)
@@ -550,6 +586,7 @@ func (s *RepositoriesService) GetBranch(owner, repo, branch string) (*Branch, *R
return nil, nil, err
}
+ // TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeProtectedBranchesPreview)
b := new(Branch)
@@ -561,42 +598,81 @@ func (s *RepositoriesService) GetBranch(owner, repo, branch string) (*Branch, *R
return b, resp, err
}
-// EditBranch edits the branch (currently only Branch Protection)
+// GetBranchProtection gets the protection of a given branch.
//
-// GitHub API docs: https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection
-func (s *RepositoriesService) EditBranch(owner, repo, branchName string, branch *Branch) (*Branch, *Response, error) {
- u := fmt.Sprintf("repos/%v/%v/branches/%v", owner, repo, branchName)
- req, err := s.client.NewRequest("PATCH", u, branch)
+// GitHub API docs: https://developer.github.com/v3/repos/branches/#get-branch-protection
+func (s *RepositoriesService) GetBranchProtection(owner, repo, branch string) (*Protection, *Response, error) {
+ u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, branch)
+ req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
+ // TODO: remove custom Accept header when this API fully launches
req.Header.Set("Accept", mediaTypeProtectedBranchesPreview)
- b := new(Branch)
- resp, err := s.client.Do(req, b)
+ p := new(Protection)
+ resp, err := s.client.Do(req, p)
if err != nil {
return nil, resp, err
}
- return b, resp, err
+ return p, resp, err
+}
+
+// UpdateBranchProtection updates the protection of a given branch.
+//
+// GitHub API docs: https://developer.github.com/v3/repos/branches/#update-branch-protection
+func (s *RepositoriesService) UpdateBranchProtection(owner, repo, branch string, preq *ProtectionRequest) (*Protection, *Response, error) {
+ u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, branch)
+ req, err := s.client.NewRequest("PUT", u, preq)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ // TODO: remove custom Accept header when this API fully launches
+ req.Header.Set("Accept", mediaTypeProtectedBranchesPreview)
+
+ p := new(Protection)
+ resp, err := s.client.Do(req, p)
+ if err != nil {
+ return nil, resp, err
+ }
+
+ return p, resp, err
+}
+
+// RemoveBranchProtection removes the protection of a given branch.
+//
+// GitHub API docs: https://developer.github.com/v3/repos/branches/#remove-branch-protection
+func (s *RepositoriesService) RemoveBranchProtection(owner, repo, branch string) (*Response, error) {
+ u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, branch)
+ req, err := s.client.NewRequest("DELETE", u, nil)
+ if err != nil {
+ return nil, err
+ }
+
+ // TODO: remove custom Accept header when this API fully launches
+ req.Header.Set("Accept", mediaTypeProtectedBranchesPreview)
+
+ return s.client.Do(req, nil)
}
// License gets the contents of a repository's license if one is detected.
//
// GitHub API docs: https://developer.github.com/v3/licenses/#get-the-contents-of-a-repositorys-license
-func (s *RepositoriesService) License(owner, repo string) (*License, *Response, error) {
+func (s *RepositoriesService) License(owner, repo string) (*RepositoryLicense, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/license", owner, repo)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
- r := &Repository{}
+ r := &RepositoryLicense{}
resp, err := s.client.Do(req, r)
if err != nil {
return nil, resp, err
}
- return r.License, resp, err
+ return r, resp, err
}