Skip to content

Commit 7a9fd60

Browse files
committed
fix
1 parent 9bf821a commit 7a9fd60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+486
-626
lines changed

models/issues/comment_code.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,12 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
112112
}
113113

114114
var err error
115-
if comment.RenderedContent, err = markdown.RenderString(&markup.RenderContext{
116-
Ctx: ctx,
117-
Repo: issue.Repo,
118-
Links: markup.Links{
119-
Base: issue.Repo.Link(),
120-
},
121-
Metas: issue.Repo.ComposeMetas(ctx),
122-
}, comment.Content); err != nil {
115+
rctx := markup.NewRenderContext(ctx).
116+
WithRepoFacade(issue.Repo).
117+
WithLinks(markup.Links{Base: issue.Repo.Link()}).
118+
WithMetas(issue.Repo.ComposeMetas(ctx))
119+
if comment.RenderedContent, err = markdown.RenderString(rctx,
120+
comment.Content); err != nil {
123121
return nil, err
124122
}
125123
}

models/repo/repo.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,7 @@ func (repo *Repository) CanEnableEditor() bool {
617617

618618
// DescriptionHTML does special handles to description and return HTML string.
619619
func (repo *Repository) DescriptionHTML(ctx context.Context) template.HTML {
620-
desc, err := markup.RenderDescriptionHTML(&markup.RenderContext{
621-
Ctx: ctx,
622-
// Don't use Metas to speedup requests
623-
}, repo.Description)
620+
desc, err := markup.RenderDescriptionHTML(markup.NewRenderContext(ctx), repo.Description)
624621
if err != nil {
625622
log.Error("Failed to render description for %s (ID: %d): %v", repo.Name, repo.ID, err)
626623
return template.HTML(markup.SanitizeDescription(repo.Description))

modules/csv/csv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"bytes"
88
stdcsv "encoding/csv"
99
"io"
10-
"path/filepath"
10+
"path"
1111
"regexp"
1212
"strings"
1313

@@ -53,7 +53,7 @@ func CreateReaderAndDetermineDelimiter(ctx *markup.RenderContext, rd io.Reader)
5353
func determineDelimiter(ctx *markup.RenderContext, data []byte) rune {
5454
extension := ".csv"
5555
if ctx != nil {
56-
extension = strings.ToLower(filepath.Ext(ctx.RelativePath))
56+
extension = strings.ToLower(path.Ext(ctx.RenderOptions.RelativePath))
5757
}
5858

5959
var delimiter rune

modules/csv/csv_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ package csv
55

66
import (
77
"bytes"
8+
"context"
89
"encoding/csv"
910
"io"
1011
"strconv"
1112
"strings"
1213
"testing"
1314

14-
"code.gitea.io/gitea/modules/git"
1515
"code.gitea.io/gitea/modules/markup"
1616
"code.gitea.io/gitea/modules/translation"
1717

@@ -231,10 +231,7 @@ John Doe [email protected] This,note,had,a,lot,of,commas,to,test,delimiters`,
231231
}
232232

233233
for n, c := range cases {
234-
delimiter := determineDelimiter(&markup.RenderContext{
235-
Ctx: git.DefaultContext,
236-
RelativePath: c.filename,
237-
}, []byte(decodeSlashes(t, c.csv)))
234+
delimiter := determineDelimiter(markup.NewRenderContext(context.Background()).WithRelativePath(c.filename), []byte(decodeSlashes(t, c.csv)))
238235
assert.EqualValues(t, c.expectedDelimiter, delimiter, "case %d: delimiter should be equal, expected '%c' got '%c'", n, c.expectedDelimiter, delimiter)
239236
}
240237
}

modules/markup/asciicast/asciicast.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ func (Renderer) SanitizerRules() []setting.MarkupSanitizerRule {
4444
func (Renderer) Render(ctx *markup.RenderContext, _ io.Reader, output io.Writer) error {
4545
rawURL := fmt.Sprintf("%s/%s/%s/raw/%s/%s",
4646
setting.AppSubURL,
47-
url.PathEscape(ctx.Metas["user"]),
48-
url.PathEscape(ctx.Metas["repo"]),
49-
ctx.Metas["BranchNameSubURL"],
50-
url.PathEscape(ctx.RelativePath),
47+
url.PathEscape(ctx.RenderOptions.Metas["user"]),
48+
url.PathEscape(ctx.RenderOptions.Metas["repo"]),
49+
ctx.RenderOptions.Metas["BranchNameSubURL"],
50+
url.PathEscape(ctx.RenderOptions.RelativePath),
5151
)
5252
return ctx.RenderInternal.FormatWithSafeAttrs(output, `<div class="%s" %s="%s"></div>`, playerClassName, playerSrcAttr, rawURL)
5353
}

modules/markup/console/console_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
package console
55

66
import (
7+
"context"
78
"strings"
89
"testing"
910

10-
"code.gitea.io/gitea/modules/git"
1111
"code.gitea.io/gitea/modules/markup"
1212

1313
"github.com/stretchr/testify/assert"
@@ -24,8 +24,7 @@ func TestRenderConsole(t *testing.T) {
2424
canRender := render.CanRender("test", strings.NewReader(k))
2525
assert.True(t, canRender)
2626

27-
err := render.Render(&markup.RenderContext{Ctx: git.DefaultContext},
28-
strings.NewReader(k), &buf)
27+
err := render.Render(markup.NewRenderContext(context.Background()), strings.NewReader(k), &buf)
2928
assert.NoError(t, err)
3029
assert.EqualValues(t, v, buf.String())
3130
}

modules/markup/csv/csv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ func (r Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.W
133133
// Check if maxRows or maxSize is reached, and if true, warn.
134134
if (row >= maxRows && maxRows != 0) || (rd.InputOffset() >= maxSize && maxSize != 0) {
135135
warn := `<table class="data-table"><tr><td>`
136-
rawLink := ` <a href="` + ctx.Links.RawLink() + `/` + util.PathEscapeSegments(ctx.RelativePath) + `">`
136+
rawLink := ` <a href="` + ctx.RenderOptions.Links.RawLink() + `/` + util.PathEscapeSegments(ctx.RenderOptions.RelativePath) + `">`
137137

138138
// Try to get the user translation
139-
if locale, ok := ctx.Ctx.Value(translation.ContextKey).(translation.Locale); ok {
139+
if locale, ok := ctx.Value(translation.ContextKey).(translation.Locale); ok {
140140
warn += locale.TrString("repo.file_too_large")
141141
rawLink += locale.TrString("repo.file_view_raw")
142142
} else {

modules/markup/csv/csv_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
package markup
55

66
import (
7+
"context"
78
"strings"
89
"testing"
910

10-
"code.gitea.io/gitea/modules/git"
1111
"code.gitea.io/gitea/modules/markup"
1212

1313
"github.com/stretchr/testify/assert"
@@ -24,8 +24,7 @@ func TestRenderCSV(t *testing.T) {
2424

2525
for k, v := range kases {
2626
var buf strings.Builder
27-
err := render.Render(&markup.RenderContext{Ctx: git.DefaultContext},
28-
strings.NewReader(k), &buf)
27+
err := render.Render(markup.NewRenderContext(context.Background()), strings.NewReader(k), &buf)
2928
assert.NoError(t, err)
3029
assert.EqualValues(t, v, buf.String())
3130
}

modules/markup/external/external.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"runtime"
1313
"strings"
1414

15-
"code.gitea.io/gitea/modules/graceful"
1615
"code.gitea.io/gitea/modules/log"
1716
"code.gitea.io/gitea/modules/markup"
1817
"code.gitea.io/gitea/modules/process"
@@ -80,8 +79,8 @@ func envMark(envName string) string {
8079
func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error {
8180
var (
8281
command = strings.NewReplacer(
83-
envMark("GITEA_PREFIX_SRC"), ctx.Links.SrcLink(),
84-
envMark("GITEA_PREFIX_RAW"), ctx.Links.RawLink(),
82+
envMark("GITEA_PREFIX_SRC"), ctx.RenderOptions.Links.SrcLink(),
83+
envMark("GITEA_PREFIX_RAW"), ctx.RenderOptions.Links.RawLink(),
8584
).Replace(p.Command)
8685
commands = strings.Fields(command)
8786
args = commands[1:]
@@ -113,22 +112,14 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.
113112
args = append(args, f.Name())
114113
}
115114

116-
if ctx.Ctx == nil {
117-
if !setting.IsProd || setting.IsInTesting {
118-
panic("RenderContext did not provide context")
119-
}
120-
log.Warn("RenderContext did not provide context, defaulting to Shutdown context")
121-
ctx.Ctx = graceful.GetManager().ShutdownContext()
122-
}
123-
124-
processCtx, _, finished := process.GetManager().AddContext(ctx.Ctx, fmt.Sprintf("Render [%s] for %s", commands[0], ctx.Links.SrcLink()))
115+
processCtx, _, finished := process.GetManager().AddContext(ctx, fmt.Sprintf("Render [%s] for %s", commands[0], ctx.RenderOptions.Links.SrcLink()))
125116
defer finished()
126117

127118
cmd := exec.CommandContext(processCtx, commands[0], args...)
128119
cmd.Env = append(
129120
os.Environ(),
130-
"GITEA_PREFIX_SRC="+ctx.Links.SrcLink(),
131-
"GITEA_PREFIX_RAW="+ctx.Links.RawLink(),
121+
"GITEA_PREFIX_SRC="+ctx.RenderOptions.Links.SrcLink(),
122+
"GITEA_PREFIX_RAW="+ctx.RenderOptions.Links.RawLink(),
132123
)
133124
if !p.IsInputFile {
134125
cmd.Stdin = input

modules/markup/html_codepreview.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func renderCodeBlock(ctx *RenderContext, node *html.Node) (urlPosStart, urlPosSt
3838
CommitID: node.Data[m[6]:m[7]],
3939
FilePath: node.Data[m[8]:m[9]],
4040
}
41-
if !httplib.IsCurrentGiteaSiteURL(ctx.Ctx, opts.FullURL) {
41+
if !httplib.IsCurrentGiteaSiteURL(ctx, opts.FullURL) {
4242
return 0, 0, "", nil
4343
}
4444
u, err := url.Parse(opts.FilePath)
@@ -51,7 +51,7 @@ func renderCodeBlock(ctx *RenderContext, node *html.Node) (urlPosStart, urlPosSt
5151
lineStart, _ := strconv.Atoi(strings.TrimPrefix(lineStartStr, "L"))
5252
lineStop, _ := strconv.Atoi(strings.TrimPrefix(lineStopStr, "L"))
5353
opts.LineStart, opts.LineStop = lineStart, lineStop
54-
h, err := DefaultProcessorHelper.RenderRepoFileCodePreview(ctx.Ctx, opts)
54+
h, err := DefaultProcessorHelper.RenderRepoFileCodePreview(ctx, opts)
5555
return m[0], m[1], h, err
5656
}
5757

0 commit comments

Comments
 (0)