2024-02-23 00:26:49 +00:00
|
|
|
// Copyright 2024 The Forgjo Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-01-09 19:04:15 +00:00
|
|
|
// 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.
|
|
|
|
|
2024-02-23 00:26:49 +00:00
|
|
|
package forgejo
|
2020-01-09 19:04:15 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// StopWatch represents a running stopwatch of an issue / pr
|
|
|
|
type StopWatch struct {
|
2021-02-13 19:24:00 +00:00
|
|
|
Created time.Time `json:"created"`
|
|
|
|
Seconds int64 `json:"seconds"`
|
|
|
|
Duration string `json:"duration"`
|
|
|
|
IssueIndex int64 `json:"issue_index"`
|
|
|
|
IssueTitle string `json:"issue_title"`
|
|
|
|
RepoOwnerName string `json:"repo_owner_name"`
|
|
|
|
RepoName string `json:"repo_name"`
|
2020-01-09 19:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetMyStopwatches list all stopwatches
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) GetMyStopwatches() ([]*StopWatch, *Response, error) {
|
2020-01-09 19:04:15 +00:00
|
|
|
stopwatches := make([]*StopWatch, 0, 1)
|
2020-09-14 03:37:09 +01:00
|
|
|
resp, err := c.getParsedResponse("GET", "/user/stopwatches", nil, nil, &stopwatches)
|
|
|
|
return stopwatches, resp, err
|
2020-01-09 19:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteIssueStopwatch delete / cancel a specific stopwatch
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) DeleteIssueStopwatch(owner, repo string, index int64) (*Response, error) {
|
2021-03-21 20:20:32 +00:00
|
|
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-14 03:37:09 +01:00
|
|
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/delete", owner, repo, index), nil, nil)
|
|
|
|
return resp, err
|
2020-01-09 19:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StartIssueStopWatch starts a stopwatch for an existing issue for a given
|
|
|
|
// repository
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) StartIssueStopWatch(owner, repo string, index int64) (*Response, error) {
|
2021-03-21 20:20:32 +00:00
|
|
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-14 03:37:09 +01:00
|
|
|
_, resp, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/start", owner, repo, index), nil, nil)
|
|
|
|
return resp, err
|
2020-01-09 19:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// StopIssueStopWatch stops an existing stopwatch for an issue in a given
|
|
|
|
// repository
|
2020-09-14 03:37:09 +01:00
|
|
|
func (c *Client) StopIssueStopWatch(owner, repo string, index int64) (*Response, error) {
|
2021-03-21 20:20:32 +00:00
|
|
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-14 03:37:09 +01:00
|
|
|
_, resp, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/stop", owner, repo, index), nil, nil)
|
|
|
|
return resp, err
|
2020-01-09 19:04:15 +00:00
|
|
|
}
|