From 4f17bb0fbc93ce02d7cb88f3646e87f2ea35c4de Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Thu, 9 Jan 2020 19:04:15 +0000 Subject: [PATCH] [Extend] StopWatch struct & functions (#211) add StopWatch struct & functions [Add] reaction struct and functions (#213) add struct and functions Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton Reviewed-by: techknowlogick [Add] issue Un-/Subscription function (#214) fix lint add issue subscription function Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton Reviewed-by: techknowlogick [Add] GetBlob (#212) fix header from PR 206 add GetBlob Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Lunny Xiao Reviewed-by: Andrew Thornton Co-authored-by: 6543 <6543@obermui.de> Reviewed-by: Andrew Thornton Reviewed-by: techknowlogick --- gitea/issue.go | 16 --------------- gitea/issue_stopwatch.go | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 gitea/issue_stopwatch.go diff --git a/gitea/issue.go b/gitea/issue.go index 35c1a1b..f1711f6 100644 --- a/gitea/issue.go +++ b/gitea/issue.go @@ -119,19 +119,3 @@ func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption) return issue, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), jsonHeader, bytes.NewReader(body), issue) } - -// 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 -} diff --git a/gitea/issue_stopwatch.go b/gitea/issue_stopwatch.go new file mode 100644 index 0000000..8b8f178 --- /dev/null +++ b/gitea/issue_stopwatch.go @@ -0,0 +1,42 @@ +// Copyright 2020 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" + "time" +) + +// StopWatch represents a running stopwatch of an issue / pr +type StopWatch struct { + Created time.Time `json:"created"` + IssueIndex int64 `json:"issue_index"` +} + +// GetMyStopwatches list all stopwatches +func (c *Client) GetMyStopwatches() ([]*StopWatch, error) { + stopwatches := make([]*StopWatch, 0, 1) + return stopwatches, c.getParsedResponse("GET", "/user/stopwatches", nil, nil, &stopwatches) +} + +// DeleteIssueStopwatch delete / cancel a specific stopwatch +func (c *Client) DeleteIssueStopwatch(owner, repo string, index int64) error { + _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/delete", owner, repo, index), nil, nil) + return err +} + +// 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), nil, 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), nil, nil) + return err +}