Add repository activity feed listing
All checks were successful
Security Scan / security (push) Successful in 11s
Test / test (push) Successful in 1m31s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 01:46:07 +00:00
parent c7809c0dc7
commit 3ed3ecaf3d
2 changed files with 78 additions and 0 deletions

View file

@ -6,6 +6,7 @@ import (
"net/http"
"net/url"
"strconv"
"time"
"dappco.re/go/core/forge/types"
)
@ -40,6 +41,20 @@ func (o RepoKeyListOptions) queryParams() map[string]string {
return query
}
// ActivityFeedListOptions controls filtering for repository activity feeds.
type ActivityFeedListOptions struct {
Date *time.Time
}
func (o ActivityFeedListOptions) queryParams() map[string]string {
if o.Date == nil {
return nil
}
return map[string]string{
"date": o.Date.Format("2006-01-02"),
}
}
func newRepoService(c *Client) *RepoService {
return &RepoService{
Resource: *NewResource[types.Repository, types.CreateRepoOption, types.EditRepoOption](
@ -359,6 +374,18 @@ func (s *RepoService) ListIssueTemplates(ctx context.Context, owner, repo string
return ListAll[types.IssueTemplate](ctx, s.client, path, nil)
}
// ListActivityFeeds returns the repository's activity feed entries.
func (s *RepoService) ListActivityFeeds(ctx context.Context, owner, repo string, filters ...ActivityFeedListOptions) ([]types.Activity, error) {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/activities/feeds", pathParams("owner", owner, "repo", repo))
return ListAll[types.Activity](ctx, s.client, path, activityFeedQuery(filters...))
}
// IterActivityFeeds returns an iterator over the repository's activity feed entries.
func (s *RepoService) IterActivityFeeds(ctx context.Context, owner, repo string, filters ...ActivityFeedListOptions) iter.Seq2[types.Activity, error] {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/activities/feeds", pathParams("owner", owner, "repo", repo))
return ListIter[types.Activity](ctx, s.client, path, activityFeedQuery(filters...))
}
// ListTopics returns the topics assigned to a repository.
func (s *RepoService) ListTopics(ctx context.Context, owner, repo string) ([]string, error) {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/topics", pathParams("owner", owner, "repo", repo))
@ -673,3 +700,20 @@ func repoKeyQuery(filters ...RepoKeyListOptions) map[string]string {
}
return query
}
func activityFeedQuery(filters ...ActivityFeedListOptions) map[string]string {
if len(filters) == 0 {
return nil
}
query := make(map[string]string, 1)
for _, filter := range filters {
if filter.Date != nil {
query["date"] = filter.Date.Format("2006-01-02")
}
}
if len(query) == 0 {
return nil
}
return query
}

View file

@ -8,10 +8,44 @@ import (
"net/http/httptest"
"reflect"
"testing"
"time"
"dappco.re/go/core/forge/types"
)
func TestRepoService_ListActivityFeeds_Good(t *testing.T) {
date := time.Date(2026, time.April, 2, 15, 4, 5, 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/activities/feeds" {
t.Errorf("wrong path: %s", r.URL.Path)
http.NotFound(w, r)
return
}
if got := r.URL.Query().Get("date"); got != "2026-04-02" {
t.Errorf("wrong date: %s", got)
}
w.Header().Set("X-Total-Count", "1")
json.NewEncoder(w).Encode([]types.Activity{{
ID: 7,
OpType: "create_repo",
Content: "created repository",
}})
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
activities, err := f.Repos.ListActivityFeeds(context.Background(), "core", "go-forge", ActivityFeedListOptions{Date: &date})
if err != nil {
t.Fatal(err)
}
if len(activities) != 1 || activities[0].ID != 7 || activities[0].OpType != "create_repo" {
t.Fatalf("got %#v", activities)
}
}
func TestRepoService_ListTopics_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {