Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
zjjhot committed Oct 23, 2023
2 parents 8879756 + f3956fc commit ea65a8c
Show file tree
Hide file tree
Showing 23 changed files with 368 additions and 115 deletions.
12 changes: 6 additions & 6 deletions docs/content/usage/actions/act-runner.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ services:

```yaml
cache:
enabled: true
dir: ""
# 使用步骤 1. 获取的 LAN IP
host: "192.168.8.17"
# 使用步骤 2. 获取的端口号
port: 8088
enabled: true
dir: ""
# 使用步骤 1. 获取的 LAN IP
host: "192.168.8.17"
# 使用步骤 2. 获取的端口号
port: 8088
```

- 4.启动容器时, 将 Cache 端口映射至主机。
Expand Down
33 changes: 19 additions & 14 deletions models/db/iterate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@ func Iterate[Bean any](ctx context.Context, cond builder.Cond, f func(ctx contex
batchSize := setting.Database.IterateBufferSize
sess := GetEngine(ctx)
for {
beans := make([]*Bean, 0, batchSize)
if cond != nil {
sess = sess.Where(cond)
}
if err := sess.Limit(batchSize, start).Find(&beans); err != nil {
return err
}
if len(beans) == 0 {
return nil
}
start += len(beans)

for _, bean := range beans {
if err := f(ctx, bean); err != nil {
select {
case <-ctx.Done():
return ctx.Err()
default:
beans := make([]*Bean, 0, batchSize)
if cond != nil {
sess = sess.Where(cond)
}
if err := sess.Limit(batchSize, start).Find(&beans); err != nil {
return err
}
if len(beans) == 0 {
return nil
}
start += len(beans)

for _, bean := range beans {
if err := f(ctx, bean); err != nil {
return err
}
}
}
}
}
2 changes: 1 addition & 1 deletion models/issues/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (c *Comment) LoadPoster(ctx context.Context) (err error) {
c.Poster, err = user_model.GetPossibleUserByID(ctx, c.PosterID)
if err != nil {
if user_model.IsErrUserNotExist(err) {
c.PosterID = -1
c.PosterID = user_model.GhostUserID
c.Poster = user_model.NewGhostUser()
} else {
log.Error("getUserByID[%d]: %v", c.ID, err)
Expand Down
2 changes: 1 addition & 1 deletion models/issues/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (issue *Issue) LoadPoster(ctx context.Context) (err error) {
if issue.Poster == nil && issue.PosterID != 0 {
issue.Poster, err = user_model.GetPossibleUserByID(ctx, issue.PosterID)
if err != nil {
issue.PosterID = -1
issue.PosterID = user_model.GhostUserID
issue.Poster = user_model.NewGhostUser()
if !user_model.IsErrUserNotExist(err) {
return fmt.Errorf("getUserByID.(poster) [%d]: %w", issue.PosterID, err)
Expand Down
31 changes: 2 additions & 29 deletions models/issues/issue_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (issue *Issue) ProjectBoardID(ctx context.Context) int64 {
func LoadIssuesFromBoard(ctx context.Context, b *project_model.Board) (IssueList, error) {
issueList := make(IssueList, 0, 10)

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

if b.Default {
issues, err := Issues(ctx, &IssuesOptions{
ProjectBoardID: -1, // Issues without ProjectBoardID
ProjectBoardID: db.NoConditionID,
ProjectID: b.ProjectID,
SortType: "project-column-sorting",
})
Expand Down Expand Up @@ -150,30 +150,3 @@ func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.U
ProjectID: newProjectID,
})
}

// MoveIssueAcrossProjectBoards move a card from one board to another
func MoveIssueAcrossProjectBoards(ctx context.Context, issue *Issue, board *project_model.Board) error {
ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
defer committer.Close()
sess := db.GetEngine(ctx)

var pis project_model.ProjectIssue
has, err := sess.Where("issue_id=?", issue.ID).Get(&pis)
if err != nil {
return err
}

if !has {
return fmt.Errorf("issue has to be added to a project first")
}

pis.ProjectBoardID = board.ID
if _, err := sess.ID(pis.ID).Cols("project_board_id").Update(&pis); err != nil {
return err
}

return committer.Commit()
}
19 changes: 12 additions & 7 deletions models/issues/issue_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ func applyProjectCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Sessio
return sess
}

func applyProjectBoardCondition(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
// opts.ProjectBoardID == 0 means all project boards,
// do not need to apply any condition
if opts.ProjectBoardID > 0 {
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}))
} else if opts.ProjectBoardID == db.NoConditionID {
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Neq{"project_board_id": 0}))
}
return sess
}

func applyRepoConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {
if len(opts.RepoIDs) == 1 {
opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]}
Expand Down Expand Up @@ -240,13 +251,7 @@ func applyConditions(sess *xorm.Session, opts *IssuesOptions) *xorm.Session {

applyProjectCondition(sess, opts)

if opts.ProjectBoardID != 0 {
if opts.ProjectBoardID > 0 {
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": opts.ProjectBoardID}))
} else {
sess.In("issue.id", builder.Select("issue_id").From("project_issue").Where(builder.Eq{"project_board_id": 0}))
}
}
applyProjectBoardCondition(sess, opts)

switch opts.IsPull {
case util.OptionalBoolTrue:
Expand Down
2 changes: 1 addition & 1 deletion models/issues/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (pr *PullRequest) LoadAttributes(ctx context.Context) (err error) {
if pr.HasMerged && pr.Merger == nil {
pr.Merger, err = user_model.GetUserByID(ctx, pr.MergerID)
if user_model.IsErrUserNotExist(err) {
pr.MergerID = -1
pr.MergerID = user_model.GhostUserID
pr.Merger = user_model.NewGhostUser()
} else if err != nil {
return fmt.Errorf("getUserByID [%d]: %w", pr.MergerID, err)
Expand Down
3 changes: 1 addition & 2 deletions models/user/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func GenerateRandomAvatar(ctx context.Context, u *User) error {

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

Expand Down
4 changes: 2 additions & 2 deletions models/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ func GetUserByIDs(ctx context.Context, ids []int64) ([]*User, error) {
// GetPossibleUserByID returns the user if id > 0 or return system usrs if id < 0
func GetPossibleUserByID(ctx context.Context, id int64) (*User, error) {
switch id {
case -1:
case GhostUserID:
return NewGhostUser(), nil
case ActionsUserID:
return NewActionsUser(), nil
Expand All @@ -949,7 +949,7 @@ func GetPossibleUserByIDs(ctx context.Context, ids []int64) ([]*User, error) {
uniqueIDs := container.SetOf(ids...)
users := make([]*User, 0, len(ids))
_ = uniqueIDs.Remove(0)
if uniqueIDs.Remove(-1) {
if uniqueIDs.Remove(GhostUserID) {
users = append(users, NewGhostUser())
}
if uniqueIDs.Remove(ActionsUserID) {
Expand Down
16 changes: 11 additions & 5 deletions models/user/user_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ import (
"code.gitea.io/gitea/modules/structs"
)

const (
GhostUserID = -1
GhostUserName = "Ghost"
GhostUserLowerName = "ghost"
)

// NewGhostUser creates and returns a fake user for someone has deleted their account.
func NewGhostUser() *User {
return &User{
ID: -1,
Name: "Ghost",
LowerName: "ghost",
ID: GhostUserID,
Name: GhostUserName,
LowerName: GhostUserLowerName,
}
}

Expand All @@ -23,13 +29,13 @@ func (u *User) IsGhost() bool {
if u == nil {
return false
}
return u.ID == -1 && u.Name == "Ghost"
return u.ID == GhostUserID && u.Name == GhostUserName
}

// NewReplaceUser creates and returns a fake user for external user
func NewReplaceUser(name string) *User {
return &User{
ID: -1,
ID: 0,
Name: name,
LowerName: strings.ToLower(name),
}
Expand Down
35 changes: 20 additions & 15 deletions modules/doctor/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,29 @@ func deleteOrphanedRepos(ctx context.Context) (int64, error) {
adminUser := &user_model.User{IsAdmin: true}

for {
var ids []int64
if err := e.Table("`repository`").
Join("LEFT", "`user`", "repository.owner_id=user.id").
Where(builder.IsNull{"`user`.id"}).
Select("`repository`.id").Limit(batchSize).Find(&ids); err != nil {
return deleted, err
}
select {
case <-ctx.Done():
return deleted, ctx.Err()
default:
var ids []int64
if err := e.Table("`repository`").
Join("LEFT", "`user`", "repository.owner_id=user.id").
Where(builder.IsNull{"`user`.id"}).
Select("`repository`.id").Limit(batchSize).Find(&ids); err != nil {
return deleted, err
}

// if we don't get ids we have deleted them all
if len(ids) == 0 {
return deleted, nil
}
// if we don't get ids we have deleted them all
if len(ids) == 0 {
return deleted, nil
}

for _, id := range ids {
if err := repo_service.DeleteRepositoryDirectly(ctx, adminUser, id, true); err != nil {
return deleted, err
for _, id := range ids {
if err := repo_service.DeleteRepositoryDirectly(ctx, adminUser, id, true); err != nil {
return deleted, err
}
deleted++
}
deleted++
}
}
}
Expand Down
1 change: 0 additions & 1 deletion modules/indexer/issues/db/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
}

if len(options.IncludedLabelIDs) == 0 && len(options.IncludedAnyLabelIDs) > 0 {
_ = ctx // issue_model.GetLabelsByIDs should be called with ctx, this line can be removed when it's done.
labels, err := issue_model.GetLabelsByIDs(ctx, options.IncludedAnyLabelIDs, "name")
if err != nil {
return nil, fmt.Errorf("GetLabelsByIDs: %v", err)
Expand Down
21 changes: 10 additions & 11 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ remove = Remove
remove_all = Remove All
remove_label_str = Remove item "%s"
edit = Edit
view = View

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


[auth]
create_new_account = Register Account
register_helper_msg = Already have an account? Sign in now!
Expand Down Expand Up @@ -858,7 +858,7 @@ oauth2_client_secret_hint = The secret will not be shown again after you leave o
oauth2_application_edit = Edit
oauth2_application_create_description = OAuth2 applications gives your third-party application access to user accounts on this instance.
oauth2_application_remove_description = Removing an OAuth2 application will prevent it from accessing authorized user accounts on this instance. Continue?
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.
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.

authorized_oauth2_applications = Authorized OAuth2 Applications
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.
Expand Down Expand Up @@ -926,7 +926,7 @@ visibility.private = Private
visibility.private_tooltip = Visible only to members of organizations you have joined

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

transfer.accept = Accept Transfer
transfer.accept_desc = Transfer to "%s"
transfer.accept_desc = Transfer to "%s"
transfer.reject = Reject Transfer
transfer.reject_desc = Cancel transfer to "%s"
transfer.reject_desc = Cancel transfer to "%s"
transfer.no_permission_to_accept = You do not have permission to accept this transfer.
transfer.no_permission_to_reject = You do not have permission to reject this transfer.

Expand Down Expand Up @@ -1159,7 +1159,7 @@ releases = Releases
tag = Tag
released_this = released this
tagged_this = tagged this
file.title = %s at %s
file.title = %s at %s
file_raw = Raw
file_history = History
file_view_source = View Source
Expand Down Expand Up @@ -2507,7 +2507,6 @@ release.releases_for = Releases for %s
release.tags_for = Tags for %s

branch.name = Branch Name
branch.search = Search branches
branch.already_exists = A branch named "%s" already exists.
branch.delete_head = Delete
branch.delete = Delete Branch "%s"
Expand Down Expand Up @@ -3174,8 +3173,8 @@ monitor.start = Start Time
monitor.execute_time = Execution Time
monitor.last_execution_result = Result
monitor.process.cancel = Cancel process
monitor.process.cancel_desc = Cancelling a process may cause data loss
monitor.process.cancel_notices = Cancel: <strong>%s</strong>?
monitor.process.cancel_desc = Cancelling a process may cause data loss
monitor.process.cancel_notices = Cancel: <strong>%s</strong>?
monitor.process.children = Children

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

0 comments on commit ea65a8c

Please sign in to comment.