mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-21 12:44:49 -05:00
Migrate WatchInfo struct to api (#1492)
* Remove WatchInfo and link to api struct * Add vendor temporary update * Return to gitea vendor source
This commit is contained in:
parent
237270ef50
commit
cf91cfb993
5 changed files with 142 additions and 18 deletions
|
@ -5,8 +5,6 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
api "code.gitea.io/sdk/gitea"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
@ -14,16 +12,6 @@ import (
|
|||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
// WatchInfo contains information about a watched 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 returns the repos that the user with the specified userID is
|
||||
// watching
|
||||
func getWatchedRepos(userID int64, private bool) ([]*api.Repository, error) {
|
||||
|
@ -67,7 +55,7 @@ func GetMyWatchedRepos(ctx *context.APIContext) {
|
|||
// specified in ctx
|
||||
func IsWatching(ctx *context.APIContext) {
|
||||
if models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID) {
|
||||
ctx.JSON(200, WatchInfo{
|
||||
ctx.JSON(200, api.WatchInfo{
|
||||
Subscribed: true,
|
||||
Ignored: false,
|
||||
Reason: nil,
|
||||
|
@ -87,7 +75,7 @@ func Watch(ctx *context.APIContext) {
|
|||
ctx.Error(500, "WatchRepo", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, WatchInfo{
|
||||
ctx.JSON(200, api.WatchInfo{
|
||||
Subscribed: true,
|
||||
Ignored: false,
|
||||
Reason: nil,
|
||||
|
|
2
vendor/code.gitea.io/sdk/gitea/issue_comment.go
generated
vendored
2
vendor/code.gitea.io/sdk/gitea/issue_comment.go
generated
vendored
|
@ -47,7 +47,7 @@ func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateI
|
|||
return nil, err
|
||||
}
|
||||
comment := new(Comment)
|
||||
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
|
||||
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
|
||||
}
|
||||
|
||||
// EditIssueCommentOption is option when editing an issue comment.
|
||||
|
|
41
vendor/code.gitea.io/sdk/gitea/repo_watch.go
generated
vendored
Normal file
41
vendor/code.gitea.io/sdk/gitea/repo_watch.go
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
// 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 a 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, pass string) ([]*Repository, error) {
|
||||
repos := make([]*Repository, 0, 10)
|
||||
return repos, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/subscriptions", user),
|
||||
http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil, &repos)
|
||||
}
|
||||
|
||||
// WatchRepo start to watch a repository
|
||||
func (c *Client) WatchRepo(user, pass, repoUser, repoName string) (*WatchInfo, error) {
|
||||
i := new(WatchInfo)
|
||||
return i, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName),
|
||||
http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil, i)
|
||||
}
|
||||
|
||||
// UnWatchRepo start to watch a repository
|
||||
func (c *Client) UnWatchRepo(user, pass, repoUser, repoName string) (int, error) {
|
||||
return c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/subscription", repoUser, repoName),
|
||||
http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil)
|
||||
}
|
95
vendor/code.gitea.io/sdk/gitea/status.go
generated
vendored
Normal file
95
vendor/code.gitea.io/sdk/gitea/status.go
generated
vendored
Normal file
|
@ -0,0 +1,95 @@
|
|||
// 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 (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// StatusState holds the state of a Status
|
||||
// It can be "pending", "success", "error", "failure", and "warning"
|
||||
type StatusState string
|
||||
|
||||
const (
|
||||
// StatusPending is for when the Status is Pending
|
||||
StatusPending StatusState = "pending"
|
||||
// StatusSuccess is for when the Status is Success
|
||||
StatusSuccess StatusState = "success"
|
||||
// StatusError is for when the Status is Error
|
||||
StatusError StatusState = "error"
|
||||
// StatusFailure is for when the Status is Failure
|
||||
StatusFailure StatusState = "failure"
|
||||
// StatusWarning is for when the Status is Warning
|
||||
StatusWarning StatusState = "warning"
|
||||
)
|
||||
|
||||
// Status holds a single Status of a single Commit
|
||||
type Status struct {
|
||||
ID int64 `json:"id"`
|
||||
State StatusState `json:"status"`
|
||||
TargetURL string `json:"target_url"`
|
||||
Description string `json:"description"`
|
||||
URL string `json:"url"`
|
||||
Context string `json:"context"`
|
||||
Creator *User `json:"creator"`
|
||||
Created time.Time `json:"created_at"`
|
||||
Updated time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// CombinedStatus holds the combined state of several statuses for a single commit
|
||||
type CombinedStatus struct {
|
||||
State StatusState `json:"state"`
|
||||
SHA string `json:"sha"`
|
||||
TotalCount int `json:"total_count"`
|
||||
Statuses []*Status `json:"statuses"`
|
||||
Repository *Repository `json:"repository"`
|
||||
CommitURL string `json:"commit_url"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// CreateStatusOption holds the information needed to create a new Status for a Commit
|
||||
type CreateStatusOption struct {
|
||||
State StatusState `json:"state"`
|
||||
TargetURL string `json:"target_url"`
|
||||
Description string `json:"description"`
|
||||
Context string `json:"context"`
|
||||
}
|
||||
|
||||
// ListStatusesOption holds pagination information
|
||||
type ListStatusesOption struct {
|
||||
Page int
|
||||
}
|
||||
|
||||
// CreateStatus creates a new Status for a given Commit
|
||||
//
|
||||
// POST /repos/:owner/:repo/statuses/:sha
|
||||
func (c *Client) CreateStatus(owner, repo, sha string, opts CreateStatusOption) (*Status, error) {
|
||||
body, err := json.Marshal(&opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
status := &Status{}
|
||||
return status, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/statuses/%s", owner, repo, sha),
|
||||
jsonHeader, bytes.NewReader(body), status)
|
||||
}
|
||||
|
||||
// ListStatuses returns all statuses for a given Commit
|
||||
//
|
||||
// GET /repos/:owner/:repo/commits/:ref/statuses
|
||||
func (c *Client) ListStatuses(owner, repo, sha string, opts ListStatusesOption) ([]*Status, error) {
|
||||
statuses := make([]*Status, 0, 10)
|
||||
return statuses, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/statuses?page=%d", owner, repo, sha, opts.Page), nil, nil, &statuses)
|
||||
}
|
||||
|
||||
// GetCombinedStatus returns the CombinedStatus for a given Commit
|
||||
//
|
||||
// GET /repos/:owner/:repo/commits/:ref/status
|
||||
func (c *Client) GetCombinedStatus(owner, repo, sha string) (*CombinedStatus, error) {
|
||||
status := &CombinedStatus{}
|
||||
return status, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s/status", owner, repo, sha), nil, nil, status)
|
||||
}
|
6
vendor/vendor.json
vendored
6
vendor/vendor.json
vendored
|
@ -9,10 +9,10 @@
|
|||
"revisionTime": "2017-04-07T07:44:04Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "32qRX47gRmdBW4l4hCKGRZbuIJk=",
|
||||
"checksumSHA1": "7/pZpgSIh/M76hwvldhgRqege/Q=",
|
||||
"path": "code.gitea.io/sdk/gitea",
|
||||
"revision": "9ceaabb8c70aba1ff73718332db2356356e26ffb",
|
||||
"revisionTime": "2017-03-09T22:08:57Z"
|
||||
"revision": "cad003b49151391f9a22f2e2edb2f348f51f9dde",
|
||||
"revisionTime": "2017-04-15T14:32:48Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "IyfS7Rbl6OgR83QR7TOfKdDCq+M=",
|
||||
|
|
Loading…
Reference in a new issue