Skip to content

Commit ea65a8c

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Fix incorrect ctx usage in defer function (go-gitea#27740) Enable followCursor for language stats bar (go-gitea#27713) teams: new View button (go-gitea#27685) fix issues in translation file (go-gitea#27699) Fix an indentation in the Chinese documentation of Act Runner (go-gitea#27730) [skip ci] Updated translations via Crowdin Fix org team endpoint (go-gitea#27721) Improve diff tree spacing (go-gitea#27714) refactor: make db iterate context aware (go-gitea#27710) [FIX] resolve confusing colors in languages stats by insert a gap (go-gitea#27704) Fix sticky diff header background (go-gitea#27697) Replace -1 with GhostUserID (go-gitea#27703) Clean some functions about project issue (go-gitea#27705)
2 parents 8879756 + f3956fc commit ea65a8c

File tree

23 files changed

+368
-115
lines changed

23 files changed

+368
-115
lines changed

docs/content/usage/actions/act-runner.zh-cn.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ services:
208208

209209
```yaml
210210
cache:
211-
enabled: true
212-
dir: ""
213-
# 使用步骤 1. 获取的 LAN IP
214-
host: "192.168.8.17"
215-
# 使用步骤 2. 获取的端口号
216-
port: 8088
211+
enabled: true
212+
dir: ""
213+
# 使用步骤 1. 获取的 LAN IP
214+
host: "192.168.8.17"
215+
# 使用步骤 2. 获取的端口号
216+
port: 8088
217217
```
218218

219219
- 4.启动容器时, 将 Cache 端口映射至主机。

models/db/iterate.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@ func Iterate[Bean any](ctx context.Context, cond builder.Cond, f func(ctx contex
1717
batchSize := setting.Database.IterateBufferSize
1818
sess := GetEngine(ctx)
1919
for {
20-
beans := make([]*Bean, 0, batchSize)
21-
if cond != nil {
22-
sess = sess.Where(cond)
23-
}
24-
if err := sess.Limit(batchSize, start).Find(&beans); err != nil {
25-
return err
26-
}
27-
if len(beans) == 0 {
28-
return nil
29-
}
30-
start += len(beans)
31-
32-
for _, bean := range beans {
33-
if err := f(ctx, bean); err != nil {
20+
select {
21+
case <-ctx.Done():
22+
return ctx.Err()
23+
default:
24+
beans := make([]*Bean, 0, batchSize)
25+
if cond != nil {
26+
sess = sess.Where(cond)
27+
}
28+
if err := sess.Limit(batchSize, start).Find(&beans); err != nil {
3429
return err
3530
}
31+
if len(beans) == 0 {
32+
return nil
33+
}
34+
start += len(beans)
35+
36+
for _, bean := range beans {
37+
if err := f(ctx, bean); err != nil {
38+
return err
39+
}
40+
}
3641
}
3742
}
3843
}

models/issues/comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func (c *Comment) LoadPoster(ctx context.Context) (err error) {
349349
c.Poster, err = user_model.GetPossibleUserByID(ctx, c.PosterID)
350350
if err != nil {
351351
if user_model.IsErrUserNotExist(err) {
352-
c.PosterID = -1
352+
c.PosterID = user_model.GhostUserID
353353
c.Poster = user_model.NewGhostUser()
354354
} else {
355355
log.Error("getUserByID[%d]: %v", c.ID, err)

models/issues/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (issue *Issue) LoadPoster(ctx context.Context) (err error) {
219219
if issue.Poster == nil && issue.PosterID != 0 {
220220
issue.Poster, err = user_model.GetPossibleUserByID(ctx, issue.PosterID)
221221
if err != nil {
222-
issue.PosterID = -1
222+
issue.PosterID = user_model.GhostUserID
223223
issue.Poster = user_model.NewGhostUser()
224224
if !user_model.IsErrUserNotExist(err) {
225225
return fmt.Errorf("getUserByID.(poster) [%d]: %w", issue.PosterID, err)

models/issues/issue_project.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (issue *Issue) ProjectBoardID(ctx context.Context) int64 {
5151
func LoadIssuesFromBoard(ctx context.Context, b *project_model.Board) (IssueList, error) {
5252
issueList := make(IssueList, 0, 10)
5353

54-
if b.ID != 0 {
54+
if b.ID > 0 {
5555
issues, err := Issues(ctx, &IssuesOptions{
5656
ProjectBoardID: b.ID,
5757
ProjectID: b.ProjectID,
@@ -65,7 +65,7 @@ func LoadIssuesFromBoard(ctx context.Context, b *project_model.Board) (IssueList
6565

6666
if b.Default {
6767
issues, err := Issues(ctx, &IssuesOptions{
68-
ProjectBoardID: -1, // Issues without ProjectBoardID
68+
ProjectBoardID: db.NoConditionID,
6969
ProjectID: b.ProjectID,
7070
SortType: "project-column-sorting",
7171
})
@@ -150,30 +150,3 @@ func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.U
150150
ProjectID: newProjectID,
151151
})
152152
}
153-
154-
// MoveIssueAcrossProjectBoards move a card from one board to another
155-
func MoveIssueAcrossProjectBoards(ctx context.Context, issue *Issue, board *project_model.Board) error {
156-
ctx, committer, err := db.TxContext(ctx)
157-
if err != nil {
158-
return err
159-
}
160-
defer committer.Close()
161-
sess := db.GetEngine(ctx)
162-
163-
var pis project_model.ProjectIssue
164-
has, err := sess.Where("issue_id=?", issue.ID).Get(&pis)
165-
if err != nil {
166-
return err
167-
}
168-
169-
if !has {
170-
return fmt.Errorf("issue has to be added to a project first")
171-
}
172-
173-
pis.ProjectBoardID = board.ID
174-
if _, err := sess.ID(pis.ID).Cols("project_board_id").Update(&pis); err != nil {
175-
return err
176-
}
177-
178-
return committer.Commit()
179-
}

models/issues/issue_search.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,17 @@ func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sessio
180180
return sess
181181
}
182182

183+
func applyProjectBoardCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
184+
// opts.ProjectBoardID == 0 means all project boards,
185+
// do not need to apply any condition
186+
if opts.ProjectBoardID > 0 {
187+
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}))
188+
} else if opts.ProjectBoardID == db.NoConditionID {
189+
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Neq{"project_board_id": 0}))
190+
}
191+
return sess
192+
}
193+
183194
func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
184195
if len(opts.RepoIDs) == 1 {
185196
opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]}
@@ -240,13 +251,7 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
240251

241252
applyProjectCondition(sess, opts)
242253

243-
if opts.ProjectBoardID != 0 {
244-
if opts.ProjectBoardID > 0 {
245-
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}))
246-
} else {
247-
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0}))
248-
}
249-
}
254+
applyProjectBoardCondition(sess, opts)
250255

251256
switch opts.IsPull {
252257
case util.OptionalBoolTrue:

models/issues/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func (pr *PullRequest) LoadAttributes(ctx context.Context) (err error) {
272272
if pr.HasMerged && pr.Merger == nil {
273273
pr.Merger, err = user_model.GetUserByID(ctx, pr.MergerID)
274274
if user_model.IsErrUserNotExist(err) {
275-
pr.MergerID = -1
275+
pr.MergerID = user_model.GhostUserID
276276
pr.Merger = user_model.NewGhostUser()
277277
} else if err != nil {
278278
return fmt.Errorf("getUserByID [%d]: %w", pr.MergerID, err)

models/user/avatar.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error {
5858

5959
// AvatarLinkWithSize returns a link to the user's avatar with size. size <= 0 means default size
6060
func (u *User) AvatarLinkWithSize(ctx context.Context, size int) string {
61-
if u.ID == -1 {
62-
// ghost user
61+
if u.IsGhost() {
6362
return avatars.DefaultAvatarLink()
6463
}
6564

models/user/user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ func GetUserByIDs(ctx context.Context, ids []int64) ([]*User, error) {
933933
// GetPossibleUserByID returns the user if id > 0 or return system usrs if id < 0
934934
func GetPossibleUserByID(ctx context.Context, id int64) (*User, error) {
935935
switch id {
936-
case -1:
936+
case GhostUserID:
937937
return NewGhostUser(), nil
938938
case ActionsUserID:
939939
return NewActionsUser(), nil
@@ -949,7 +949,7 @@ func GetPossibleUserByIDs(ctx context.Context, ids []int64) ([]*User, error) {
949949
uniqueIDs := container.SetOf(ids...)
950950
users := make([]*User, 0, len(ids))
951951
_ = uniqueIDs.Remove(0)
952-
if uniqueIDs.Remove(-1) {
952+
if uniqueIDs.Remove(GhostUserID) {
953953
users = append(users, NewGhostUser())
954954
}
955955
if uniqueIDs.Remove(ActionsUserID) {

models/user/user_system.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ import (
99
"code.gitea.io/gitea/modules/structs"
1010
)
1111

12+
const (
13+
GhostUserID = -1
14+
GhostUserName = "Ghost"
15+
GhostUserLowerName = "ghost"
16+
)
17+
1218
// NewGhostUser creates and returns a fake user for someone has deleted their account.
1319
func NewGhostUser() *User {
1420
return &User{
15-
ID: -1,
16-
Name: "Ghost",
17-
LowerName: "ghost",
21+
ID: GhostUserID,
22+
Name: GhostUserName,
23+
LowerName: GhostUserLowerName,
1824
}
1925
}
2026

@@ -23,13 +29,13 @@ func (u *User) IsGhost() bool {
2329
if u == nil {
2430
return false
2531
}
26-
return u.ID == -1 && u.Name == "Ghost"
32+
return u.ID == GhostUserID && u.Name == GhostUserName
2733
}
2834

2935
// NewReplaceUser creates and returns a fake user for external user
3036
func NewReplaceUser(name string) *User {
3137
return &User{
32-
ID: -1,
38+
ID: 0,
3339
Name: name,
3440
LowerName: strings.ToLower(name),
3541
}

modules/doctor/repository.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,29 @@ func deleteOrphanedRepos(ctx context.Context) (int64, error) {
3737
adminUser := &user_model.User{IsAdmin: true}
3838

3939
for {
40-
var ids []int64
41-
if err := e.Table("`repository`").
42-
Join("LEFT", "`user`", "repository.owner_id=user.id").
43-
Where(builder.IsNull{"`user`.id"}).
44-
Select("`repository`.id").Limit(batchSize).Find(&ids); err != nil {
45-
return deleted, err
46-
}
40+
select {
41+
case <-ctx.Done():
42+
return deleted, ctx.Err()
43+
default:
44+
var ids []int64
45+
if err := e.Table("`repository`").
46+
Join("LEFT", "`user`", "repository.owner_id=user.id").
47+
Where(builder.IsNull{"`user`.id"}).
48+
Select("`repository`.id").Limit(batchSize).Find(&ids); err != nil {
49+
return deleted, err
50+
}
4751

48-
// if we don't get ids we have deleted them all
49-
if len(ids) == 0 {
50-
return deleted, nil
51-
}
52+
// if we don't get ids we have deleted them all
53+
if len(ids) == 0 {
54+
return deleted, nil
55+
}
5256

53-
for _, id := range ids {
54-
if err := repo_service.DeleteRepositoryDirectly(ctx, adminUser, id, true); err != nil {
55-
return deleted, err
57+
for _, id := range ids {
58+
if err := repo_service.DeleteRepositoryDirectly(ctx, adminUser, id, true); err != nil {
59+
return deleted, err
60+
}
61+
deleted++
5662
}
57-
deleted++
5863
}
5964
}
6065
}

modules/indexer/issues/db/options.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
9696
}
9797

9898
if len(options.IncludedLabelIDs) == 0 && len(options.IncludedAnyLabelIDs) > 0 {
99-
_ = ctx // issue_model.GetLabelsByIDs should be called with ctx, this line can be removed when it's done.
10099
labels, err := issue_model.GetLabelsByIDs(ctx, options.IncludedAnyLabelIDs, "name")
101100
if err != nil {
102101
return nil, fmt.Errorf("GetLabelsByIDs: %v", err)

options/locale/locale_en-US.ini

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ remove = Remove
9191
remove_all = Remove All
9292
remove_label_str = Remove item "%s"
9393
edit = Edit
94+
view = View
9495

9596
enabled = Enabled
9697
disabled = Disabled
@@ -355,7 +356,6 @@ code_last_indexed_at = Last indexed %s
355356
relevant_repositories_tooltip = Repositories that are forks or that have no topic, no icon, and no description are hidden.
356357
relevant_repositories = Only relevant repositories are being shown, <a href="%s">show unfiltered results</a>.
357358

358-
359359
[auth]
360360
create_new_account = Register Account
361361
register_helper_msg = Already have an account? Sign in now!
@@ -858,7 +858,7 @@ oauth2_client_secret_hint = The secret will not be shown again after you leave o
858858
oauth2_application_edit = Edit
859859
oauth2_application_create_description = OAuth2 applications gives your third-party application access to user accounts on this instance.
860860
oauth2_application_remove_description = Removing an OAuth2 application will prevent it from accessing authorized user accounts on this instance. Continue?
861-
oauth2_application_locked = Gitea pre-registers some OAuth2 applications on startup if enabled in config. To prevent unexpected bahavior, these can neither be edited nor removed. Please refer to the OAuth2 documentation for more information.
861+
oauth2_application_locked = Gitea pre-registers some OAuth2 applications on startup if enabled in config. To prevent unexpected behavior, these can neither be edited nor removed. Please refer to the OAuth2 documentation for more information.
862862

863863
authorized_oauth2_applications = Authorized OAuth2 Applications
864864
authorized_oauth2_applications_description = You have granted access to your personal Gitea account to these third party applications. Please revoke access for applications you no longer need.
@@ -926,7 +926,7 @@ visibility.private = Private
926926
visibility.private_tooltip = Visible only to members of organizations you have joined
927927

928928
[repo]
929-
new_repo_helper = A repository contains all project files, including revision history. Already hosting one elsewhere? <a href="%s">Migrate repository.</a>
929+
new_repo_helper = A repository contains all project files, including revision history. Already hosting one elsewhere? <a href="%s">Migrate repository.</a>
930930
owner = Owner
931931
owner_helper = Some organizations may not show up in the dropdown due to a maximum repository count limit.
932932
repo_name = Repository Name
@@ -1023,9 +1023,9 @@ tree_path_not_found_branch = Path %[1]s doesn't exist in branch %[2]s
10231023
tree_path_not_found_tag = Path %[1]s doesn't exist in tag %[2]s
10241024

10251025
transfer.accept = Accept Transfer
1026-
transfer.accept_desc = Transfer to "%s"
1026+
transfer.accept_desc = Transfer to "%s"
10271027
transfer.reject = Reject Transfer
1028-
transfer.reject_desc = Cancel transfer to "%s"
1028+
transfer.reject_desc = Cancel transfer to "%s"
10291029
transfer.no_permission_to_accept = You do not have permission to accept this transfer.
10301030
transfer.no_permission_to_reject = You do not have permission to reject this transfer.
10311031

@@ -1159,7 +1159,7 @@ releases = Releases
11591159
tag = Tag
11601160
released_this = released this
11611161
tagged_this = tagged this
1162-
file.title = %s at %s
1162+
file.title = %s at %s
11631163
file_raw = Raw
11641164
file_history = History
11651165
file_view_source = View Source
@@ -2507,7 +2507,6 @@ release.releases_for = Releases for %s
25072507
release.tags_for = Tags for %s
25082508

25092509
branch.name = Branch Name
2510-
branch.search = Search branches
25112510
branch.already_exists = A branch named "%s" already exists.
25122511
branch.delete_head = Delete
25132512
branch.delete = Delete Branch "%s"
@@ -3174,8 +3173,8 @@ monitor.start = Start Time
31743173
monitor.execute_time = Execution Time
31753174
monitor.last_execution_result = Result
31763175
monitor.process.cancel = Cancel process
3177-
monitor.process.cancel_desc = Cancelling a process may cause data loss
3178-
monitor.process.cancel_notices = Cancel: <strong>%s</strong>?
3176+
monitor.process.cancel_desc = Cancelling a process may cause data loss
3177+
monitor.process.cancel_notices = Cancel: <strong>%s</strong>?
31793178
monitor.process.children = Children
31803179

31813180
monitor.queues = Queues
@@ -3239,7 +3238,7 @@ mirror_sync_create = synced new reference <a href="%[2]s">%[3]s</a> to <a href="
32393238
mirror_sync_delete = synced and deleted reference <code>%[2]s</code> at <a href="%[1]s">%[3]s</a> from mirror
32403239
approve_pull_request = `approved <a href="%[1]s">%[3]s#%[2]s</a>`
32413240
reject_pull_request = `suggested changes for <a href="%[1]s">%[3]s#%[2]s</a>`
3242-
publish_release = `released <a href="%[2]s"> "%[4]s" </a> at <a href="%[1]s">%[3]s</a>`
3241+
publish_release = `released <a href="%[2]s"> "%[4]s" </a> at <a href="%[1]s">%[3]s</a>`
32433242
review_dismissed = `dismissed review from <b>%[4]s</b> for <a href="%[1]s">%[3]s#%[2]s</a>`
32443243
review_dismissed_reason = Reason:
32453244
create_branch = created branch <a href="%[2]s">%[3]s</a> in <a href="%[1]s">%[4]s</a>
@@ -3565,7 +3564,7 @@ type-3.display_name = Organization Project
35653564
35663565
[git.filemode]
35673566
changed_filemode = %[1]s → %[2]s
3568-
# Ordered by git filemode value, ascending. E.g. directory has "040000", normal file has "100644", …
3567+
; Ordered by git filemode value, ascending. E.g. directory has "040000", normal file has "100644", …
35693568
directory = Directory
35703569
normal_file = Normal file
35713570
executable_file = Executable file

0 commit comments

Comments
 (0)