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)