feat: add issue time iterator
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
272de12bf0
commit
15265e4599
3 changed files with 75 additions and 14 deletions
|
|
@ -119,6 +119,7 @@ Coverage notes: rows list direct tests when a symbol is named in test names or r
|
|||
| method | IssueService.IterTimeline | `func (s *IssueService) IterTimeline(ctx context.Context, owner, repo string, index int64, since, before *time.Time) iter.Seq2[types.TimelineComment, error]` | IterTimeline returns an iterator over all comments and events on an issue. | `TestIssueService_IterTimeline_Good` |
|
||||
| method | IssueService.ListTimeline | `func (s *IssueService) ListTimeline(ctx context.Context, owner, repo string, index int64, since, before *time.Time) ([]types.TimelineComment, error)` | ListTimeline returns all comments and events on an issue. | `TestIssueService_ListTimeline_Good` |
|
||||
| method | IssueService.ListTimes | `func (s *IssueService) ListTimes(ctx context.Context, owner, repo string, index int64, user string, since, before *time.Time) ([]types.TrackedTime, error)` | ListTimes returns all tracked times on an issue. | `TestIssueService_ListTimes_Good` |
|
||||
| method | IssueService.IterTimes | `func (s *IssueService) IterTimes(ctx context.Context, owner, repo string, index int64, user string, since, before *time.Time) iter.Seq2[types.TrackedTime, error]` | IterTimes returns an iterator over all tracked times on an issue. | `TestIssueService_IterTimes_Good` |
|
||||
| method | IssueService.Pin | `func (s *IssueService) Pin(ctx context.Context, owner, repo string, index int64) error` | Pin pins an issue. | `TestIssueService_Good_Pin` |
|
||||
| method | IssueService.RemoveLabel | `func (s *IssueService) RemoveLabel(ctx context.Context, owner, repo string, index int64, labelID int64) error` | RemoveLabel removes a single label from an issue. | No direct tests. |
|
||||
| method | IssueService.SetDeadline | `func (s *IssueService) SetDeadline(ctx context.Context, owner, repo string, index int64, deadline string) error` | SetDeadline sets or updates the deadline on an issue. | No direct tests. |
|
||||
|
|
|
|||
38
issues.go
38
issues.go
|
|
@ -174,20 +174,13 @@ func (s *IssueService) DeleteStopwatch(ctx context.Context, owner, repo string,
|
|||
// ListTimes returns all tracked times on an issue.
|
||||
func (s *IssueService) ListTimes(ctx context.Context, owner, repo string, index int64, user string, since, before *time.Time) ([]types.TrackedTime, error) {
|
||||
path := ResolvePath("/api/v1/repos/{owner}/{repo}/issues/{index}/times", pathParams("owner", owner, "repo", repo, "index", int64String(index)))
|
||||
query := make(map[string]string, 3)
|
||||
if user != "" {
|
||||
query["user"] = user
|
||||
}
|
||||
if since != nil {
|
||||
query["since"] = since.Format(time.RFC3339)
|
||||
}
|
||||
if before != nil {
|
||||
query["before"] = before.Format(time.RFC3339)
|
||||
}
|
||||
if len(query) == 0 {
|
||||
query = nil
|
||||
}
|
||||
return ListAll[types.TrackedTime](ctx, s.client, path, query)
|
||||
return ListAll[types.TrackedTime](ctx, s.client, path, issueTimeQuery(user, since, before))
|
||||
}
|
||||
|
||||
// IterTimes returns an iterator over all tracked times on an issue.
|
||||
func (s *IssueService) IterTimes(ctx context.Context, owner, repo string, index int64, user string, since, before *time.Time) iter.Seq2[types.TrackedTime, error] {
|
||||
path := ResolvePath("/api/v1/repos/{owner}/{repo}/issues/{index}/times", pathParams("owner", owner, "repo", repo, "index", int64String(index)))
|
||||
return ListIter[types.TrackedTime](ctx, s.client, path, issueTimeQuery(user, since, before))
|
||||
}
|
||||
|
||||
// AddTime adds tracked time to an issue.
|
||||
|
|
@ -364,3 +357,20 @@ func toAnySlice(ids []int64) []any {
|
|||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func issueTimeQuery(user string, since, before *time.Time) map[string]string {
|
||||
query := make(map[string]string, 3)
|
||||
if user != "" {
|
||||
query["user"] = user
|
||||
}
|
||||
if since != nil {
|
||||
query["since"] = since.Format(time.RFC3339)
|
||||
}
|
||||
if before != nil {
|
||||
query["before"] = before.Format(time.RFC3339)
|
||||
}
|
||||
if len(query) == 0 {
|
||||
return nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
|
|
|||
|
|
@ -758,6 +758,56 @@ func TestIssueService_ListTimes_Good(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIssueService_IterTimes_Good(t *testing.T) {
|
||||
since := time.Date(2026, time.March, 3, 9, 15, 0, 0, time.UTC)
|
||||
before := time.Date(2026, time.March, 4, 9, 15, 0, 0, time.UTC)
|
||||
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
t.Errorf("expected GET, got %s", r.Method)
|
||||
}
|
||||
if r.URL.Path != "/api/v1/repos/core/go-forge/issues/42/times" {
|
||||
t.Errorf("wrong path: %s", r.URL.Path)
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if got := r.URL.Query().Get("user"); got != "alice" {
|
||||
t.Errorf("got user=%q, want %q", got, "alice")
|
||||
}
|
||||
if got := r.URL.Query().Get("since"); got != since.Format(time.RFC3339) {
|
||||
t.Errorf("got since=%q, want %q", got, since.Format(time.RFC3339))
|
||||
}
|
||||
if got := r.URL.Query().Get("before"); got != before.Format(time.RFC3339) {
|
||||
t.Errorf("got before=%q, want %q", got, before.Format(time.RFC3339))
|
||||
}
|
||||
if got := r.URL.Query().Get("page"); got != "1" {
|
||||
t.Errorf("got page=%q, want %q", got, "1")
|
||||
}
|
||||
if got := r.URL.Query().Get("limit"); got != "50" {
|
||||
t.Errorf("got limit=%q, want %q", got, "50")
|
||||
}
|
||||
w.Header().Set("X-Total-Count", "1")
|
||||
json.NewEncoder(w).Encode([]types.TrackedTime{
|
||||
{ID: 11, Time: 30, UserName: "alice"},
|
||||
})
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
f := NewForge(srv.URL, "tok")
|
||||
var seen []types.TrackedTime
|
||||
for entry, err := range f.Issues.IterTimes(context.Background(), "core", "go-forge", 42, "alice", &since, &before) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seen = append(seen, entry)
|
||||
}
|
||||
if !reflect.DeepEqual(seen, []types.TrackedTime{
|
||||
{ID: 11, Time: 30, UserName: "alice"},
|
||||
}) {
|
||||
t.Fatalf("got %#v", seen)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssueService_AddTime_Good(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue