Add repo raw file helper
All checks were successful
Security Scan / security (push) Successful in 12s
Test / test (push) Successful in 1m13s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-01 22:46:14 +00:00
parent 26ea87556b
commit 1569bfea61
2 changed files with 32 additions and 0 deletions

View file

@ -185,6 +185,32 @@ func TestRepoService_GetArchive_Good(t *testing.T) {
}
}
func TestRepoService_GetRawFile_Good(t *testing.T) {
want := []byte("# go-forge\n\nA Go client for Forgejo.")
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/raw/README.md" {
t.Errorf("wrong path: %s", r.URL.Path)
http.NotFound(w, r)
return
}
w.WriteHeader(http.StatusOK)
_, _ = w.Write(want)
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
got, err := f.Repos.GetRawFile(context.Background(), "core", "go-forge", "README.md")
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(got, want) {
t.Fatalf("got %q, want %q", got, want)
}
}
func TestRepoService_ListTags_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {

View file

@ -148,6 +148,12 @@ func (s *RepoService) GetArchive(ctx context.Context, owner, repo, archive strin
return s.client.GetRaw(ctx, path)
}
// GetRawFile returns the raw content of a repository file as bytes.
func (s *RepoService) GetRawFile(ctx context.Context, owner, repo, filepath string) ([]byte, error) {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/raw/{filepath}", pathParams("owner", owner, "repo", repo, "filepath", filepath))
return s.client.GetRaw(ctx, path)
}
// ListIssueTemplates returns all issue templates available for a repository.
func (s *RepoService) ListIssueTemplates(ctx context.Context, owner, repo string) ([]types.IssueTemplate, error) {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/issue_templates", pathParams("owner", owner, "repo", repo))