Skip to content

Commit e3d10b2

Browse files
authored
Merge branch 'main' into theme-meta-info
2 parents 40fd4b3 + f7d2f69 commit e3d10b2

File tree

123 files changed

+1905
-1168
lines changed

Some content is hidden

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

123 files changed

+1905
-1168
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ kerwin612 <[email protected]> (@kerwin612)
6161
Gary Wang <[email protected]> (@BLumia)
6262
Tim-Niclas Oelschläger <[email protected]> (@zokkis)
6363
Yu Liu <[email protected]> (@HEREYUA)
64+
Kemal Zebari <[email protected]> (@kemzeb)

cmd/hook.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,7 @@ Gitea or set your environment appropriately.`, "")
220220
}
221221
}
222222

223-
supportProcReceive := false
224-
if git.CheckGitVersionAtLeast("2.29") == nil {
225-
supportProcReceive = true
226-
}
223+
supportProcReceive := git.DefaultFeatures().SupportProcReceive
227224

228225
for scanner.Scan() {
229226
// TODO: support news feeds for wiki
@@ -341,6 +338,7 @@ Gitea or set your environment appropriately.`, "")
341338
isWiki, _ := strconv.ParseBool(os.Getenv(repo_module.EnvRepoIsWiki))
342339
repoName := os.Getenv(repo_module.EnvRepoName)
343340
pusherID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPusherID), 10, 64)
341+
prID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPRID), 10, 64)
344342
pusherName := os.Getenv(repo_module.EnvPusherName)
345343

346344
hookOptions := private.HookOptions{
@@ -350,6 +348,8 @@ Gitea or set your environment appropriately.`, "")
350348
GitObjectDirectory: os.Getenv(private.GitObjectDirectory),
351349
GitQuarantinePath: os.Getenv(private.GitQuarantinePath),
352350
GitPushOptions: pushOptions(),
351+
PullRequestID: prID,
352+
PushTrigger: repo_module.PushTrigger(os.Getenv(repo_module.EnvPushTrigger)),
353353
}
354354
oldCommitIDs := make([]string, hookBatchSize)
355355
newCommitIDs := make([]string, hookBatchSize)
@@ -497,7 +497,7 @@ Gitea or set your environment appropriately.`, "")
497497
return nil
498498
}
499499

500-
if git.CheckGitVersionAtLeast("2.29") != nil {
500+
if !git.DefaultFeatures().SupportProcReceive {
501501
return fail(ctx, "No proc-receive support", "current git version doesn't support proc-receive.")
502502
}
503503

cmd/migrate_storage.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var CmdMigrateStorage = &cli.Command{
3434
Name: "type",
3535
Aliases: []string{"t"},
3636
Value: "",
37-
Usage: "Type of stored files to copy. Allowed types: 'attachments', 'lfs', 'avatars', 'repo-avatars', 'repo-archivers', 'packages', 'actions-log'",
37+
Usage: "Type of stored files to copy. Allowed types: 'attachments', 'lfs', 'avatars', 'repo-avatars', 'repo-archivers', 'packages', 'actions-log', 'actions-artifacts",
3838
},
3939
&cli.StringFlag{
4040
Name: "storage",
@@ -160,6 +160,13 @@ func migrateActionsLog(ctx context.Context, dstStorage storage.ObjectStorage) er
160160
})
161161
}
162162

163+
func migrateActionsArtifacts(ctx context.Context, dstStorage storage.ObjectStorage) error {
164+
return db.Iterate(ctx, nil, func(ctx context.Context, artifact *actions_model.ActionArtifact) error {
165+
_, err := storage.Copy(dstStorage, artifact.ArtifactPath, storage.ActionsArtifacts, artifact.ArtifactPath)
166+
return err
167+
})
168+
}
169+
163170
func runMigrateStorage(ctx *cli.Context) error {
164171
stdCtx, cancel := installSignals()
165172
defer cancel()
@@ -223,13 +230,14 @@ func runMigrateStorage(ctx *cli.Context) error {
223230
}
224231

225232
migratedMethods := map[string]func(context.Context, storage.ObjectStorage) error{
226-
"attachments": migrateAttachments,
227-
"lfs": migrateLFS,
228-
"avatars": migrateAvatars,
229-
"repo-avatars": migrateRepoAvatars,
230-
"repo-archivers": migrateRepoArchivers,
231-
"packages": migratePackages,
232-
"actions-log": migrateActionsLog,
233+
"attachments": migrateAttachments,
234+
"lfs": migrateLFS,
235+
"avatars": migrateAvatars,
236+
"repo-avatars": migrateRepoAvatars,
237+
"repo-archivers": migrateRepoArchivers,
238+
"packages": migratePackages,
239+
"actions-log": migrateActionsLog,
240+
"actions-artifacts": migrateActionsArtifacts,
233241
}
234242

235243
tp := strings.ToLower(ctx.String("type"))

cmd/serv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func runServ(c *cli.Context) error {
178178
}
179179

180180
if len(words) < 2 {
181-
if git.CheckGitVersionAtLeast("2.29") == nil {
181+
if git.DefaultFeatures().SupportProcReceive {
182182
// for AGit Flow
183183
if cmd == "ssh_info" {
184184
fmt.Print(`{"type":"gitea","version":1}`)

docker/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Gitea - Docker
22

3-
Dockerfile is found in root of repository.
3+
Dockerfile is found in the root of the repository.
44

5-
Docker image can be found on [docker hub](https://hub.docker.com/r/gitea/gitea)
5+
Docker image can be found on [docker hub](https://hub.docker.com/r/gitea/gitea).
66

7-
Documentation on using docker image can be found on [Gitea Docs site](https://docs.gitea.com/installation/install-with-docker-rootless)
7+
Documentation on using docker image can be found on [Gitea Docs site](https://docs.gitea.com/installation/install-with-docker-rootless).

models/db/engine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type Engine interface {
5757
SumInt(bean any, columnName string) (res int64, err error)
5858
Sync(...any) error
5959
Select(string) *xorm.Session
60+
SetExpr(string, any) *xorm.Session
6061
NotIn(string, ...any) *xorm.Session
6162
OrderBy(any, ...any) *xorm.Session
6263
Exist(...any) (bool, error)

models/issues/issue_project.go

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ package issues
55

66
import (
77
"context"
8-
"fmt"
98

109
"code.gitea.io/gitea/models/db"
1110
project_model "code.gitea.io/gitea/models/project"
1211
user_model "code.gitea.io/gitea/models/user"
12+
"code.gitea.io/gitea/modules/util"
1313
)
1414

1515
// LoadProject load the project the issue was assigned to
@@ -90,58 +90,73 @@ func LoadIssuesFromBoardList(ctx context.Context, bs project_model.BoardList) (m
9090
return issuesMap, nil
9191
}
9292

93-
// ChangeProjectAssign changes the project associated with an issue
94-
func ChangeProjectAssign(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64) error {
95-
ctx, committer, err := db.TxContext(ctx)
96-
if err != nil {
97-
return err
98-
}
99-
defer committer.Close()
100-
101-
if err := addUpdateIssueProject(ctx, issue, doer, newProjectID); err != nil {
102-
return err
103-
}
104-
105-
return committer.Commit()
106-
}
93+
// IssueAssignOrRemoveProject changes the project associated with an issue
94+
// If newProjectID is 0, the issue is removed from the project
95+
func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID, newColumnID int64) error {
96+
return db.WithTx(ctx, func(ctx context.Context) error {
97+
oldProjectID := issue.projectID(ctx)
10798

108-
func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.User, newProjectID int64) error {
109-
oldProjectID := issue.projectID(ctx)
99+
if err := issue.LoadRepo(ctx); err != nil {
100+
return err
101+
}
110102

111-
if err := issue.LoadRepo(ctx); err != nil {
112-
return err
113-
}
103+
// Only check if we add a new project and not remove it.
104+
if newProjectID > 0 {
105+
newProject, err := project_model.GetProjectByID(ctx, newProjectID)
106+
if err != nil {
107+
return err
108+
}
109+
if !newProject.CanBeAccessedByOwnerRepo(issue.Repo.OwnerID, issue.Repo) {
110+
return util.NewPermissionDeniedErrorf("issue %d can't be accessed by project %d", issue.ID, newProject.ID)
111+
}
112+
if newColumnID == 0 {
113+
newDefaultColumn, err := newProject.GetDefaultBoard(ctx)
114+
if err != nil {
115+
return err
116+
}
117+
newColumnID = newDefaultColumn.ID
118+
}
119+
}
114120

115-
// Only check if we add a new project and not remove it.
116-
if newProjectID > 0 {
117-
newProject, err := project_model.GetProjectByID(ctx, newProjectID)
118-
if err != nil {
121+
if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil {
119122
return err
120123
}
121-
if newProject.RepoID != issue.RepoID && newProject.OwnerID != issue.Repo.OwnerID {
122-
return fmt.Errorf("issue's repository is not the same as project's repository")
123-
}
124-
}
125124

126-
if _, err := db.GetEngine(ctx).Where("project_issue.issue_id=?", issue.ID).Delete(&project_model.ProjectIssue{}); err != nil {
127-
return err
128-
}
125+
if oldProjectID > 0 || newProjectID > 0 {
126+
if _, err := CreateComment(ctx, &CreateCommentOptions{
127+
Type: CommentTypeProject,
128+
Doer: doer,
129+
Repo: issue.Repo,
130+
Issue: issue,
131+
OldProjectID: oldProjectID,
132+
ProjectID: newProjectID,
133+
}); err != nil {
134+
return err
135+
}
136+
}
137+
if newProjectID == 0 {
138+
return nil
139+
}
140+
if newColumnID == 0 {
141+
panic("newColumnID must not be zero") // shouldn't happen
142+
}
129143

130-
if oldProjectID > 0 || newProjectID > 0 {
131-
if _, err := CreateComment(ctx, &CreateCommentOptions{
132-
Type: CommentTypeProject,
133-
Doer: doer,
134-
Repo: issue.Repo,
135-
Issue: issue,
136-
OldProjectID: oldProjectID,
137-
ProjectID: newProjectID,
138-
}); err != nil {
144+
res := struct {
145+
MaxSorting int64
146+
IssueCount int64
147+
}{}
148+
if _, err := db.GetEngine(ctx).Select("max(sorting) as max_sorting, count(*) as issue_count").Table("project_issue").
149+
Where("project_id=?", newProjectID).
150+
And("project_board_id=?", newColumnID).
151+
Get(&res); err != nil {
139152
return err
140153
}
141-
}
142-
143-
return db.Insert(ctx, &project_model.ProjectIssue{
144-
IssueID: issue.ID,
145-
ProjectID: newProjectID,
154+
newSorting := util.Iif(res.IssueCount > 0, res.MaxSorting+1, 0)
155+
return db.Insert(ctx, &project_model.ProjectIssue{
156+
IssueID: issue.ID,
157+
ProjectID: newProjectID,
158+
ProjectBoardID: newColumnID,
159+
Sorting: newSorting,
160+
})
146161
})
147162
}

models/issues/issue_update.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -429,62 +429,6 @@ func UpdateIssueMentions(ctx context.Context, issueID int64, mentions []*user_mo
429429
return nil
430430
}
431431

432-
// UpdateIssueByAPI updates all allowed fields of given issue.
433-
// If the issue status is changed a statusChangeComment is returned
434-
// similarly if the title is changed the titleChanged bool is set to true
435-
func UpdateIssueByAPI(ctx context.Context, issue *Issue, doer *user_model.User) (statusChangeComment *Comment, titleChanged bool, err error) {
436-
ctx, committer, err := db.TxContext(ctx)
437-
if err != nil {
438-
return nil, false, err
439-
}
440-
defer committer.Close()
441-
442-
if err := issue.LoadRepo(ctx); err != nil {
443-
return nil, false, fmt.Errorf("loadRepo: %w", err)
444-
}
445-
446-
// Reload the issue
447-
currentIssue, err := GetIssueByID(ctx, issue.ID)
448-
if err != nil {
449-
return nil, false, err
450-
}
451-
452-
if _, err := db.GetEngine(ctx).ID(issue.ID).Cols(
453-
"name", "content", "milestone_id", "priority",
454-
"deadline_unix", "updated_unix", "is_locked").
455-
Update(issue); err != nil {
456-
return nil, false, err
457-
}
458-
459-
titleChanged = currentIssue.Title != issue.Title
460-
if titleChanged {
461-
opts := &CreateCommentOptions{
462-
Type: CommentTypeChangeTitle,
463-
Doer: doer,
464-
Repo: issue.Repo,
465-
Issue: issue,
466-
OldTitle: currentIssue.Title,
467-
NewTitle: issue.Title,
468-
}
469-
_, err := CreateComment(ctx, opts)
470-
if err != nil {
471-
return nil, false, fmt.Errorf("createComment: %w", err)
472-
}
473-
}
474-
475-
if currentIssue.IsClosed != issue.IsClosed {
476-
statusChangeComment, err = doChangeIssueStatus(ctx, issue, doer, false)
477-
if err != nil {
478-
return nil, false, err
479-
}
480-
}
481-
482-
if err := issue.AddCrossReferences(ctx, doer, true); err != nil {
483-
return nil, false, err
484-
}
485-
return statusChangeComment, titleChanged, committer.Commit()
486-
}
487-
488432
// UpdateIssueDeadline updates an issue deadline and adds comments. Setting a deadline to 0 means deleting it.
489433
func UpdateIssueDeadline(ctx context.Context, issue *Issue, deadlineUnix timeutil.TimeStamp, doer *user_model.User) (err error) {
490434
// if the deadline hasn't changed do nothing

0 commit comments

Comments
 (0)