From 0aa18b54fbb141d32d7163f6375278f397e5bc2f Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 28 Aug 2018 16:13:55 +0100 Subject: [PATCH 1/2] Change Collaborators List to include permissions Signed-off-by: Andrew Thornton --- gitea/repo.go | 19 +++++++++++++++++++ gitea/repo_collaborator.go | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gitea/repo.go b/gitea/repo.go index 8b7c0b1..ca1cd45 100644 --- a/gitea/repo.go +++ b/gitea/repo.go @@ -48,6 +48,25 @@ type Repository struct { Permissions *Permission `json:"permissions,omitempty"` } +// Collaborator represents a collaborator +// swagger:model +type Collaborator struct { + // the user's id + ID int64 `json:"id"` + // the user's username + UserName string `json:"login"` + // the user's full name + FullName string `json:"full_name"` + // swagger:strfmt email + Email string `json:"email"` + // URL to the user's avatar + AvatarURL string `json:"avatar_url"` + // User locale + Language string `json:"language"` + // Permissions + Permissions *Permission `json:"permissions,omitempty"` +} + // ListMyRepos lists all repositories for the authenticated user that has access to. func (c *Client) ListMyRepos() ([]*Repository, error) { repos := make([]*Repository, 0, 10) diff --git a/gitea/repo_collaborator.go b/gitea/repo_collaborator.go index bd61a22..fbcecfc 100644 --- a/gitea/repo_collaborator.go +++ b/gitea/repo_collaborator.go @@ -11,8 +11,8 @@ import ( ) // ListCollaborators list a repository's collaborators -func (c *Client) ListCollaborators(user, repo string) ([]*User, error) { - collaborators := make([]*User, 0, 10) +func (c *Client) ListCollaborators(user, repo string) ([]*Collaborator, error) { + collaborators := make([]*Collaborator, 0, 10) err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/collaborators", user, repo), nil, nil, &collaborators) From 95682dfe612ddc87a0f40978f45784775e4267a9 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 28 Aug 2018 17:09:16 +0100 Subject: [PATCH 2/2] Adjust /api/v1/repos/:owner/:repo/collaborator/:collaborator to return the permission Signed-off-by: Andrew Thornton --- gitea/repo_collaborator.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/gitea/repo_collaborator.go b/gitea/repo_collaborator.go index fbcecfc..69ee29b 100644 --- a/gitea/repo_collaborator.go +++ b/gitea/repo_collaborator.go @@ -21,16 +21,18 @@ func (c *Client) ListCollaborators(user, repo string) ([]*Collaborator, error) { // IsCollaborator check if a user is a collaborator of a repository func (c *Client) IsCollaborator(user, repo, collaborator string) (bool, error) { - status, err := c.getStatusCode("GET", + var permission *Permission + err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), - nil, nil) + nil, nil, &permission) if err != nil { - return false, err - } - if status == 204 { - return true, nil + if err.Error() == "404 Not Found" { + return false, nil + } else { + return false, err + } } - return false, nil + return (permission.Pull || permission.Push || permission.Admin), nil } // AddCollaboratorOption options when adding a user as a collaborator of a repository