mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-25 20:11:36 +01:00
0d98cbd657
* update & migrate gitea sdk (Fix Delete Tag Issue) * upgraded github.com/AlecAivazis/survey v2.2.7 => v2.2.8 * upgraded github.com/adrg/xdg v0.2.3 => v0.3.1 * upgraded github.com/araddon/dateparse * upgraded github.com/olekukonko/tablewriter v0.0.4 => v0.0.5 * upgraded gopkg.in/yaml.v2 v2.3.0 => v2.4.0 Reviewed-on: https://gitea.com/gitea/tea/pulls/337 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: khmarbaise <khmarbaise@noreply.gitea.io> Co-authored-by: 6543 <6543@obermui.de> Co-committed-by: 6543 <6543@obermui.de>
82 lines
2.7 KiB
Go
82 lines
2.7 KiB
Go
// Copyright 2021 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"
|
|
)
|
|
|
|
// ListStargazersOptions options for listing a repository's stargazers
|
|
type ListStargazersOptions struct {
|
|
ListOptions
|
|
}
|
|
|
|
// ListRepoStargazers list a repository's stargazers
|
|
func (c *Client) ListRepoStargazers(user, repo string, opt ListStargazersOptions) ([]*User, *Response, error) {
|
|
opt.setDefaults()
|
|
stargazers := make([]*User, 0, opt.PageSize)
|
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/stargazers?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &stargazers)
|
|
return stargazers, resp, err
|
|
}
|
|
|
|
// GetStarredRepos returns the repos that the given user has starred
|
|
func (c *Client) GetStarredRepos(user string) ([]*Repository, *Response, error) {
|
|
repos := make([]*Repository, 0, 10)
|
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/starred", user), jsonHeader, nil, &repos)
|
|
return repos, resp, err
|
|
}
|
|
|
|
// GetMyStarredRepos returns the repos that the authenticated user has starred
|
|
func (c *Client) GetMyStarredRepos() ([]*Repository, *Response, error) {
|
|
repos := make([]*Repository, 0, 10)
|
|
resp, err := c.getParsedResponse("GET", "/user/starred", jsonHeader, nil, &repos)
|
|
return repos, resp, err
|
|
}
|
|
|
|
// IsRepoStarring returns whether the authenticated user has starred the repo or not
|
|
func (c *Client) IsRepoStarring(user, repo string) (bool, *Response, error) {
|
|
_, resp, err := c.getResponse("GET", fmt.Sprintf("/user/starred/%s/%s", user, repo), jsonHeader, nil)
|
|
if resp != nil {
|
|
switch resp.StatusCode {
|
|
case http.StatusNotFound:
|
|
return false, resp, nil
|
|
case http.StatusNoContent:
|
|
return true, resp, nil
|
|
default:
|
|
return false, resp, fmt.Errorf("unexpected status code '%d'", resp.StatusCode)
|
|
}
|
|
}
|
|
return false, nil, err
|
|
}
|
|
|
|
// StarRepo star specified repo as the authenticated user
|
|
func (c *Client) StarRepo(user, repo string) (*Response, error) {
|
|
_, resp, err := c.getResponse("PUT", fmt.Sprintf("/user/starred/%s/%s", user, repo), jsonHeader, nil)
|
|
if resp != nil {
|
|
switch resp.StatusCode {
|
|
case http.StatusNoContent:
|
|
return resp, nil
|
|
default:
|
|
return resp, fmt.Errorf("unexpected status code '%d'", resp.StatusCode)
|
|
}
|
|
}
|
|
return nil, err
|
|
}
|
|
|
|
// UnStarRepo remove star to specified repo as the authenticated user
|
|
func (c *Client) UnStarRepo(user, repo string) (*Response, error) {
|
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/user/starred/%s/%s", user, repo), jsonHeader, nil)
|
|
if resp != nil {
|
|
switch resp.StatusCode {
|
|
case http.StatusNoContent:
|
|
return resp, nil
|
|
default:
|
|
return resp, fmt.Errorf("unexpected status code '%d'", resp.StatusCode)
|
|
}
|
|
}
|
|
return nil, err
|
|
}
|