Use RepositoryMeta struct on Issues (#267)
Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/go-sdk/pulls/267 Reviewed-by: lafriks <lafriks@noreply.gitea.io> Reviewed-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
3c04db72f4
commit
f84cd3442d
2 changed files with 34 additions and 5 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,6 +20,14 @@ type PullRequestMeta struct {
|
||||||
Merged *time.Time `json:"merged_at"`
|
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
|
// Issue represents an issue in a repository
|
||||||
type Issue struct {
|
type Issue struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
|
@ -41,7 +50,7 @@ type Issue struct {
|
||||||
Closed *time.Time `json:"closed_at"`
|
Closed *time.Time `json:"closed_at"`
|
||||||
Deadline *time.Time `json:"due_date"`
|
Deadline *time.Time `json:"due_date"`
|
||||||
PullRequest *PullRequestMeta `json:"pull_request"`
|
PullRequest *PullRequestMeta `json:"pull_request"`
|
||||||
Repository *Repository `json:"repository"`
|
Repository *RepositoryMeta `json:"repository"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListIssueOption list issue options
|
// ListIssueOption list issue options
|
||||||
|
@ -95,7 +104,15 @@ func (c *Client) ListIssues(opt ListIssueOption) ([]*Issue, error) {
|
||||||
link, _ := url.Parse("/repos/issues/search")
|
link, _ := url.Parse("/repos/issues/search")
|
||||||
issues := make([]*Issue, 0, 10)
|
issues := make([]*Issue, 0, 10)
|
||||||
link.RawQuery = opt.QueryEncode()
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListRepoIssues returns all issues for a given repository
|
// ListRepoIssues returns all issues for a given repository
|
||||||
|
@ -103,13 +120,25 @@ func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Iss
|
||||||
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues", owner, repo))
|
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues", owner, repo))
|
||||||
link.RawQuery = opt.QueryEncode()
|
link.RawQuery = opt.QueryEncode()
|
||||||
issues := make([]*Issue, 0, 10)
|
issues := make([]*Issue, 0, 10)
|
||||||
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
|
// GetIssue returns a single issue for a given repository
|
||||||
func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) {
|
func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) {
|
||||||
issue := new(Issue)
|
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
|
// CreateIssueOption options to create one issue
|
||||||
|
|
|
@ -89,7 +89,7 @@ func TestNotifications(t *testing.T) {
|
||||||
assert.Len(t, nList, 0)
|
assert.Len(t, nList, 0)
|
||||||
|
|
||||||
// ReadThread
|
// ReadThread
|
||||||
iState := "closed"
|
iState := StateClosed
|
||||||
c.sudo = ""
|
c.sudo = ""
|
||||||
_, err = c.EditIssue(repoB.Owner.UserName, repoB.Name, issue.Index, EditIssueOption{State: &iState})
|
_, err = c.EditIssue(repoB.Owner.UserName, repoB.Name, issue.Index, EditIssueOption{State: &iState})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
Loading…
Reference in a new issue