From 7b42de67ca062bb0392e3dc7c1d8fe0a0620af94 Mon Sep 17 00:00:00 2001 From: Rodin Date: Fri, 1 May 2026 14:46:40 -0700 Subject: [PATCH] fix: handle empty path in ListContents (root listing) Empty path now yields /contents instead of /contents/ (trailing slash). Added doc comment noting empty path = repo root. --- gitea/client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gitea/client.go b/gitea/client.go index c2060fc..9653a18 100644 --- a/gitea/client.go +++ b/gitea/client.go @@ -204,8 +204,14 @@ type ContentEntry struct { } // ListContents lists files and directories at a given path in a repo. +// Pass an empty path to list the repository root. func (c *Client) ListContents(ctx context.Context, owner, repo, path string) ([]ContentEntry, error) { - reqURL := fmt.Sprintf("%s/api/v1/repos/%s/%s/contents/%s", c.baseURL, owner, repo, escapePath(path)) + var reqURL string + if path == "" { + reqURL = fmt.Sprintf("%s/api/v1/repos/%s/%s/contents", c.baseURL, owner, repo) + } else { + reqURL = fmt.Sprintf("%s/api/v1/repos/%s/%s/contents/%s", c.baseURL, owner, repo, escapePath(path)) + } body, err := c.doGet(ctx, reqURL) if err != nil { return nil, fmt.Errorf("list contents %s: %w", path, err)