feat(repos): add editorconfig endpoint
All checks were successful
Security Scan / security (push) Successful in 15s
Test / test (push) Successful in 1m42s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 03:13:29 +00:00
parent 628de4704b
commit 11e614af4a
2 changed files with 52 additions and 0 deletions

View file

@ -383,6 +383,22 @@ func (s *RepoService) GetRawFileOrLFS(ctx context.Context, owner, repo, filepath
return s.client.GetRaw(ctx, path)
}
// GetEditorConfig returns the EditorConfig definitions for a repository file.
func (s *RepoService) GetEditorConfig(ctx context.Context, owner, repo, filepath, ref string) error {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/editorconfig/{filepath}", pathParams("owner", owner, "repo", repo, "filepath", filepath))
if ref != "" {
u, err := url.Parse(path)
if err != nil {
return err
}
q := u.Query()
q.Set("ref", ref)
u.RawQuery = q.Encode()
path = u.String()
}
return s.client.Get(ctx, path, nil)
}
// ApplyDiffPatch applies a diff patch to a repository.
func (s *RepoService) ApplyDiffPatch(ctx context.Context, owner, repo string, opts *types.UpdateFileOptions) (*types.FileResponse, error) {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/diffpatch", pathParams("owner", owner, "repo", repo))

View file

@ -573,6 +573,42 @@ func TestRepoService_GetRawFileOrLFS_Good(t *testing.T) {
}
}
func TestRepoService_GetEditorConfig_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/editorconfig/README.md" {
t.Errorf("wrong path: %s", r.URL.Path)
http.NotFound(w, r)
return
}
if got := r.URL.Query().Get("ref"); got != "main" {
t.Errorf("wrong ref: %s", got)
}
w.WriteHeader(http.StatusOK)
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
if err := f.Repos.GetEditorConfig(context.Background(), "core", "go-forge", "README.md", "main"); err != nil {
t.Fatal(err)
}
}
func TestRepoService_GetEditorConfig_Bad_NotFound(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(map[string]string{"message": "not found"})
}))
defer srv.Close()
f := NewForge(srv.URL, "tok")
if err := f.Repos.GetEditorConfig(context.Background(), "core", "go-forge", "README.md", "main"); !IsNotFound(err) {
t.Fatalf("expected not found, got %v", err)
}
}
func TestRepoService_ApplyDiffPatch_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {