Skip to content

Use repo as of renderctx's member rather than a repoPath on metas #29222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
use repo as of renderctx's member rather than a repoPath on metas
  • Loading branch information
lunny committed Feb 17, 2024
commit 635d188e77acb97c9c5841d3db41a35130a185c3
3 changes: 2 additions & 1 deletion models/issues/comment_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu

var err error
if comment.RenderedContent, err = markdown.RenderString(&markup.RenderContext{
Ctx: ctx,
Ctx: ctx,
Repo: issue.Repo,
Links: markup.Links{
Base: issue.Repo.Link(),
},
Expand Down
7 changes: 3 additions & 4 deletions models/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,9 @@ func (repo *Repository) MustOwner(ctx context.Context) *user_model.User {
func (repo *Repository) ComposeMetas(ctx context.Context) map[string]string {
if len(repo.RenderingMetas) == 0 {
metas := map[string]string{
"user": repo.OwnerName,
"repo": repo.Name,
"repoPath": repo.RepoPath(),
"mode": "comment",
"user": repo.OwnerName,
"repo": repo.Name,
"mode": "comment",
}

unit, err := repo.GetUnit(ctx, unit.TypeExternalTracker)
Expand Down
6 changes: 3 additions & 3 deletions modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/emoji"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup/common"
"code.gitea.io/gitea/modules/references"
Expand Down Expand Up @@ -1114,7 +1114,7 @@ func emojiProcessor(ctx *RenderContext, node *html.Node) {
// hashCurrentPatternProcessor renders SHA1 strings to corresponding links that
// are assumed to be in the same repository.
func hashCurrentPatternProcessor(ctx *RenderContext, node *html.Node) {
if ctx.Metas == nil || ctx.Metas["user"] == "" || ctx.Metas["repo"] == "" || ctx.Metas["repoPath"] == "" {
if ctx.Metas == nil || ctx.Metas["user"] == "" || ctx.Metas["repo"] == "" || (ctx.Repo == nil && ctx.GitRepo == nil) {
return
}

Expand Down Expand Up @@ -1146,7 +1146,7 @@ func hashCurrentPatternProcessor(ctx *RenderContext, node *html.Node) {
if !inCache {
if ctx.GitRepo == nil {
var err error
ctx.GitRepo, err = git.OpenRepository(ctx.Ctx, ctx.Metas["repoPath"])
ctx.GitRepo, _, err = gitrepo.RepositoryFromContextOrOpen(ctx.Ctx, ctx.Repo)
if err != nil {
log.Error("unable to open repository: %s Error: %v", ctx.Metas["repoPath"], err)
return
Expand Down
2 changes: 2 additions & 0 deletions modules/markup/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"sync"

"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"

Expand Down Expand Up @@ -74,6 +75,7 @@ type RenderContext struct {
Metas map[string]string
DefaultLink string
GitRepo *git.Repository
Repo gitrepo.Repository
ShaExistCache map[string]bool
cancelFn func()
SidebarTocNode ast.Node
Expand Down
3 changes: 2 additions & 1 deletion routers/common/markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func RenderMarkup(ctx *context.Base, repo *context.Repository, mode, text, urlPr
}

if err := markup.Render(&markup.RenderContext{
Ctx: ctx,
Ctx: ctx,
Repo: repo.Repository,
Links: markup.Links{
Base: urlPrefix,
},
Expand Down
3 changes: 2 additions & 1 deletion routers/web/feed/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ func releasesToFeedItems(ctx *context.Context, releases []*repo_model.Release, i

link := &feeds.Link{Href: rel.HTMLURL()}
content, err = markdown.RenderString(&markup.RenderContext{
Ctx: ctx,
Ctx: ctx,
Repo: rel.Repo,
Links: markup.Links{
Base: rel.Repo.Link(),
},
Expand Down
1 change: 1 addition & 0 deletions routers/web/repo/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ func Diff(ctx *context.Context) {
},
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Repo: ctx.Repo.Repository,
Ctx: ctx,
}, template.HTMLEscapeString(string(charset.ToUTF8WithFallback(note.Message, charset.ConvertOpts{}))))
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@ func ViewIssue(ctx *context.Context) {
},
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Repo: ctx.Repo.Repository,
Ctx: ctx,
}, issue.Content)
if err != nil {
Expand Down Expand Up @@ -1623,6 +1624,7 @@ func ViewIssue(ctx *context.Context) {
},
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Repo: ctx.Repo.Repository,
Ctx: ctx,
}, comment.Content)
if err != nil {
Expand Down Expand Up @@ -1702,6 +1704,7 @@ func ViewIssue(ctx *context.Context) {
},
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Repo: ctx.Repo.Repository,
Ctx: ctx,
}, comment.Content)
if err != nil {
Expand Down Expand Up @@ -2262,6 +2265,7 @@ func UpdateIssueContent(ctx *context.Context) {
},
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Repo: ctx.Repo.Repository,
Ctx: ctx,
}, issue.Content)
if err != nil {
Expand Down Expand Up @@ -3173,6 +3177,7 @@ func UpdateCommentContent(ctx *context.Context) {
},
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Repo: ctx.Repo.Repository,
Ctx: ctx,
}, comment.Content)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions routers/web/repo/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func Milestones(ctx *context.Context) {
},
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Repo: ctx.Repo.Repository,
Ctx: ctx,
}, m.Content)
if err != nil {
Expand Down Expand Up @@ -282,6 +283,7 @@ func MilestoneIssuesAndPulls(ctx *context.Context) {
},
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Repo: ctx.Repo.Repository,
Ctx: ctx,
}, milestone.Content)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions routers/web/repo/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func Projects(ctx *context.Context) {
},
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Repo: ctx.Repo.Repository,
Ctx: ctx,
}, projects[i].Description)
if err != nil {
Expand Down Expand Up @@ -364,6 +365,7 @@ func ViewProject(ctx *context.Context) {
},
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Repo: ctx.Repo.Repository,
Ctx: ctx,
}, project.Description)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions routers/web/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func Releases(ctx *context.Context) {
},
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Repo: ctx.Repo.Repository,
Ctx: ctx,
}, r.Note)
if err != nil {
Expand Down Expand Up @@ -294,6 +295,7 @@ func SingleRelease(ctx *context.Context) {
},
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Repo: ctx.Repo.Repository,
Ctx: ctx,
}, release.Note)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions routers/web/user/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func Milestones(ctx *context.Context) {
},
Metas: milestones[i].Repo.ComposeMetas(ctx),
Ctx: ctx,
Repo: milestones[i].Repo,
}, milestones[i].Content)
if err != nil {
ctx.ServerError("RenderString", err)
Expand Down
3 changes: 2 additions & 1 deletion services/mailer/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient

// This is the body of the new issue or comment, not the mail body
body, err := markdown.RenderString(&markup.RenderContext{
Ctx: ctx,
Ctx: ctx,
Repo: ctx.Issue.Repo,
Links: markup.Links{
Base: ctx.Issue.Repo.HTMLURL(),
},
Expand Down
3 changes: 2 additions & 1 deletion services/mailer/mail_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func mailNewRelease(ctx context.Context, lang string, tos []string, rel *repo_mo

var err error
rel.RenderedNote, err = markdown.RenderString(&markup.RenderContext{
Ctx: ctx,
Ctx: ctx,
Repo: rel.Repo,
Links: markup.Links{
Base: rel.Repo.HTMLURL(),
},
Expand Down