mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 20:27:03 +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)
75 lines
2.4 KiB
Go
Vendored
75 lines
2.4 KiB
Go
Vendored
// Copyright 2017 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"
|
|
"time"
|
|
)
|
|
|
|
// WatchInfo represents an API watch status of one repository
|
|
type WatchInfo struct {
|
|
Subscribed bool `json:"subscribed"`
|
|
Ignored bool `json:"ignored"`
|
|
Reason interface{} `json:"reason"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
URL string `json:"url"`
|
|
RepositoryURL string `json:"repository_url"`
|
|
}
|
|
|
|
// GetWatchedRepos list all the watched repos of user
|
|
func (c *Client) GetWatchedRepos(user string) ([]*Repository, *Response, error) {
|
|
repos := make([]*Repository, 0, 10)
|
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/subscriptions", user), nil, nil, &repos)
|
|
return repos, resp, err
|
|
}
|
|
|
|
// GetMyWatchedRepos list repositories watched by the authenticated user
|
|
func (c *Client) GetMyWatchedRepos() ([]*Repository, *Response, error) {
|
|
repos := make([]*Repository, 0, 10)
|
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/subscriptions"), nil, nil, &repos)
|
|
return repos, resp, err
|
|
}
|
|
|
|
// CheckRepoWatch check if the current user is watching a repo
|
|
func (c *Client) CheckRepoWatch(repoUser, repoName string) (bool, *Response, error) {
|
|
status, resp, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName), nil, nil)
|
|
if err != nil {
|
|
return false, resp, err
|
|
}
|
|
switch status {
|
|
case http.StatusNotFound:
|
|
return false, resp, nil
|
|
case http.StatusOK:
|
|
return true, resp, nil
|
|
default:
|
|
return false, resp, fmt.Errorf("unexpected Status: %d", status)
|
|
}
|
|
}
|
|
|
|
// WatchRepo start to watch a repository
|
|
func (c *Client) WatchRepo(repoUser, repoName string) (*Response, error) {
|
|
status, resp, err := c.getStatusCode("PUT", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName), nil, nil)
|
|
if err != nil {
|
|
return resp, err
|
|
}
|
|
if status == http.StatusOK {
|
|
return resp, nil
|
|
}
|
|
return resp, fmt.Errorf("unexpected Status: %d", status)
|
|
}
|
|
|
|
// UnWatchRepo stop to watch a repository
|
|
func (c *Client) UnWatchRepo(repoUser, repoName string) (*Response, error) {
|
|
status, resp, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName), nil, nil)
|
|
if err != nil {
|
|
return resp, err
|
|
}
|
|
if status == http.StatusNoContent {
|
|
return resp, nil
|
|
}
|
|
return resp, fmt.Errorf("unexpected Status: %d", status)
|
|
}
|