Add issue timeline listing
All checks were successful
Security Scan / security (push) Successful in 11s
Test / test (push) Successful in 1m4s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-01 22:40:32 +00:00
parent 717de80cac
commit 36181a7335
3 changed files with 104 additions and 0 deletions

View file

@ -113,6 +113,8 @@ Coverage notes: rows list direct tests when a symbol is named in test names or r
| method | IssueService.DeleteReaction | `func (s *IssueService) DeleteReaction(ctx context.Context, owner, repo string, index int64, reaction string) error` | DeleteReaction removes a reaction from an issue. | No direct tests. |
| method | IssueService.IterComments | `func (s *IssueService) IterComments(ctx context.Context, owner, repo string, index int64) iter.Seq2[types.Comment, error]` | IterComments returns an iterator over all comments on an issue. | No direct tests. |
| method | IssueService.ListComments | `func (s *IssueService) ListComments(ctx context.Context, owner, repo string, index int64) ([]types.Comment, error)` | ListComments returns all comments on an issue. | No direct tests. |
| 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.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. |

View file

@ -3,6 +3,7 @@ package forge
import (
"context"
"iter"
"time"
"dappco.re/go/core/forge/types"
)
@ -118,6 +119,38 @@ func (s *IssueService) CreateComment(ctx context.Context, owner, repo string, in
return &out, nil
}
// ListTimeline returns all comments and events on an issue.
func (s *IssueService) ListTimeline(ctx context.Context, owner, repo string, index int64, since, before *time.Time) ([]types.TimelineComment, error) {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/issues/{index}/timeline", pathParams("owner", owner, "repo", repo, "index", int64String(index)))
query := make(map[string]string, 2)
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.TimelineComment](ctx, s.client, path, query)
}
// IterTimeline returns an iterator over all comments and events on an issue.
func (s *IssueService) IterTimeline(ctx context.Context, owner, repo string, index int64, since, before *time.Time) iter.Seq2[types.TimelineComment, error] {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/issues/{index}/timeline", pathParams("owner", owner, "repo", repo, "index", int64String(index)))
query := make(map[string]string, 2)
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 ListIter[types.TimelineComment](ctx, s.client, path, query)
}
// ListSubscriptions returns all users subscribed to an issue.
func (s *IssueService) ListSubscriptions(ctx context.Context, owner, repo string, index int64) ([]types.User, error) {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/issues/{index}/subscriptions", pathParams("owner", owner, "repo", repo, "index", int64String(index)))

View file

@ -7,6 +7,7 @@ import (
"net/http/httptest"
"reflect"
"testing"
"time"
"dappco.re/go/core/forge/types"
)
@ -169,6 +170,74 @@ func TestIssueService_CreateComment_Good(t *testing.T) {
}
}
func TestIssueService_ListTimeline_Good(t *testing.T) {
since := time.Date(2026, time.March, 1, 12, 30, 0, 0, time.UTC)
before := time.Date(2026, time.March, 2, 12, 30, 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/1/timeline" {
t.Errorf("wrong path: %s", r.URL.Path)
http.NotFound(w, r)
return
}
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))
}
w.Header().Set("X-Total-Count", "2")
json.NewEncoder(w).Encode([]types.TimelineComment{
{ID: 11, Type: "comment", Body: "first"},
{ID: 12, Type: "state_change", Body: "second"},
})
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
events, err := f.Issues.ListTimeline(context.Background(), "core", "go-forge", 1, &since, &before)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(events, []types.TimelineComment{
{ID: 11, Type: "comment", Body: "first"},
{ID: 12, Type: "state_change", Body: "second"},
}) {
t.Fatalf("got %#v", events)
}
}
func TestIssueService_IterTimeline_Good(t *testing.T) {
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/1/timeline" {
t.Errorf("wrong path: %s", r.URL.Path)
http.NotFound(w, r)
return
}
w.Header().Set("X-Total-Count", "1")
json.NewEncoder(w).Encode([]types.TimelineComment{{ID: 11, Type: "comment", Body: "first"}})
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
var seen []types.TimelineComment
for event, err := range f.Issues.IterTimeline(context.Background(), "core", "go-forge", 1, nil, nil) {
if err != nil {
t.Fatal(err)
}
seen = append(seen, event)
}
if !reflect.DeepEqual(seen, []types.TimelineComment{{ID: 11, Type: "comment", Body: "first"}}) {
t.Fatalf("got %#v", seen)
}
}
func TestIssueService_ListSubscriptions_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {