mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-19 10:12:54 +02:00
Migrate gitea-sdk to v0.12.0 (#133)
Migrate Update code.gitea.io/sdk/gitea to v0.12.0. Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/133 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
118
vendor/code.gitea.io/sdk/gitea/issue.go
generated
vendored
118
vendor/code.gitea.io/sdk/gitea/issue.go
generated
vendored
@ -10,6 +10,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -19,6 +20,14 @@ type PullRequestMeta struct {
|
||||
Merged *time.Time `json:"merged_at"`
|
||||
}
|
||||
|
||||
// RepositoryMeta basic repository information
|
||||
type RepositoryMeta struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Owner string `json:"owner"`
|
||||
FullName string `json:"full_name"`
|
||||
}
|
||||
|
||||
// Issue represents an issue in a repository
|
||||
type Issue struct {
|
||||
ID int64 `json:"id"`
|
||||
@ -41,18 +50,31 @@ type Issue struct {
|
||||
Closed *time.Time `json:"closed_at"`
|
||||
Deadline *time.Time `json:"due_date"`
|
||||
PullRequest *PullRequestMeta `json:"pull_request"`
|
||||
Repository *RepositoryMeta `json:"repository"`
|
||||
}
|
||||
|
||||
// ListIssueOption list issue options
|
||||
type ListIssueOption struct {
|
||||
Page int
|
||||
// open, closed, all
|
||||
State string
|
||||
Type IssueType
|
||||
Labels []string
|
||||
KeyWord string
|
||||
ListOptions
|
||||
State StateType
|
||||
Type IssueType
|
||||
Labels []string
|
||||
Milestones []string
|
||||
KeyWord string
|
||||
}
|
||||
|
||||
// StateType issue state type
|
||||
type StateType string
|
||||
|
||||
const (
|
||||
// StateOpen pr/issue is opend
|
||||
StateOpen StateType = "open"
|
||||
// StateClosed pr/issue is closed
|
||||
StateClosed StateType = "closed"
|
||||
// StateAll is all
|
||||
StateAll StateType = "all"
|
||||
)
|
||||
|
||||
// IssueType is issue a pull or only an issue
|
||||
type IssueType string
|
||||
|
||||
@ -67,79 +89,73 @@ const (
|
||||
|
||||
// QueryEncode turns options into querystring argument
|
||||
func (opt *ListIssueOption) QueryEncode() string {
|
||||
query := make(url.Values)
|
||||
if opt.Page > 0 {
|
||||
query.Add("page", fmt.Sprintf("%d", opt.Page))
|
||||
}
|
||||
query := opt.getURLQuery()
|
||||
|
||||
if len(opt.State) > 0 {
|
||||
query.Add("state", opt.State)
|
||||
query.Add("state", string(opt.State))
|
||||
}
|
||||
|
||||
if opt.Page > 0 {
|
||||
query.Add("page", fmt.Sprintf("%d", opt.Page))
|
||||
}
|
||||
if len(opt.State) > 0 {
|
||||
query.Add("state", opt.State)
|
||||
}
|
||||
if len(opt.Labels) > 0 {
|
||||
var lq string
|
||||
for _, l := range opt.Labels {
|
||||
if len(lq) > 0 {
|
||||
lq += ","
|
||||
}
|
||||
lq += l
|
||||
}
|
||||
query.Add("labels", lq)
|
||||
query.Add("labels", strings.Join(opt.Labels, ","))
|
||||
}
|
||||
|
||||
if len(opt.KeyWord) > 0 {
|
||||
query.Add("q", opt.KeyWord)
|
||||
}
|
||||
|
||||
query.Add("type", string(opt.Type))
|
||||
|
||||
if len(opt.Milestones) > 0 {
|
||||
query.Add("milestones", strings.Join(opt.Milestones, ","))
|
||||
}
|
||||
|
||||
return query.Encode()
|
||||
}
|
||||
|
||||
// ListIssues returns all issues assigned the authenticated user
|
||||
func (c *Client) ListIssues(opt ListIssueOption) ([]*Issue, error) {
|
||||
link, _ := url.Parse("/repos/issues/search")
|
||||
issues := make([]*Issue, 0, 10)
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
return issues, c.getParsedResponse("GET", link.String(), jsonHeader, nil, &issues)
|
||||
}
|
||||
opt.setDefaults()
|
||||
issues := make([]*Issue, 0, opt.PageSize)
|
||||
|
||||
// ListUserIssues returns all issues assigned to the authenticated user
|
||||
func (c *Client) ListUserIssues(opt ListIssueOption) ([]*Issue, error) {
|
||||
// WARNING: "/user/issues" API is not implemented jet!
|
||||
allIssues, err := c.ListIssues(opt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user, err := c.GetMyUserInfo()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Workaround: client sort out non user related issues
|
||||
issues := make([]*Issue, 0, 10)
|
||||
for _, i := range allIssues {
|
||||
if i.ID == user.ID {
|
||||
issues = append(issues, i)
|
||||
link, _ := url.Parse("/repos/issues/search")
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &issues)
|
||||
if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil {
|
||||
for i := 0; i < len(issues); i++ {
|
||||
if issues[i].Repository != nil {
|
||||
issues[i].Repository.Owner = strings.Split(issues[i].Repository.FullName, "/")[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
return issues, nil
|
||||
return issues, err
|
||||
}
|
||||
|
||||
// ListRepoIssues returns all issues for a given repository
|
||||
func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) {
|
||||
opt.setDefaults()
|
||||
issues := make([]*Issue, 0, opt.PageSize)
|
||||
|
||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues", owner, repo))
|
||||
issues := make([]*Issue, 0, 10)
|
||||
link.RawQuery = opt.QueryEncode()
|
||||
return issues, c.getParsedResponse("GET", link.String(), jsonHeader, nil, &issues)
|
||||
err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &issues)
|
||||
if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil {
|
||||
for i := 0; i < len(issues); i++ {
|
||||
if issues[i].Repository != nil {
|
||||
issues[i].Repository.Owner = strings.Split(issues[i].Repository.FullName, "/")[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
return issues, err
|
||||
}
|
||||
|
||||
// GetIssue returns a single issue for a given repository
|
||||
func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) {
|
||||
issue := new(Issue)
|
||||
return issue, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue)
|
||||
err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue)
|
||||
if e := c.CheckServerVersionConstraint(">=1.12.0"); e != nil && issue.Repository != nil {
|
||||
issue.Repository.Owner = strings.Split(issue.Repository.FullName, "/")[0]
|
||||
}
|
||||
return issue, err
|
||||
}
|
||||
|
||||
// CreateIssueOption options to create one issue
|
||||
@ -175,7 +191,7 @@ type EditIssueOption struct {
|
||||
Assignee *string `json:"assignee"`
|
||||
Assignees []string `json:"assignees"`
|
||||
Milestone *int64 `json:"milestone"`
|
||||
State *string `json:"state"`
|
||||
State *StateType `json:"state"`
|
||||
Deadline *time.Time `json:"due_date"`
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user