From ee5cf4e4fd782519091d00dc938e24fb12a147e3 Mon Sep 17 00:00:00 2001 From: logikonline Date: Fri, 9 Jan 2026 15:30:43 -0500 Subject: [PATCH] fix: resolve build errors in v2 API and wiki service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix wiki_index.go: use WebPathToGitPath/GitPathToWebPath instead of undefined functions - Fix wiki_index.go: use gitrepo.OpenRepository pattern instead of repo.WikiPath() - Fix wiki.go: use markdown.Render instead of undefined RenderWiki - Fix wiki.go: use charset.ToUTF8WithFallbackReader instead of undefined ToUTF8Reader - Fix wiki.go: use gitrepo.CommitsCount instead of undefined wikiRepo.CommitsCount - Fix wiki.go: handle WebPathToUserTitle returning two values - Fix gofmt formatting issues in v2 API files 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- routers/api/v2/ai_context.go | 26 +++++++++++++------------- routers/api/v2/health.go | 16 ++++++++-------- routers/api/v2/operations.go | 32 ++++++++++++++++---------------- routers/api/v2/wiki.go | 19 ++++++++++--------- services/wiki/wiki_index.go | 23 ++++++++++++++--------- 5 files changed, 61 insertions(+), 55 deletions(-) diff --git a/routers/api/v2/ai_context.go b/routers/api/v2/ai_context.go index e64004b380..fb2d3717a0 100644 --- a/routers/api/v2/ai_context.go +++ b/routers/api/v2/ai_context.go @@ -64,17 +64,17 @@ type AIRepoSummaryResponse struct { // Structure overview Structure struct { - TopLevelDirs []string `json:"top_level_dirs"` - TopLevelFiles []string `json:"top_level_files"` - FileCount int `json:"total_file_count"` - Languages map[string]int64 `json:"languages"` // language -> bytes - HasReadme bool `json:"has_readme"` - ReadmePath string `json:"readme_path,omitempty"` - HasLicense bool `json:"has_license"` - LicensePath string `json:"license_path,omitempty"` - HasContrib bool `json:"has_contributing"` - ContribPath string `json:"contributing_path,omitempty"` - ConfigFiles []string `json:"config_files"` // package.json, go.mod, etc. + TopLevelDirs []string `json:"top_level_dirs"` + TopLevelFiles []string `json:"top_level_files"` + FileCount int `json:"total_file_count"` + Languages map[string]int64 `json:"languages"` // language -> bytes + HasReadme bool `json:"has_readme"` + ReadmePath string `json:"readme_path,omitempty"` + HasLicense bool `json:"has_license"` + LicensePath string `json:"license_path,omitempty"` + HasContrib bool `json:"has_contributing"` + ContribPath string `json:"contributing_path,omitempty"` + ConfigFiles []string `json:"config_files"` // package.json, go.mod, etc. } `json:"structure"` // Recent activity @@ -377,8 +377,8 @@ type AIIssueContextResponse struct { // AI hints AIHints struct { - Category string `json:"category"` // "bug", "feature", "question", etc. - Complexity string `json:"complexity"` // "simple", "moderate", "complex" + Category string `json:"category"` // "bug", "feature", "question", etc. + Complexity string `json:"complexity"` // "simple", "moderate", "complex" SuggestedFiles []string `json:"suggested_files,omitempty"` } `json:"ai_hints"` } diff --git a/routers/api/v2/health.go b/routers/api/v2/health.go index 7f80c42d2a..723bb38245 100644 --- a/routers/api/v2/health.go +++ b/routers/api/v2/health.go @@ -12,12 +12,12 @@ import ( // HealthCheckResponse represents the health check response type HealthCheckResponse struct { - Status string `json:"status"` - Version string `json:"version"` - Uptime float64 `json:"uptime_seconds"` - Timestamp string `json:"timestamp"` - Components map[string]*ComponentStatus `json:"components"` - System *health.SystemInfo `json:"system,omitempty"` + Status string `json:"status"` + Version string `json:"version"` + Uptime float64 `json:"uptime_seconds"` + Timestamp string `json:"timestamp"` + Components map[string]*ComponentStatus `json:"components"` + System *health.SystemInfo `json:"system,omitempty"` } // ComponentStatus represents a component's health status @@ -136,8 +136,8 @@ func ComponentHealthCheck(ctx *context.APIContext) { if !found { ctx.JSON(http.StatusNotFound, map[string]any{ - "code": "COMPONENT_NOT_FOUND", - "message": "Health check component not found", + "code": "COMPONENT_NOT_FOUND", + "message": "Health check component not found", "component": component, }) return diff --git a/routers/api/v2/operations.go b/routers/api/v2/operations.go index c00cb65de0..ccbd85a775 100644 --- a/routers/api/v2/operations.go +++ b/routers/api/v2/operations.go @@ -13,22 +13,22 @@ import ( // OperationProgressResponse represents an operation progress response type OperationProgressResponse struct { - OperationID string `json:"operation_id"` - Type string `json:"type"` - Status string `json:"status"` - CurrentPhase string `json:"current_phase,omitempty"` - Phases []Phase `json:"phases,omitempty"` - Progress int `json:"progress"` - BytesTotal int64 `json:"bytes_total,omitempty"` - BytesDone int64 `json:"bytes_done,omitempty"` - ItemsTotal int `json:"items_total,omitempty"` - ItemsDone int `json:"items_done,omitempty"` - Message string `json:"message,omitempty"` - Error string `json:"error,omitempty"` - StartedAt string `json:"started_at"` - UpdatedAt string `json:"updated_at"` - EstimatedETA string `json:"estimated_eta,omitempty"` - SpeedBPS int64 `json:"speed_bps,omitempty"` + OperationID string `json:"operation_id"` + Type string `json:"type"` + Status string `json:"status"` + CurrentPhase string `json:"current_phase,omitempty"` + Phases []Phase `json:"phases,omitempty"` + Progress int `json:"progress"` + BytesTotal int64 `json:"bytes_total,omitempty"` + BytesDone int64 `json:"bytes_done,omitempty"` + ItemsTotal int `json:"items_total,omitempty"` + ItemsDone int `json:"items_done,omitempty"` + Message string `json:"message,omitempty"` + Error string `json:"error,omitempty"` + StartedAt string `json:"started_at"` + UpdatedAt string `json:"updated_at"` + EstimatedETA string `json:"estimated_eta,omitempty"` + SpeedBPS int64 `json:"speed_bps,omitempty"` } // Phase represents a phase in an operation diff --git a/routers/api/v2/wiki.go b/routers/api/v2/wiki.go index 3843efbc5d..83200b710b 100644 --- a/routers/api/v2/wiki.go +++ b/routers/api/v2/wiki.go @@ -114,9 +114,10 @@ func ListWikiPagesV2(ctx *context.APIContext) { // Get last commit for this page lastCommit, _ := wikiRepo.GetCommitByPath(entry.Name()) + _, pageTitle := wiki_service.WebPathToUserTitle(wikiName) page := &api.WikiPageV2{ Name: string(wikiName), - Title: wiki_service.WebPathToUserTitle(wikiName), + Title: pageTitle, Path: entry.Name(), URL: setting.AppURL + repo.FullName() + "/wiki/" + string(wikiName), HTMLURL: setting.AppURL + repo.FullName() + "/wiki/" + string(wikiName), @@ -205,11 +206,10 @@ func GetWikiPageV2(ctx *context.APIContext) { // Render HTML var htmlContent string - if rd, err := charset.ToUTF8Reader(nil, strings.NewReader(content)); err == nil { - if buf := new(strings.Builder); buf != nil { - if err := markdown.RenderWiki(ctx, markup.NewRenderContext(ctx).WithRelativePath(gitFilename), rd, buf); err == nil { - htmlContent = buf.String() - } + rd := charset.ToUTF8WithFallbackReader(strings.NewReader(content), charset.ConvertOpts{}) + if buf := new(strings.Builder); buf != nil { + if err := markdown.Render(markup.NewRenderContext(ctx).WithRelativePath(gitFilename), rd, buf); err == nil { + htmlContent = buf.String() } } @@ -236,9 +236,10 @@ func GetWikiPageV2(ctx *context.APIContext) { linksIn = incoming } + _, pageTitle := wiki_service.WebPathToUserTitle(wikiName) page := &api.WikiPageV2{ Name: string(wikiName), - Title: wiki_service.WebPathToUserTitle(wikiName), + Title: pageTitle, Path: gitFilename, URL: setting.AppURL + "api/v2/repos/" + repo.FullName() + "/wiki/pages/" + string(wikiName), HTMLURL: setting.AppURL + repo.FullName() + "/wiki/" + string(wikiName), @@ -707,8 +708,8 @@ func GetWikiStatsV2(ctx *context.APIContext) { if err == nil && wikiRepo != nil { defer wikiRepo.Close() // Get commit count - if count, err := wikiRepo.CommitsCount(&git.CommitsCountOptions{ - Branch: repo.DefaultWikiBranch, + if count, err := gitrepo.CommitsCount(ctx, repo.WikiStorageRepo(), gitrepo.CommitsCountOptions{ + Revision: []string{repo.DefaultWikiBranch}, }); err == nil { totalCommits = count } diff --git a/services/wiki/wiki_index.go b/services/wiki/wiki_index.go index ff68962ffc..72deffaf7b 100644 --- a/services/wiki/wiki_index.go +++ b/services/wiki/wiki_index.go @@ -13,6 +13,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/log" ) @@ -30,7 +31,7 @@ func IndexWikiPage(ctx context.Context, repo *repo_model.Repository, pageName st } // Get the page content - pagePath := NameToFilename(pageName) + pagePath := WebPathToGitPath(WebPath(pageName)) entry, err := commit.GetTreeEntryByPath(pagePath) if err != nil { return err @@ -110,7 +111,11 @@ func IndexAllWikiPages(ctx context.Context, repo *repo_model.Repository) error { continue } - pageName := FilenameToName(entry.Name()) + webPath, err := GitPathToWebPath(entry.Name()) + if err != nil { + continue + } + pageName := string(webPath) if pageName == "" { continue } @@ -278,14 +283,11 @@ func GetDeadLinks(ctx context.Context, repoID int64) ([]map[string]string, error // findWikiRepoCommit opens the wiki repo and gets the latest commit func findWikiRepoCommit(ctx context.Context, repo *repo_model.Repository) (*git.Repository, *git.Commit, error) { - wikiPath := repo.WikiPath() - - if !git.IsRepoURLAccessible(ctx, wikiPath) { - return nil, nil, nil - } - - wikiRepo, err := git.OpenRepository(ctx, wikiPath) + wikiRepo, err := gitrepo.OpenRepository(ctx, repo.WikiStorageRepo()) if err != nil { + if git.IsErrNotExist(err) { + return nil, nil, nil + } return nil, nil, err } @@ -297,6 +299,9 @@ func findWikiRepoCommit(ctx context.Context, repo *repo_model.Repository) (*git. commit, err := wikiRepo.GetBranchCommit(branch) if err != nil { wikiRepo.Close() + if git.IsErrNotExist(err) { + return nil, nil, nil + } return nil, nil, err }