|
| 1 | +// Copyright 2017 The Gitea Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package gitea |
| 6 | + |
| 7 | +import ( |
| 8 | + "fmt" |
| 9 | + "net/http" |
| 10 | + "time" |
| 11 | +) |
| 12 | + |
| 13 | +// WatchInfo represents a API watch status of one repository |
| 14 | +type WatchInfo struct { |
| 15 | + Subscribed bool `json:"subscribed"` |
| 16 | + Ignored bool `json:"ignored"` |
| 17 | + Reason interface{} `json:"reason"` |
| 18 | + CreatedAt time.Time `json:"created_at"` |
| 19 | + URL string `json:"url"` |
| 20 | + RepositoryURL string `json:"repository_url"` |
| 21 | +} |
| 22 | + |
| 23 | +// GetWatchedRepos list all the watched repos of user |
| 24 | +func (c *Client) GetWatchedRepos(user, pass string) ([]*Repository, error) { |
| 25 | + repos := make([]*Repository, 0, 10) |
| 26 | + return repos, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/subscriptions", user), |
| 27 | + http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil, &repos) |
| 28 | +} |
| 29 | + |
| 30 | +// WatchRepo start to watch a repository |
| 31 | +func (c *Client) WatchRepo(user, pass, repoUser, repoName string) (*WatchInfo, error) { |
| 32 | + i := new(WatchInfo) |
| 33 | + return i, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName), |
| 34 | + http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil, i) |
| 35 | +} |
| 36 | + |
| 37 | +// UnWatchRepo start to watch a repository |
| 38 | +func (c *Client) UnWatchRepo(user, pass, repoUser, repoName string) (int, error) { |
| 39 | + return c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName), |
| 40 | + http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil) |
| 41 | +} |
0 commit comments