aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/google/go-github/github/repos_collaborators.go
diff options
context:
space:
mode:
authorhaixunlu <luhaixun@gmail.com>2018-12-18 12:49:30 -0800
committer无闻 <u@gogs.io>2018-12-18 15:49:30 -0500
commit311df9c521f05cdca880152e73dbed47afb74cde (patch)
treef3b9159e6dc23e6659e1da5939ff7f09d7a32c16 /vendor/github.com/google/go-github/github/repos_collaborators.go
parentff93d9dbda5cebe90d86e4b7dfb2c6b8642970ce (diff)
auth: add new authentication source: GitHub, including GitHub Enterprise (#5340)
* Add new Authentication Source: GitHub, including GitHub Enterprise. * Add vendor dependencies.
Diffstat (limited to 'vendor/github.com/google/go-github/github/repos_collaborators.go')
-rw-r--r--vendor/github.com/google/go-github/github/repos_collaborators.go140
1 files changed, 140 insertions, 0 deletions
diff --git a/vendor/github.com/google/go-github/github/repos_collaborators.go b/vendor/github.com/google/go-github/github/repos_collaborators.go
new file mode 100644
index 00000000..61ee9d39
--- /dev/null
+++ b/vendor/github.com/google/go-github/github/repos_collaborators.go
@@ -0,0 +1,140 @@
+// 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
+
+import (
+ "context"
+ "fmt"
+)
+
+// ListCollaboratorsOptions specifies the optional parameters to the
+// RepositoriesService.ListCollaborators method.
+type ListCollaboratorsOptions struct {
+ // Affiliation specifies how collaborators should be filtered by their affiliation.
+ // Possible values are:
+ // outside - All outside collaborators of an organization-owned repository
+ // direct - All collaborators with permissions to an organization-owned repository,
+ // regardless of organization membership status
+ // all - All collaborators the authenticated user can see
+ //
+ // Default value is "all".
+ Affiliation string `url:"affiliation,omitempty"`
+
+ ListOptions
+}
+
+// ListCollaborators lists the GitHub users that have access to the repository.
+//
+// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#list-collaborators
+func (s *RepositoriesService) ListCollaborators(ctx context.Context, owner, repo string, opt *ListCollaboratorsOptions) ([]*User, *Response, error) {
+ u := fmt.Sprintf("repos/%v/%v/collaborators", 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", mediaTypeNestedTeamsPreview)
+
+ var users []*User
+ resp, err := s.client.Do(ctx, req, &users)
+ if err != nil {
+ return nil, resp, err
+ }
+
+ return users, resp, nil
+}
+
+// IsCollaborator checks whether the specified GitHub user has collaborator
+// access to the given repo.
+// Note: This will return false if the user is not a collaborator OR the user
+// is not a GitHub user.
+//
+// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#get
+func (s *RepositoriesService) IsCollaborator(ctx context.Context, owner, repo, user string) (bool, *Response, error) {
+ u := fmt.Sprintf("repos/%v/%v/collaborators/%v", owner, repo, user)
+ req, err := s.client.NewRequest("GET", u, nil)
+ if err != nil {
+ return false, nil, err
+ }
+
+ resp, err := s.client.Do(ctx, req, nil)
+ isCollab, err := parseBoolResponse(err)
+ return isCollab, resp, err
+}
+
+// RepositoryPermissionLevel represents the permission level an organization
+// member has for a given repository.
+type RepositoryPermissionLevel struct {
+ // Possible values: "admin", "write", "read", "none"
+ Permission *string `json:"permission,omitempty"`
+
+ User *User `json:"user,omitempty"`
+}
+
+// GetPermissionLevel retrieves the specific permission level a collaborator has for a given repository.
+// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level
+func (s *RepositoriesService) GetPermissionLevel(ctx context.Context, owner, repo, user string) (*RepositoryPermissionLevel, *Response, error) {
+ u := fmt.Sprintf("repos/%v/%v/collaborators/%v/permission", owner, repo, user)
+ req, err := s.client.NewRequest("GET", u, nil)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ rpl := new(RepositoryPermissionLevel)
+ resp, err := s.client.Do(ctx, req, rpl)
+ if err != nil {
+ return nil, resp, err
+ }
+ return rpl, resp, nil
+}
+
+// RepositoryAddCollaboratorOptions specifies the optional parameters to the
+// RepositoriesService.AddCollaborator method.
+type RepositoryAddCollaboratorOptions struct {
+ // Permission specifies the permission to grant the user on this repository.
+ // Possible values are:
+ // pull - team members can pull, but not push to or administer this repository
+ // push - team members can pull and push, but not administer this repository
+ // admin - team members can pull, push and administer this repository
+ //
+ // Default value is "push". This option is only valid for organization-owned repositories.
+ Permission string `json:"permission,omitempty"`
+}
+
+// AddCollaborator sends an invitation to the specified GitHub user
+// to become a collaborator to the given repo.
+//
+// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator
+func (s *RepositoriesService) AddCollaborator(ctx context.Context, owner, repo, user string, opt *RepositoryAddCollaboratorOptions) (*Response, error) {
+ u := fmt.Sprintf("repos/%v/%v/collaborators/%v", owner, repo, user)
+ req, err := s.client.NewRequest("PUT", u, opt)
+ if err != nil {
+ return nil, err
+ }
+
+ // TODO: remove custom Accept header when this API fully launches.
+ req.Header.Set("Accept", mediaTypeRepositoryInvitationsPreview)
+
+ return s.client.Do(ctx, req, nil)
+}
+
+// RemoveCollaborator removes the specified GitHub user as collaborator from the given repo.
+// Note: Does not return error if a valid user that is not a collaborator is removed.
+//
+// GitHub API docs: https://developer.github.com/v3/repos/collaborators/#remove-collaborator
+func (s *RepositoriesService) RemoveCollaborator(ctx context.Context, owner, repo, user string) (*Response, error) {
+ u := fmt.Sprintf("repos/%v/%v/collaborators/%v", owner, repo, user)
+ req, err := s.client.NewRequest("DELETE", u, nil)
+ if err != nil {
+ return nil, err
+ }
+ return s.client.Do(ctx, req, nil)
+}