fix integration
This commit is contained in:
@@ -6,11 +6,19 @@ package repo
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
sourcegraph_service "code.gitea.io/gitea/services/sourcegraph"
|
||||
)
|
||||
|
||||
// sourcegraphRepoName returns the full repository name for Sourcegraph,
|
||||
// which includes the server domain prefix (e.g., "git.example.com/owner/repo")
|
||||
func sourcegraphRepoName(ctx *context.APIContext) string {
|
||||
return setting.Domain + "/" + ctx.Repo.Repository.FullName()
|
||||
}
|
||||
|
||||
// SourcegraphHover returns hover information at a position
|
||||
func SourcegraphHover(ctx *context.APIContext) {
|
||||
// swagger:operation GET /repos/{owner}/{repo}/sourcegraph/hover repository repoSourcegraphHover
|
||||
@@ -80,7 +88,7 @@ func SourcegraphHover(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := client.Hover(ctx, ctx.Repo.Repository.FullName(), ref, path, line, char)
|
||||
result, err := client.Hover(ctx, sourcegraphRepoName(ctx), ref, path, line, char)
|
||||
if err != nil {
|
||||
ctx.APIError(http.StatusBadGateway, err)
|
||||
return
|
||||
@@ -91,6 +99,14 @@ func SourcegraphHover(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
// Render markdown content to HTML
|
||||
if result.Contents != "" {
|
||||
rendered, err := markdown.RenderString(markup.NewRenderContext(ctx).WithMetas(markup.ComposeSimpleDocumentMetas()), result.Contents)
|
||||
if err == nil {
|
||||
result.Contents = string(rendered)
|
||||
}
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
@@ -163,7 +179,7 @@ func SourcegraphDefinition(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := client.Definition(ctx, ctx.Repo.Repository.FullName(), ref, path, line, char)
|
||||
result, err := client.Definition(ctx, sourcegraphRepoName(ctx), ref, path, line, char)
|
||||
if err != nil {
|
||||
ctx.APIError(http.StatusBadGateway, err)
|
||||
return
|
||||
@@ -245,7 +261,7 @@ func SourcegraphReferences(ctx *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := client.References(ctx, ctx.Repo.Repository.FullName(), ref, path, line, char)
|
||||
result, err := client.References(ctx, sourcegraphRepoName(ctx), ref, path, line, char)
|
||||
if err != nil {
|
||||
ctx.APIError(http.StatusBadGateway, err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user