mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-18 08:39:47 +01:00
49b1948cb1
* first draft
* update gitea sdk to 9e280adb4da
* adapt feat of updated sdk
* releases now works
* break the Reactions loop
* use convertGiteaLabel
* fix endless loop because paggination is not supported there !!!
* rename gitea local uploader files
* pagination can bite you in the ass
* Version Checks
* lint
* docs
* rename gitea sdk import to miss future conficts
* go-swagger: dont scan the sdk structs
* make sure gitea can shutdown gracefully
* make GetPullRequests and GetIssues similar
* rm useles
* Add Test: started ...
* ... add tests ...
* Add tests and Fixing things
* Workaround missing SHA
* Adapt: Ensure that all migration requests are cancellable
(714ab71ddc
)
* LINT: fix misspells in test set
* adapt ListMergeRequestAwardEmoji
* update sdk
* Return error when creating giteadownloader failed
* update sdk
* adapt new sdk
* adopt new features
* check version before err
* adapt: 'migrate service type switch page'
* optimize
* Fix DefaultBranch
* impruve
* handle subPath
* fix test
* Fix ReviewCommentPosition
* test GetReviews
* add DefaultBranch int test set
* rm unused
* Update SDK to v0.13.0
* addopt sdk changes
* found better link
* format template
* Update Docs
* Update Gitea SDK (v0.13.1)
101 lines
3.3 KiB
Go
Vendored
101 lines
3.3 KiB
Go
Vendored
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package gitea
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
// DeleteOrgMembership remove a member from an organization
|
|
func (c *Client) DeleteOrgMembership(org, user string) (*Response, error) {
|
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/orgs/%s/members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
|
return resp, err
|
|
}
|
|
|
|
// ListOrgMembershipOption list OrgMembership options
|
|
type ListOrgMembershipOption struct {
|
|
ListOptions
|
|
}
|
|
|
|
// ListOrgMembership list an organization's members
|
|
func (c *Client) ListOrgMembership(org string, opt ListOrgMembershipOption) ([]*User, *Response, error) {
|
|
opt.setDefaults()
|
|
users := make([]*User, 0, opt.PageSize)
|
|
|
|
link, _ := url.Parse(fmt.Sprintf("/orgs/%s/members", url.PathEscape(org)))
|
|
link.RawQuery = opt.getURLQuery().Encode()
|
|
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &users)
|
|
return users, resp, err
|
|
}
|
|
|
|
// ListPublicOrgMembership list an organization's members
|
|
func (c *Client) ListPublicOrgMembership(org string, opt ListOrgMembershipOption) ([]*User, *Response, error) {
|
|
opt.setDefaults()
|
|
users := make([]*User, 0, opt.PageSize)
|
|
|
|
link, _ := url.Parse(fmt.Sprintf("/orgs/%s/public_members", url.PathEscape(org)))
|
|
link.RawQuery = opt.getURLQuery().Encode()
|
|
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &users)
|
|
return users, resp, err
|
|
}
|
|
|
|
// CheckOrgMembership Check if a user is a member of an organization
|
|
func (c *Client) CheckOrgMembership(org, user string) (bool, *Response, error) {
|
|
status, resp, err := c.getStatusCode("GET", fmt.Sprintf("/orgs/%s/members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
|
if err != nil {
|
|
return false, resp, err
|
|
}
|
|
switch status {
|
|
case http.StatusNoContent:
|
|
return true, resp, nil
|
|
case http.StatusNotFound:
|
|
return false, resp, nil
|
|
default:
|
|
return false, resp, fmt.Errorf("unexpected Status: %d", status)
|
|
}
|
|
}
|
|
|
|
// CheckPublicOrgMembership Check if a user is a member of an organization
|
|
func (c *Client) CheckPublicOrgMembership(org, user string) (bool, *Response, error) {
|
|
status, resp, err := c.getStatusCode("GET", fmt.Sprintf("/orgs/%s/public_members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
|
if err != nil {
|
|
return false, resp, err
|
|
}
|
|
switch status {
|
|
case http.StatusNoContent:
|
|
return true, resp, nil
|
|
case http.StatusNotFound:
|
|
return false, resp, nil
|
|
default:
|
|
return false, resp, fmt.Errorf("unexpected Status: %d", status)
|
|
}
|
|
}
|
|
|
|
// SetPublicOrgMembership publicize/conceal a user's membership
|
|
func (c *Client) SetPublicOrgMembership(org, user string, visible bool) (*Response, error) {
|
|
var (
|
|
status int
|
|
err error
|
|
resp *Response
|
|
)
|
|
if visible {
|
|
status, resp, err = c.getStatusCode("PUT", fmt.Sprintf("/orgs/%s/public_members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
|
} else {
|
|
status, resp, err = c.getStatusCode("DELETE", fmt.Sprintf("/orgs/%s/public_members/%s", url.PathEscape(org), url.PathEscape(user)), nil, nil)
|
|
}
|
|
if err != nil {
|
|
return resp, err
|
|
}
|
|
switch status {
|
|
case http.StatusNoContent:
|
|
return resp, nil
|
|
case http.StatusNotFound:
|
|
return resp, fmt.Errorf("forbidden")
|
|
default:
|
|
return resp, fmt.Errorf("unexpected Status: %d", status)
|
|
}
|
|
}
|