2016-03-14 03:18:27 +00:00
|
|
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
2019-05-11 16:38:52 +01:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2016-03-14 03:18:27 +00:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2016-11-07 01:57:49 +00:00
|
|
|
package gitea
|
2016-03-14 03:18:27 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2016-08-14 11:32:53 +01:00
|
|
|
|
2019-05-11 16:38:52 +01:00
|
|
|
"code.gitea.io/gitea/modules/structs"
|
2016-08-14 11:32:53 +01:00
|
|
|
)
|
|
|
|
|
2019-05-11 16:38:52 +01:00
|
|
|
// PullRequestMeta is equal to structs.PullRequestMeta
|
|
|
|
type PullRequestMeta = structs.PullRequestMeta
|
2016-03-14 03:18:27 +00:00
|
|
|
|
2019-05-11 16:38:52 +01:00
|
|
|
// Issue is equal to structs.Issue
|
|
|
|
type Issue = structs.Issue
|
2016-03-14 03:18:27 +00:00
|
|
|
|
2016-11-09 16:03:04 +00:00
|
|
|
// ListIssues returns all issues assigned the authenticated user
|
2019-05-11 16:38:52 +01:00
|
|
|
func (c *Client) ListIssues(opt structs.ListIssueOption) ([]*Issue, error) {
|
2016-11-09 16:03:04 +00:00
|
|
|
issues := make([]*Issue, 0, 10)
|
|
|
|
return issues, c.getParsedResponse("GET", fmt.Sprintf("/issues?page=%d", opt.Page), nil, nil, &issues)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListUserIssues returns all issues assigned to the authenticated user
|
2019-05-11 16:38:52 +01:00
|
|
|
func (c *Client) ListUserIssues(opt structs.ListIssueOption) ([]*Issue, error) {
|
2016-11-09 16:03:04 +00:00
|
|
|
issues := make([]*Issue, 0, 10)
|
|
|
|
return issues, c.getParsedResponse("GET", fmt.Sprintf("/user/issues?page=%d", opt.Page), nil, nil, &issues)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListRepoIssues returns all issues for a given repository
|
2019-05-11 16:38:52 +01:00
|
|
|
func (c *Client) ListRepoIssues(owner, repo string, opt structs.ListIssueOption) ([]*Issue, error) {
|
2016-03-14 03:18:27 +00:00
|
|
|
issues := make([]*Issue, 0, 10)
|
|
|
|
return issues, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues?page=%d", owner, repo, opt.Page), nil, nil, &issues)
|
|
|
|
}
|
|
|
|
|
2016-11-09 16:03:04 +00:00
|
|
|
// GetIssue returns a single issue for a given repository
|
2016-08-02 19:59:54 +01:00
|
|
|
func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) {
|
2016-03-14 03:18:27 +00:00
|
|
|
issue := new(Issue)
|
|
|
|
return issue, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue)
|
|
|
|
}
|
|
|
|
|
2016-11-09 16:03:04 +00:00
|
|
|
// CreateIssue create a new issue for a given repository
|
2019-05-11 16:38:52 +01:00
|
|
|
func (c *Client) CreateIssue(owner, repo string, opt structs.CreateIssueOption) (*Issue, error) {
|
2016-03-14 03:18:27 +00:00
|
|
|
body, err := json.Marshal(&opt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
issue := new(Issue)
|
|
|
|
return issue, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues", owner, repo),
|
2016-07-17 01:46:54 +01:00
|
|
|
jsonHeader, bytes.NewReader(body), issue)
|
2016-03-14 03:18:27 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 16:03:04 +00:00
|
|
|
// EditIssue modify an existing issue for a given repository
|
2019-05-11 16:38:52 +01:00
|
|
|
func (c *Client) EditIssue(owner, repo string, index int64, opt structs.EditIssueOption) (*Issue, error) {
|
2016-03-14 03:18:27 +00:00
|
|
|
body, err := json.Marshal(&opt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
issue := new(Issue)
|
|
|
|
return issue, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
|
2016-07-17 01:46:54 +01:00
|
|
|
jsonHeader, bytes.NewReader(body), issue)
|
2016-03-14 03:18:27 +00:00
|
|
|
}
|
2018-05-03 15:30:21 +01:00
|
|
|
|
2019-02-08 10:38:52 +00:00
|
|
|
// StartIssueStopWatch starts a stopwatch for an existing issue for a given
|
|
|
|
// repository
|
|
|
|
func (c *Client) StartIssueStopWatch(owner, repo string, index int64) error {
|
|
|
|
_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/start", owner, repo, index),
|
|
|
|
jsonHeader, nil)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// StopIssueStopWatch stops an existing stopwatch for an issue in a given
|
|
|
|
// repository
|
|
|
|
func (c *Client) StopIssueStopWatch(owner, repo string, index int64) error {
|
|
|
|
_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/stop", owner, repo, index),
|
|
|
|
jsonHeader, nil)
|
|
|
|
return err
|
|
|
|
}
|