Skip to content

Commit 31d881b

Browse files
committed
Add context param
1 parent eb57fd3 commit 31d881b

File tree

92 files changed

+185
-184
lines changed

Some content is hidden

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

92 files changed

+185
-184
lines changed

models/actions/run_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,6 @@ func GetActors(ctx context.Context, repoID int64) ([]*user_model.User, error) {
134134
GroupBy("`action_run`.trigger_user_id").
135135
Where(builder.Eq{"`action_run`.repo_id": repoID}))).
136136
Cols("id", "name", "full_name", "avatar", "avatar_email", "use_custom_avatar").
137-
OrderBy(user_model.GetOrderByName()).
137+
OrderBy(user_model.GetOrderByName(ctx)).
138138
Find(&actors)
139139
}

models/issues/issue_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (issues IssueList) LoadAssignees(ctx context.Context) error {
251251
}
252252
rows, err := db.GetEngine(ctx).Table("issue_assignees").
253253
Join("INNER", "`user`", "`user`.id = `issue_assignees`.assignee_id").
254-
In("`issue_assignees`.issue_id", issueIDs[:limit]).OrderBy(user_model.GetOrderByName()).
254+
In("`issue_assignees`.issue_id", issueIDs[:limit]).OrderBy(user_model.GetOrderByName(ctx)).
255255
Rows(new(AssigneeIssue))
256256
if err != nil {
257257
return err

models/issues/reaction.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@ func (list ReactionList) LoadUsers(ctx context.Context, repo *repo_model.Reposit
355355
}
356356

357357
// GetFirstUsers returns first reacted user display names separated by comma
358-
func (list ReactionList) GetFirstUsers() string {
358+
func (list ReactionList) GetFirstUsers(ctx context.Context) string {
359359
var buffer bytes.Buffer
360-
rem := setting.Config().UI.ReactionMaxUserNum.Value(context.Background())
360+
rem := setting.Config().UI.ReactionMaxUserNum.Value(ctx)
361361
for _, reaction := range list {
362362
if buffer.Len() > 0 {
363363
buffer.WriteString(", ")
@@ -371,8 +371,7 @@ func (list ReactionList) GetFirstUsers() string {
371371
}
372372

373373
// GetMoreUserCount returns count of not shown users in reaction tooltip
374-
func (list ReactionList) GetMoreUserCount() int {
375-
ctx := context.Background()
374+
func (list ReactionList) GetMoreUserCount(ctx context.Context) int {
376375
if len(list) <= setting.Config().UI.ReactionMaxUserNum.Value(ctx) {
377376
return 0
378377
}

models/organization/org.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ func (org *Organization) OrganisationLink() string {
169169
}
170170

171171
// ShortName ellipses username to length
172-
func (org *Organization) ShortName(length int) string {
173-
return org.AsUser().ShortName(length)
172+
func (org *Organization) ShortName(ctx context.Context, length int) string {
173+
return org.AsUser().ShortName(ctx, length)
174174
}
175175

176176
// HomeLink returns the user or organization home page link.

models/organization/org_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func GetOrgAssignees(ctx context.Context, orgID int64) (_ []*user_model.User, er
163163
if len(userIDs) > 0 {
164164
if err = e.In("id", uniqueUserIDs.Values()).
165165
Where(builder.Eq{"`user`.is_active": true}).
166-
OrderBy(user_model.GetOrderByName()).
166+
OrderBy(user_model.GetOrderByName(ctx)).
167167
Find(&users); err != nil {
168168
return nil, err
169169
}

models/repo/user_repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us
134134
if len(uniqueUserIDs) > 0 {
135135
if err = e.In("id", uniqueUserIDs.Values()).
136136
Where(builder.Eq{"`user`.is_active": true}).
137-
OrderBy(user_model.GetOrderByName()).
137+
OrderBy(user_model.GetOrderByName(ctx)).
138138
Find(&users); err != nil {
139139
return nil, err
140140
}

models/user/user.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ func (u *User) EmailTo() string {
440440

441441
// GetDisplayName returns full name if it's not empty and DEFAULT_SHOW_FULL_NAME is set,
442442
// returns username otherwise.
443-
func (u *User) GetDisplayName() string {
444-
if setting.Config().UI.DefaultShowFullName.Value(context.Background()) {
443+
func (u *User) GetDisplayName(ctx context.Context) string {
444+
if setting.Config().UI.DefaultShowFullName.Value(ctx) {
445445
trimmed := strings.TrimSpace(u.FullName)
446446
if len(trimmed) > 0 {
447447
return trimmed
@@ -482,8 +482,8 @@ func (u *User) GitName() string {
482482
}
483483

484484
// ShortName ellipses username to length
485-
func (u *User) ShortName(length int) string {
486-
if setting.Config().UI.DefaultShowFullName.Value(context.Background()) && len(u.FullName) > 0 {
485+
func (u *User) ShortName(ctx context.Context, length int) string {
486+
if setting.Config().UI.DefaultShowFullName.Value(ctx) && len(u.FullName) > 0 {
487487
return util.EllipsisDisplayString(u.FullName, length)
488488
}
489489
return util.EllipsisDisplayString(u.Name, length)
@@ -1393,8 +1393,8 @@ func FixWrongUserType(ctx context.Context) (int64, error) {
13931393
return db.GetEngine(ctx).Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Cols("type").NoAutoTime().Update(&User{Type: 1})
13941394
}
13951395

1396-
func GetOrderByName() string {
1397-
if setting.Config().UI.DefaultShowFullName.Value(context.Background()) {
1396+
func GetOrderByName(ctx context.Context) string {
1397+
if setting.Config().UI.DefaultShowFullName.Value(ctx) {
13981398
return "full_name, name"
13991399
}
14001400
return "name"

modules/charset/escape.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ import (
2222
const RuneNBSP = 0xa0
2323

2424
// EscapeControlHTML escapes the unicode control sequences in a provided html document
25-
func EscapeControlHTML(html template.HTML, locale translation.Locale, allowed ...rune) (escaped *EscapeStatus, output template.HTML) {
25+
func EscapeControlHTML(ctx context.Context, html template.HTML, locale translation.Locale, allowed ...rune) (escaped *EscapeStatus, output template.HTML) {
2626
sb := &strings.Builder{}
27-
escaped, _ = EscapeControlReader(strings.NewReader(string(html)), sb, locale, allowed...) // err has been handled in EscapeControlReader
27+
escaped, _ = EscapeControlReader(ctx, strings.NewReader(string(html)), sb, locale, allowed...) // err has been handled in EscapeControlReader
2828
return escaped, template.HTML(sb.String())
2929
}
3030

3131
// EscapeControlReader escapes the unicode control sequences in a provided reader of HTML content and writer in a locale and returns the findings as an EscapeStatus
32-
func EscapeControlReader(reader io.Reader, writer io.Writer, locale translation.Locale, allowed ...rune) (escaped *EscapeStatus, err error) {
33-
if !setting.Config().UI.AmbiguousUnicodeDetection.Value(context.Background()) {
32+
func EscapeControlReader(ctx context.Context, reader io.Reader, writer io.Writer, locale translation.Locale, allowed ...rune) (escaped *EscapeStatus, err error) {
33+
if !setting.Config().UI.AmbiguousUnicodeDetection.Value(ctx) {
3434
_, err = io.Copy(writer, reader)
3535
return &EscapeStatus{}, err
3636
}

modules/charset/escape_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func TestEscapeControlReader(t *testing.T) {
162162
for _, tt := range tests {
163163
t.Run(tt.name, func(t *testing.T) {
164164
output := &strings.Builder{}
165-
status, err := EscapeControlReader(strings.NewReader(tt.text), output, &translation.MockLocale{})
165+
status, err := EscapeControlReader(t.Context(), strings.NewReader(tt.text), output, &translation.MockLocale{})
166166
assert.NoError(t, err)
167167
assert.Equal(t, tt.status, *status)
168168
outStr := output.String()
@@ -175,10 +175,10 @@ func TestEscapeControlReader(t *testing.T) {
175175
func TestSettingAmbiguousUnicodeDetection(t *testing.T) {
176176
ambiguousUnicodeDetectionValue := setting.Config().UI.AmbiguousUnicodeDetection.Value(t.Context())
177177
defer test.MockVariableValue(&ambiguousUnicodeDetectionValue, true)()
178-
_, out := EscapeControlHTML("a test", &translation.MockLocale{})
178+
_, out := EscapeControlHTML(t.Context(), "a test", &translation.MockLocale{})
179179
assert.EqualValues(t, `a<span class="escaped-code-point" data-escaped="[U+00A0]"><span class="char"> </span></span>test`, out)
180180
ambiguousUnicodeDetection := config.Value[bool]{}
181181
setting.Config().UI.AmbiguousUnicodeDetection = ambiguousUnicodeDetection.WithDefault(false)
182-
_, out = EscapeControlHTML("a test", &translation.MockLocale{})
182+
_, out = EscapeControlHTML(t.Context(), "a test", &translation.MockLocale{})
183183
assert.EqualValues(t, `a test`, out)
184184
}

modules/issue/template/unmarshal.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,31 @@ func Unmarshal(filename string, content []byte) (*api.IssueTemplate, error) {
4343
}
4444

4545
// UnmarshalFromEntry parses out a valid template from the blob in entry
46-
func UnmarshalFromEntry(entry *git.TreeEntry, dir string) (*api.IssueTemplate, error) {
47-
return unmarshalFromEntry(entry, path.Join(dir, entry.Name())) // Filepaths in Git are ALWAYS '/' separated do not use filepath here
46+
func UnmarshalFromEntry(ctx context.Context, entry *git.TreeEntry, dir string) (*api.IssueTemplate, error) {
47+
return unmarshalFromEntry(ctx, entry, path.Join(dir, entry.Name())) // Filepaths in Git are ALWAYS '/' separated do not use filepath here
4848
}
4949

5050
// UnmarshalFromCommit parses out a valid template from the commit
51-
func UnmarshalFromCommit(commit *git.Commit, filename string) (*api.IssueTemplate, error) {
51+
func UnmarshalFromCommit(ctx context.Context, commit *git.Commit, filename string) (*api.IssueTemplate, error) {
5252
entry, err := commit.GetTreeEntryByPath(filename)
5353
if err != nil {
5454
return nil, fmt.Errorf("get entry for %q: %w", filename, err)
5555
}
56-
return unmarshalFromEntry(entry, filename)
56+
return unmarshalFromEntry(ctx, entry, filename)
5757
}
5858

5959
// UnmarshalFromRepo parses out a valid template from the head commit of the branch
60-
func UnmarshalFromRepo(repo *git.Repository, branch, filename string) (*api.IssueTemplate, error) {
60+
func UnmarshalFromRepo(ctx context.Context, repo *git.Repository, branch, filename string) (*api.IssueTemplate, error) {
6161
commit, err := repo.GetBranchCommit(branch)
6262
if err != nil {
6363
return nil, fmt.Errorf("get commit on branch %q: %w", branch, err)
6464
}
6565

66-
return UnmarshalFromCommit(commit, filename)
66+
return UnmarshalFromCommit(ctx, commit, filename)
6767
}
6868

69-
func unmarshalFromEntry(entry *git.TreeEntry, filename string) (*api.IssueTemplate, error) {
70-
if size := entry.Blob().Size(); size > setting.Config().UI.MaxDisplayFileSize.Value(context.Background()) {
69+
func unmarshalFromEntry(ctx context.Context, entry *git.TreeEntry, filename string) (*api.IssueTemplate, error) {
70+
if size := entry.Blob().Size(); size > setting.Config().UI.MaxDisplayFileSize.Value(ctx) {
7171
return nil, fmt.Errorf("too large: %v > MaxDisplayFileSize", size)
7272
}
7373

0 commit comments

Comments
 (0)