From c8f707b89071a5d75af2906cde92f849c5529649 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 10 Jul 2023 08:30:09 +0000 Subject: [PATCH 01/97] fix --- models/git/branch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/git/branch.go b/models/git/branch.go index 97891f01ebb40..ca38130bdc4af 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -391,7 +391,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64) (B "issue.is_closed": false, }) err := db.GetEngine(ctx). - Where("pusher_id=? AND is_deleted=?", userID, false). + Where("repo_id=? AND pusher_id=? AND is_deleted=?", repoID, userID, false). And("updated_unix >= ?", time.Now().Add(-time.Hour*6).Unix()). NotIn("name", subQuery). OrderBy("branch.updated_unix DESC"). From b3e3b7311cef5921de84130476c5b3693631d283 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 11 Jul 2023 01:10:12 +0000 Subject: [PATCH 02/97] support show notification in origin repo --- models/git/branch.go | 26 ++++++++++++++++--- models/git/branch_list.go | 21 +++++++++++++++ routers/web/repo/view.go | 9 +++++-- .../code/recently_pushed_new_branches.tmpl | 11 ++++++-- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index ca38130bdc4af..87c54e026e4f6 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -102,8 +102,9 @@ func (err ErrBranchesEqual) Unwrap() error { // for pagination, keyword search and filtering type Branch struct { ID int64 - RepoID int64 `xorm:"UNIQUE(s)"` - Name string `xorm:"UNIQUE(s) NOT NULL"` // git's ref-name is case-sensitive internally, however, in some databases (mssql, mysql, by default), it's case-insensitive at the moment + RepoID int64 `xorm:"UNIQUE(s)"` + Repo *repo_model.Repository `xorm:"-"` + Name string `xorm:"UNIQUE(s) NOT NULL"` // git's ref-name is case-sensitive internally, however, in some databases (mssql, mysql, by default), it's case-insensitive at the moment CommitID string CommitMessage string `xorm:"TEXT"` // it only stores the message summary (the first line) PusherID int64 @@ -139,6 +140,16 @@ func (b *Branch) LoadPusher(ctx context.Context) (err error) { return err } +func (b *Branch) LoadRepo(ctx context.Context) (err error) { + if b.Repo == nil && b.RepoID > 0 { + b.Repo, err = repo_model.GetRepositoryByID(ctx, b.RepoID) + if repo_model.IsErrRepoNotExist(err) { + err = nil + } + } + return err +} + func init() { db.RegisterModel(new(Branch)) db.RegisterModel(new(RenamedBranch)) @@ -382,8 +393,14 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str } // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created -func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64) (BranchList, error) { +func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64, latestCommitID string) (BranchList, error) { branches := make(BranchList, 0, 2) + repoCond := builder.Select("id").From("repository"). + Where(builder.Or( + builder.Eq{"id": repoID, "is_fork": false}, + builder.Eq{"is_fork": true, "fork_id": repoID}, + )) + subQuery := builder.Select("head_branch").From("pull_request"). InnerJoin("issue", "issue.id = pull_request.issue_id"). Where(builder.Eq{ @@ -391,9 +408,10 @@ func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64) (B "issue.is_closed": false, }) err := db.GetEngine(ctx). - Where("repo_id=? AND pusher_id=? AND is_deleted=?", repoID, userID, false). + Where("commit_id != ? AND pusher_id = ? AND is_deleted = ?", latestCommitID, userID, false). And("updated_unix >= ?", time.Now().Add(-time.Hour*6).Unix()). NotIn("name", subQuery). + In("repo_id", repoCond). OrderBy("branch.updated_unix DESC"). Limit(2). Find(&branches) diff --git a/models/git/branch_list.go b/models/git/branch_list.go index 131a149782e27..a87e93c05aa07 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -7,6 +7,7 @@ import ( "context" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/util" @@ -64,6 +65,26 @@ func (branches BranchList) LoadPusher(ctx context.Context) error { return nil } +func (branches BranchList) LoadRepo(ctx context.Context) error { + ids := container.Set[int64]{} + for _, branch := range branches { + if branch.RepoID > 0 { + ids.Add(branch.RepoID) + } + } + reposMap := make(map[int64]*repo_model.Repository, len(ids)) + if err := db.GetEngine(ctx).In("id", ids.Values()).Find(&reposMap); err != nil { + return err + } + for _, branch := range branches { + if branch.RepoID <= 0 { + continue + } + branch.Repo = reposMap[branch.RepoID] + } + return nil +} + type FindBranchOptions struct { db.ListOptions RepoID int64 diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index acea08d6297ec..852cf8cc76a68 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -982,11 +982,16 @@ func renderCode(ctx *context.Context) { ctx.ServerError("GetBaseRepo", err) return } - ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID) + branches, err := git_model.FindRecentlyPushedNewBranches(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID, ctx.Repo.CommitID) if err != nil { - ctx.ServerError("GetRecentlyPushedBranches", err) + ctx.ServerError("FindRecentlyPushedNewBranches", err) return } + if err := branches.LoadRepo(ctx); err != nil { + ctx.ServerError("branches.LoadRepo", err) + return + } + ctx.Data["RecentlyPushedNewBranches"] = branches } var treeNames []string diff --git a/templates/repo/code/recently_pushed_new_branches.tmpl b/templates/repo/code/recently_pushed_new_branches.tmpl index e936fa4bb462b..0a3f3f8965db0 100644 --- a/templates/repo/code/recently_pushed_new_branches.tmpl +++ b/templates/repo/code/recently_pushed_new_branches.tmpl @@ -1,10 +1,17 @@ {{range .RecentlyPushedNewBranches}} + {{$pullRepo := $.Repository}} + {{$branchName := .Name}} + {{if .Repo}} + {{$pullRepo = .Repo}} + {{$branchName = (print $pullRepo.FullName ":" .Name)}} + {{end}}
{{$timeSince := TimeSince .UpdatedUnix.AsTime $.locale}} - {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" (PathEscapeSegments .Name) $timeSince | Safe}} + {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" (PathEscapeSegments $branchName) $timeSince | Safe}}
- + + {{$.locale.Tr "repo.pulls.compare_changes"}}
From df97530659c8e1f789c02c105316eb5632582853 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 11 Jul 2023 01:39:58 +0000 Subject: [PATCH 03/97] support show notification in forked repo --- routers/web/repo/view.go | 18 +++++++++++++++++- .../code/recently_pushed_new_branches.tmpl | 10 ++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 852cf8cc76a68..7c649ea369fb8 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -982,7 +982,23 @@ func renderCode(ctx *context.Context) { ctx.ServerError("GetBaseRepo", err) return } - branches, err := git_model.FindRecentlyPushedNewBranches(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID, ctx.Repo.CommitID) + baseRepo := ctx.Repo.Repository + latestCommit := ctx.Repo.Commit + if ctx.Repo.Repository.IsFork { + baseRepo = ctx.Repo.Repository.BaseRepo + repoPath := repo_model.RepoPath(baseRepo.OwnerName, baseRepo.Name) + gitRepo, err := git.OpenRepository(ctx, repoPath) + if err != nil { + ctx.ServerError("OpenRepository", err) + return + } + latestCommit, err = gitRepo.GetBranchCommit(baseRepo.DefaultBranch) + if err != nil { + ctx.ServerError("GetBranchCommit", err) + return + } + } + branches, err := git_model.FindRecentlyPushedNewBranches(ctx, baseRepo.ID, ctx.Doer.ID, latestCommit.ID.String()) if err != nil { ctx.ServerError("FindRecentlyPushedNewBranches", err) return diff --git a/templates/repo/code/recently_pushed_new_branches.tmpl b/templates/repo/code/recently_pushed_new_branches.tmpl index 0a3f3f8965db0..953063c06d17e 100644 --- a/templates/repo/code/recently_pushed_new_branches.tmpl +++ b/templates/repo/code/recently_pushed_new_branches.tmpl @@ -1,9 +1,15 @@ {{range .RecentlyPushedNewBranches}} {{$pullRepo := $.Repository}} + {{$baseRepo := $.Repository}} {{$branchName := .Name}} {{if .Repo}} {{$pullRepo = .Repo}} - {{$branchName = (print $pullRepo.FullName ":" .Name)}} + {{if and $.Repository.IsFork}} + {{$baseRepo = $.Repository.BaseRepo}} + {{end}} + {{if not (eq .Repo.ID $.Repository.ID)}} + {{$branchName = (print .Repo.FullName ":" .Name)}} + {{end}} {{end}}
@@ -11,7 +17,7 @@ {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" (PathEscapeSegments $branchName) $timeSince | Safe}}
- + {{$.locale.Tr "repo.pulls.compare_changes"}}
From 71dd7404160ed117fec0eb48f3a14e40d4850742 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 11 Jul 2023 02:35:36 +0000 Subject: [PATCH 04/97] avoid attach already created pr branch --- models/git/branch.go | 16 +++++++++------- routers/web/repo/view.go | 16 +++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index 87c54e026e4f6..d84c8cd5a7447 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -395,22 +395,24 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64, latestCommitID string) (BranchList, error) { branches := make(BranchList, 0, 2) + // search all related repos repoCond := builder.Select("id").From("repository"). Where(builder.Or( builder.Eq{"id": repoID, "is_fork": false}, builder.Eq{"is_fork": true, "fork_id": repoID}, )) - - subQuery := builder.Select("head_branch").From("pull_request"). + // avoid check branches which have already created PRs + usedBranchIDs := builder.Select("branch.id").From("branch"). + InnerJoin("pull_request", "branch.name = pull_request.head_branch AND branch.repo_id = pull_request.head_repo_id"). InnerJoin("issue", "issue.id = pull_request.issue_id"). - Where(builder.Eq{ - "pull_request.head_repo_id": repoID, - "issue.is_closed": false, - }) + Where(builder.And( + builder.Eq{"issue.is_closed": false}, + builder.In("pull_request.head_repo_id", repoCond), + )) err := db.GetEngine(ctx). Where("commit_id != ? AND pusher_id = ? AND is_deleted = ?", latestCommitID, userID, false). And("updated_unix >= ?", time.Now().Add(-time.Hour*6).Unix()). - NotIn("name", subQuery). + NotIn("id", usedBranchIDs). In("repo_id", repoCond). OrderBy("branch.updated_unix DESC"). Limit(2). diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 7c649ea369fb8..eb923a2a5b4ec 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -982,21 +982,23 @@ func renderCode(ctx *context.Context) { ctx.ServerError("GetBaseRepo", err) return } + + var latestCommit *git.Commit baseRepo := ctx.Repo.Repository - latestCommit := ctx.Repo.Commit + gitRepo := ctx.Repo.GitRepo if ctx.Repo.Repository.IsFork { baseRepo = ctx.Repo.Repository.BaseRepo repoPath := repo_model.RepoPath(baseRepo.OwnerName, baseRepo.Name) - gitRepo, err := git.OpenRepository(ctx, repoPath) + gitRepo, err = git.OpenRepository(ctx, repoPath) if err != nil { ctx.ServerError("OpenRepository", err) return } - latestCommit, err = gitRepo.GetBranchCommit(baseRepo.DefaultBranch) - if err != nil { - ctx.ServerError("GetBranchCommit", err) - return - } + } + latestCommit, err = gitRepo.GetBranchCommit(baseRepo.DefaultBranch) + if err != nil { + ctx.ServerError("GetBranchCommit", err) + return } branches, err := git_model.FindRecentlyPushedNewBranches(ctx, baseRepo.ID, ctx.Doer.ID, latestCommit.ID.String()) if err != nil { From 2b0abf933184effda634698d1a19bd6c2a849696 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 11 Jul 2023 04:18:36 +0000 Subject: [PATCH 05/97] use branch.id instead of branch.name --- models/git/branch.go | 19 ++++++++++++------- routers/web/repo/view.go | 15 +-------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index d84c8cd5a7447..56653f01eac32 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -393,26 +393,31 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str } // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created -func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64, latestCommitID string) (BranchList, error) { +func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Repository, userID int64) (BranchList, error) { branches := make(BranchList, 0, 2) + baseBranch, err := GetBranch(ctx, baseRepo.ID, baseRepo.DefaultBranch) + if err != nil { + return nil, err + } // search all related repos repoCond := builder.Select("id").From("repository"). Where(builder.Or( - builder.Eq{"id": repoID, "is_fork": false}, - builder.Eq{"is_fork": true, "fork_id": repoID}, + builder.Eq{"id": baseRepo.ID, "is_fork": false}, + builder.Eq{"is_fork": true, "fork_id": baseRepo.ID}, )) // avoid check branches which have already created PRs - usedBranchIDs := builder.Select("branch.id").From("branch"). + // TODO add head_branch_id in pull_request table + invalidBranchCond := builder.Select("branch.id").From("branch"). InnerJoin("pull_request", "branch.name = pull_request.head_branch AND branch.repo_id = pull_request.head_repo_id"). InnerJoin("issue", "issue.id = pull_request.issue_id"). Where(builder.And( builder.Eq{"issue.is_closed": false}, builder.In("pull_request.head_repo_id", repoCond), )) - err := db.GetEngine(ctx). - Where("commit_id != ? AND pusher_id = ? AND is_deleted = ?", latestCommitID, userID, false). + err = db.GetEngine(ctx). + Where("id != ? AND commit_id != ? AND pusher_id = ? AND is_deleted = ?", baseBranch.ID, baseBranch.CommitID, userID, false). And("updated_unix >= ?", time.Now().Add(-time.Hour*6).Unix()). - NotIn("id", usedBranchIDs). + NotIn("id", invalidBranchCond). In("repo_id", repoCond). OrderBy("branch.updated_unix DESC"). Limit(2). diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index eb923a2a5b4ec..a75f26795a05f 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -983,24 +983,11 @@ func renderCode(ctx *context.Context) { return } - var latestCommit *git.Commit baseRepo := ctx.Repo.Repository - gitRepo := ctx.Repo.GitRepo if ctx.Repo.Repository.IsFork { baseRepo = ctx.Repo.Repository.BaseRepo - repoPath := repo_model.RepoPath(baseRepo.OwnerName, baseRepo.Name) - gitRepo, err = git.OpenRepository(ctx, repoPath) - if err != nil { - ctx.ServerError("OpenRepository", err) - return - } - } - latestCommit, err = gitRepo.GetBranchCommit(baseRepo.DefaultBranch) - if err != nil { - ctx.ServerError("GetBranchCommit", err) - return } - branches, err := git_model.FindRecentlyPushedNewBranches(ctx, baseRepo.ID, ctx.Doer.ID, latestCommit.ID.String()) + branches, err := git_model.FindRecentlyPushedNewBranches(ctx, baseRepo, ctx.Doer.ID) if err != nil { ctx.ServerError("FindRecentlyPushedNewBranches", err) return From 4c116821fa373898c1da64a02391eaf46f1ad3ff Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 11 Jul 2023 04:25:41 +0000 Subject: [PATCH 06/97] allow forked repo from forked repo --- models/git/branch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/git/branch.go b/models/git/branch.go index 56653f01eac32..89913ff5a8be4 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -402,7 +402,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Rep // search all related repos repoCond := builder.Select("id").From("repository"). Where(builder.Or( - builder.Eq{"id": baseRepo.ID, "is_fork": false}, + builder.Eq{"id": baseRepo.ID}, builder.Eq{"is_fork": true, "fork_id": baseRepo.ID}, )) // avoid check branches which have already created PRs From 54f4fd56cdb28ad14bd91b1b4a3d9f23a54bf2dc Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 11 Jul 2023 05:02:20 +0000 Subject: [PATCH 07/97] improve TODO --- models/git/branch.go | 8 +++++--- routers/web/repo/view.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index 89913ff5a8be4..711f5768e3b26 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -393,7 +393,9 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str } // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created -func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Repository, userID int64) (BranchList, error) { +// doer should not be nil +// TODO use options to find the branches +func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Repository, doer *user_model.User) (BranchList, error) { branches := make(BranchList, 0, 2) baseBranch, err := GetBranch(ctx, baseRepo.ID, baseRepo.DefaultBranch) if err != nil { @@ -406,7 +408,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Rep builder.Eq{"is_fork": true, "fork_id": baseRepo.ID}, )) // avoid check branches which have already created PRs - // TODO add head_branch_id in pull_request table + // TODO add head_branch_id in pull_request table then we can get the branch id from pull_request table directly invalidBranchCond := builder.Select("branch.id").From("branch"). InnerJoin("pull_request", "branch.name = pull_request.head_branch AND branch.repo_id = pull_request.head_repo_id"). InnerJoin("issue", "issue.id = pull_request.issue_id"). @@ -415,7 +417,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Rep builder.In("pull_request.head_repo_id", repoCond), )) err = db.GetEngine(ctx). - Where("id != ? AND commit_id != ? AND pusher_id = ? AND is_deleted = ?", baseBranch.ID, baseBranch.CommitID, userID, false). + Where("id != ? AND commit_id != ? AND pusher_id = ? AND is_deleted = ?", baseBranch.ID, baseBranch.CommitID, doer.ID, false). And("updated_unix >= ?", time.Now().Add(-time.Hour*6).Unix()). NotIn("id", invalidBranchCond). In("repo_id", repoCond). diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index a75f26795a05f..e844dcf82b76e 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -987,7 +987,7 @@ func renderCode(ctx *context.Context) { if ctx.Repo.Repository.IsFork { baseRepo = ctx.Repo.Repository.BaseRepo } - branches, err := git_model.FindRecentlyPushedNewBranches(ctx, baseRepo, ctx.Doer.ID) + branches, err := git_model.FindRecentlyPushedNewBranches(ctx, baseRepo, ctx.Doer) if err != nil { ctx.ServerError("FindRecentlyPushedNewBranches", err) return From 172ceebf14cbe4a9a3ef857ce8c503255fa05047 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 11 Jul 2023 05:04:24 +0000 Subject: [PATCH 08/97] fix lint --- templates/repo/code/recently_pushed_new_branches.tmpl | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/repo/code/recently_pushed_new_branches.tmpl b/templates/repo/code/recently_pushed_new_branches.tmpl index 953063c06d17e..339c40fca382e 100644 --- a/templates/repo/code/recently_pushed_new_branches.tmpl +++ b/templates/repo/code/recently_pushed_new_branches.tmpl @@ -16,7 +16,6 @@ {{$timeSince := TimeSince .UpdatedUnix.AsTime $.locale}} {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" (PathEscapeSegments $branchName) $timeSince | Safe}} - {{$.locale.Tr "repo.pulls.compare_changes"}} From bc176bb1bc3b61494ef1564c0c94475e74d296a5 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 13 Jul 2023 06:20:33 +0000 Subject: [PATCH 09/97] improve --- models/git/branch.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index 711f5768e3b26..59c1f48b48e31 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -412,17 +412,19 @@ func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Rep invalidBranchCond := builder.Select("branch.id").From("branch"). InnerJoin("pull_request", "branch.name = pull_request.head_branch AND branch.repo_id = pull_request.head_repo_id"). InnerJoin("issue", "issue.id = pull_request.issue_id"). - Where(builder.And( - builder.Eq{"issue.is_closed": false}, + Where(builder.Or( + builder.Eq{"pull_request.has_merged": true}, builder.In("pull_request.head_repo_id", repoCond), + builder.Eq{"branch.id": baseBranch.ID}, )) - err = db.GetEngine(ctx). - Where("id != ? AND commit_id != ? AND pusher_id = ? AND is_deleted = ?", baseBranch.ID, baseBranch.CommitID, doer.ID, false). - And("updated_unix >= ?", time.Now().Add(-time.Hour*6).Unix()). - NotIn("id", invalidBranchCond). - In("repo_id", repoCond). - OrderBy("branch.updated_unix DESC"). - Limit(2). - Find(&branches) + cond := builder.And( + builder.Neq{"commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them + builder.Eq{"pusher_id": doer.ID}, + builder.Eq{"is_deleted": false}, + builder.Gte{"updated_unix": time.Now().Add(-time.Hour * 6).Unix()}, + builder.In("repo_id", repoCond), + builder.NotIn("id", invalidBranchCond), + ) + err = db.GetEngine(ctx).Where(cond).OrderBy("branch.updated_unix DESC").Limit(2).Find(&branches) return branches, err } From d3f72aac2fdb9f9c7f871d395032319e32443fe2 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 13 Jul 2023 07:52:58 +0000 Subject: [PATCH 10/97] remove PathEscapeSegments --- templates/repo/code/recently_pushed_new_branches.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/code/recently_pushed_new_branches.tmpl b/templates/repo/code/recently_pushed_new_branches.tmpl index 339c40fca382e..177dc5ee8e141 100644 --- a/templates/repo/code/recently_pushed_new_branches.tmpl +++ b/templates/repo/code/recently_pushed_new_branches.tmpl @@ -14,9 +14,9 @@
{{$timeSince := TimeSince .UpdatedUnix.AsTime $.locale}} - {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" (PathEscapeSegments $branchName) $timeSince | Safe}} + {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" $branchName $timeSince | Safe}}
- + {{$.locale.Tr "repo.pulls.compare_changes"}}
From d93b2bcc80dfe191a6e70c29ffec903bbf7c2362 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 20 Jul 2023 05:19:56 +0000 Subject: [PATCH 11/97] use findbranch to search branch --- models/git/branch.go | 23 ++++++++--------- models/git/branch_list.go | 38 ++++++++++++++++++++++++++--- models/git/protected_branch_list.go | 2 +- modules/context/repo.go | 2 +- modules/repository/branch.go | 2 +- routers/api/v1/repo/branch.go | 4 +-- routers/web/repo/compare.go | 4 +-- routers/web/repo/issue.go | 2 +- services/repository/adopt.go | 2 +- services/repository/branch.go | 2 +- 10 files changed, 57 insertions(+), 24 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index 59c1f48b48e31..c0f95e7a89e06 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -396,7 +396,6 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str // doer should not be nil // TODO use options to find the branches func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Repository, doer *user_model.User) (BranchList, error) { - branches := make(BranchList, 0, 2) baseBranch, err := GetBranch(ctx, baseRepo.ID, baseRepo.DefaultBranch) if err != nil { return nil, err @@ -417,14 +416,16 @@ func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Rep builder.In("pull_request.head_repo_id", repoCond), builder.Eq{"branch.id": baseBranch.ID}, )) - cond := builder.And( - builder.Neq{"commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them - builder.Eq{"pusher_id": doer.ID}, - builder.Eq{"is_deleted": false}, - builder.Gte{"updated_unix": time.Now().Add(-time.Hour * 6).Unix()}, - builder.In("repo_id", repoCond), - builder.NotIn("id", invalidBranchCond), - ) - err = db.GetEngine(ctx).Where(cond).OrderBy("branch.updated_unix DESC").Limit(2).Find(&branches) - return branches, err + + opts := FindBranchOptions{ + IDCond: builder.NotIn("id", invalidBranchCond), + RepoCond: builder.In("repo_id", repoCond), + CommitCond: builder.Neq{"commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them, + PusherID: doer.ID, + IsDeletedBranch: util.OptionalBoolFalse, + OrderBy: "branch.updated_unix DESC", + } + opts.PageSize = 2 + opts.Page = 1 + return FindBranches(ctx, opts) } diff --git a/models/git/branch_list.go b/models/git/branch_list.go index a87e93c05aa07..b089405a3a54c 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -10,6 +10,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/container" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" "xorm.io/builder" @@ -87,24 +88,55 @@ func (branches BranchList) LoadRepo(ctx context.Context) error { type FindBranchOptions struct { db.ListOptions - RepoID int64 + IDCond builder.Cond + RepoIDs []int64 // overwrites RepoCond if the length is not 0 + RepoCond builder.Cond ExcludeBranchNames []string + CommitCond builder.Cond + PusherID int64 IsDeletedBranch util.OptionalBool + UpdatedAfterUnix timeutil.TimeStamp + UpdatedBeforeUnix timeutil.TimeStamp OrderBy string } func (opts *FindBranchOptions) Cond() builder.Cond { cond := builder.NewCond() - if opts.RepoID > 0 { - cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) + if opts.IDCond != nil { + cond = cond.And(opts.IDCond) + } + + if len(opts.RepoIDs) == 1 { + opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]} + } else if len(opts.RepoIDs) > 1 { + opts.RepoCond = builder.In("issue.repo_id", opts.RepoIDs) + } + if opts.RepoCond != nil { + cond = cond.And(opts.RepoCond) } if len(opts.ExcludeBranchNames) > 0 { cond = cond.And(builder.NotIn("name", opts.ExcludeBranchNames)) } + + if opts.CommitCond != nil { + cond = cond.And(opts.CommitCond) + } + + if opts.PusherID > 0 { + cond = cond.And(builder.Eq{"pusher_id": opts.PusherID}) + } + if !opts.IsDeletedBranch.IsNone() { cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.IsTrue()}) } + + if opts.UpdatedAfterUnix != 0 { + cond = cond.And(builder.Gte{"updated_unix": opts.UpdatedAfterUnix}) + } + if opts.UpdatedBeforeUnix != 0 { + cond = cond.And(builder.Lte{"updated_unix": opts.UpdatedBeforeUnix}) + } return cond } diff --git a/models/git/protected_branch_list.go b/models/git/protected_branch_list.go index eeb307e2454e7..f67bb14d173db 100644 --- a/models/git/protected_branch_list.go +++ b/models/git/protected_branch_list.go @@ -55,7 +55,7 @@ func FindAllMatchedBranches(ctx context.Context, repoID int64, ruleName string) PageSize: 100, Page: page, }, - RepoID: repoID, + RepoIDs: []int64{repoID}, IsDeletedBranch: util.OptionalBoolFalse, }) if err != nil { diff --git a/modules/context/repo.go b/modules/context/repo.go index eae71cfb7be67..6eb08bef58847 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -668,7 +668,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc { ctx.Data["Tags"] = tags branchOpts := git_model.FindBranchOptions{ - RepoID: ctx.Repo.Repository.ID, + RepoIDs: []int64{ctx.Repo.Repository.ID}, IsDeletedBranch: util.OptionalBoolFalse, ListOptions: db.ListOptions{ ListAll: true, diff --git a/modules/repository/branch.go b/modules/repository/branch.go index bffadd62f4d92..2c45dbb7f2707 100644 --- a/modules/repository/branch.go +++ b/modules/repository/branch.go @@ -53,7 +53,7 @@ func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository, ListOptions: db.ListOptions{ ListAll: true, }, - RepoID: repo.ID, + RepoIDs: []int64{repo.ID}, }) if err != nil { return 0, err diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index 5e2c9878f0884..62c776403850a 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -142,7 +142,7 @@ func DeleteBranch(ctx *context.APIContext) { // check whether branches of this repository has been synced totalNumOfBranches, err := git_model.CountBranches(ctx, git_model.FindBranchOptions{ - RepoID: ctx.Repo.Repository.ID, + RepoIDs: []int64{ctx.Repo.Repository.ID}, IsDeletedBranch: util.OptionalBoolFalse, }) if err != nil { @@ -349,7 +349,7 @@ func ListBranches(ctx *context.APIContext) { branchOpts := git_model.FindBranchOptions{ ListOptions: listOptions, - RepoID: ctx.Repo.Repository.ID, + RepoIDs: []int64{ctx.Repo.Repository.ID}, IsDeletedBranch: util.OptionalBoolFalse, } var err error diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 7089c219ad25c..68ccfcb1a5aa2 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -685,7 +685,7 @@ func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repositor defer gitRepo.Close() branches, err = git_model.FindBranchNames(ctx, git_model.FindBranchOptions{ - RepoID: repo.ID, + RepoIDs: []int64{repo.ID}, ListOptions: db.ListOptions{ ListAll: true, }, @@ -742,7 +742,7 @@ func CompareDiff(ctx *context.Context) { } headBranches, err := git_model.FindBranchNames(ctx, git_model.FindBranchOptions{ - RepoID: ci.HeadRepo.ID, + RepoIDs: []int64{ci.HeadRepo.ID}, ListOptions: db.ListOptions{ ListAll: true, }, diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index bd8959846c0ed..603f5a3fad892 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -786,7 +786,7 @@ func RetrieveRepoMetas(ctx *context.Context, repo *repo_model.Repository, isPull } brs, err := git_model.FindBranchNames(ctx, git_model.FindBranchOptions{ - RepoID: ctx.Repo.Repository.ID, + RepoIDs: []int64{ctx.Repo.Repository.ID}, ListOptions: db.ListOptions{ ListAll: true, }, diff --git a/services/repository/adopt.go b/services/repository/adopt.go index f95fb5988f66b..450c0371fc13a 100644 --- a/services/repository/adopt.go +++ b/services/repository/adopt.go @@ -149,7 +149,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r } branches, _ := git_model.FindBranchNames(ctx, git_model.FindBranchOptions{ - RepoID: repo.ID, + RepoIDs: []int64{repo.ID}, ListOptions: db.ListOptions{ ListAll: true, }, diff --git a/services/repository/branch.go b/services/repository/branch.go index 11a8b20531578..3dd42361291b9 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -73,7 +73,7 @@ func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git } branchOpts := git_model.FindBranchOptions{ - RepoID: repo.ID, + RepoIDs: []int64{repo.ID}, IsDeletedBranch: isDeletedBranch, ListOptions: db.ListOptions{ Page: page, From 5c3f7aa231228baed2fa44b882ef7e3f1c19433d Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 20 Jul 2023 08:53:31 +0000 Subject: [PATCH 12/97] add test 1 --- models/fixtures/branch.yml | 24 ++++++++++++++++ models/git/branch.go | 7 ++++- models/git/branch_list.go | 13 ++++----- models/git/branch_test.go | 26 +++++++++++++++++- .../2a/e4cd61145dbece4166c20a7f683e41d5ee5a8b | Bin 0 -> 55 bytes .../96/cac303b24be71685d77202689de5a751b972d3 | Bin 0 -> 54 bytes .../cb/24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d | Bin 0 -> 148 bytes .../refs/heads/new-branch-no-notification | 1 + .../refs/heads/new-branch-notification | 1 + 9 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 tests/gitea-repositories-meta/user2/repo1.git/objects/2a/e4cd61145dbece4166c20a7f683e41d5ee5a8b create mode 100644 tests/gitea-repositories-meta/user2/repo1.git/objects/96/cac303b24be71685d77202689de5a751b972d3 create mode 100644 tests/gitea-repositories-meta/user2/repo1.git/objects/cb/24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d create mode 100644 tests/gitea-repositories-meta/user2/repo1.git/refs/heads/new-branch-no-notification create mode 100644 tests/gitea-repositories-meta/user2/repo1.git/refs/heads/new-branch-notification diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index 93003049c67fb..8233698cc0030 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -45,3 +45,27 @@ is_deleted: false deleted_by_id: 0 deleted_unix: 0 + +- + id: 5 + repo_id: 1 + name: 'new-branch-notification' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1689838761 + pusher_id: 1 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 6 + repo_id: 1 + name: 'new-branch-no-notification' + commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' + commit_message: 'Initial commit' + commit_time: 1489927679 + pusher_id: 1 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 diff --git a/models/git/branch.go b/models/git/branch.go index c0f95e7a89e06..3b2f75954d90f 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -394,8 +394,9 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created // doer should not be nil +// if commitAfterUnix is 0, will find the branches commited in recently 6 hours // TODO use options to find the branches -func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Repository, doer *user_model.User) (BranchList, error) { +func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Repository, doer *user_model.User, commitAfterUnix int64) (BranchList, error) { baseBranch, err := GetBranch(ctx, baseRepo.ID, baseRepo.DefaultBranch) if err != nil { return nil, err @@ -417,12 +418,16 @@ func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Rep builder.Eq{"branch.id": baseBranch.ID}, )) + if commitAfterUnix == 0 { + commitAfterUnix = time.Now().Add(-time.Hour * 6).Unix() + } opts := FindBranchOptions{ IDCond: builder.NotIn("id", invalidBranchCond), RepoCond: builder.In("repo_id", repoCond), CommitCond: builder.Neq{"commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them, PusherID: doer.ID, IsDeletedBranch: util.OptionalBoolFalse, + CommitAfterUnix: commitAfterUnix, OrderBy: "branch.updated_unix DESC", } opts.PageSize = 2 diff --git a/models/git/branch_list.go b/models/git/branch_list.go index b089405a3a54c..291400379067f 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -10,7 +10,6 @@ import ( repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/container" - "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" "xorm.io/builder" @@ -95,8 +94,8 @@ type FindBranchOptions struct { CommitCond builder.Cond PusherID int64 IsDeletedBranch util.OptionalBool - UpdatedAfterUnix timeutil.TimeStamp - UpdatedBeforeUnix timeutil.TimeStamp + CommitAfterUnix int64 + CommitBeforeUnix int64 OrderBy string } @@ -131,11 +130,11 @@ func (opts *FindBranchOptions) Cond() builder.Cond { cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.IsTrue()}) } - if opts.UpdatedAfterUnix != 0 { - cond = cond.And(builder.Gte{"updated_unix": opts.UpdatedAfterUnix}) + if opts.CommitAfterUnix != 0 { + cond = cond.And(builder.Gte{"commit_time": opts.CommitAfterUnix}) } - if opts.UpdatedBeforeUnix != 0 { - cond = cond.And(builder.Lte{"updated_unix": opts.UpdatedBeforeUnix}) + if opts.CommitBeforeUnix != 0 { + cond = cond.And(builder.Lte{"commit_time": opts.CommitBeforeUnix}) } return cond } diff --git a/models/git/branch_test.go b/models/git/branch_test.go index ba6902692792e..75251864994bb 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -11,6 +11,7 @@ import ( issues_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/util" @@ -49,7 +50,7 @@ func TestGetDeletedBranches(t *testing.T) { ListOptions: db.ListOptions{ ListAll: true, }, - RepoID: repo.ID, + RepoIDs: []int64{repo.ID}, IsDeletedBranch: util.OptionalBoolTrue, }) assert.NoError(t, err) @@ -183,3 +184,26 @@ func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, deletedBranch) } + +func TestFindRecentlyPushedNewBranches(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) + user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) + + // test new branch of the repo + branches, err := git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user1, 1689838760) + assert.NoError(t, err) + assert.Equal(t, 1, len(branches)) + assert.Equal(t, "new-branch-notification", branches[0].Name) + + // TODO: test new branch from user fork repo + + // TODO: test new branch from org fork repo + + // TODO: test new branch from private user repo + + // TODO: test new branch from private org with code permisstion repo + + // TODO: test new branch from private org with no code permisstion repo +} diff --git a/tests/gitea-repositories-meta/user2/repo1.git/objects/2a/e4cd61145dbece4166c20a7f683e41d5ee5a8b b/tests/gitea-repositories-meta/user2/repo1.git/objects/2a/e4cd61145dbece4166c20a7f683e41d5ee5a8b new file mode 100644 index 0000000000000000000000000000000000000000..f3271266444f56b0b43aa0ff66b009188f4c0421 GIT binary patch literal 55 zcmV-70LcG%0ZYosPf{?kU{F>lN-fAYZaql`QKEzwcVg K%wW2O|04hjX%!Rz literal 0 HcmV?d00001 diff --git a/tests/gitea-repositories-meta/user2/repo1.git/objects/cb/24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d b/tests/gitea-repositories-meta/user2/repo1.git/objects/cb/24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d new file mode 100644 index 0000000000000000000000000000000000000000..5f318261228bae266b08c7819b1fe880ca9603b5 GIT binary patch literal 148 zcmV;F0Biqv0hNwB4gxU@1*vn2^hn70*iNJs7omz1M^G&LQ7E`QxdQFejONvCU0=g` zh?jAy+Dx_706}~dWk(4cvj Date: Thu, 20 Jul 2023 08:56:50 +0000 Subject: [PATCH 13/97] fix --- routers/web/repo/view.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index e844dcf82b76e..bdd7a3e059459 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -987,7 +987,7 @@ func renderCode(ctx *context.Context) { if ctx.Repo.Repository.IsFork { baseRepo = ctx.Repo.Repository.BaseRepo } - branches, err := git_model.FindRecentlyPushedNewBranches(ctx, baseRepo, ctx.Doer) + branches, err := git_model.FindRecentlyPushedNewBranches(ctx, baseRepo, ctx.Doer, 0) if err != nil { ctx.ServerError("FindRecentlyPushedNewBranches", err) return From 69b76246b0fdbd5493f024f26228c6975e71aa99 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 21 Jul 2023 00:08:45 +0000 Subject: [PATCH 14/97] fix bug --- models/git/branch_list.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/models/git/branch_list.go b/models/git/branch_list.go index 291400379067f..0299737488324 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -106,16 +106,16 @@ func (opts *FindBranchOptions) Cond() builder.Cond { } if len(opts.RepoIDs) == 1 { - opts.RepoCond = builder.Eq{"issue.repo_id": opts.RepoIDs[0]} + opts.RepoCond = builder.Eq{"branch.repo_id": opts.RepoIDs[0]} } else if len(opts.RepoIDs) > 1 { - opts.RepoCond = builder.In("issue.repo_id", opts.RepoIDs) + opts.RepoCond = builder.In("branch.repo_id", opts.RepoIDs) } if opts.RepoCond != nil { cond = cond.And(opts.RepoCond) } if len(opts.ExcludeBranchNames) > 0 { - cond = cond.And(builder.NotIn("name", opts.ExcludeBranchNames)) + cond = cond.And(builder.NotIn("branch.name", opts.ExcludeBranchNames)) } if opts.CommitCond != nil { @@ -123,18 +123,18 @@ func (opts *FindBranchOptions) Cond() builder.Cond { } if opts.PusherID > 0 { - cond = cond.And(builder.Eq{"pusher_id": opts.PusherID}) + cond = cond.And(builder.Eq{"branch.pusher_id": opts.PusherID}) } if !opts.IsDeletedBranch.IsNone() { - cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.IsTrue()}) + cond = cond.And(builder.Eq{"branch.is_deleted": opts.IsDeletedBranch.IsTrue()}) } if opts.CommitAfterUnix != 0 { - cond = cond.And(builder.Gte{"commit_time": opts.CommitAfterUnix}) + cond = cond.And(builder.Gte{"branch.commit_time": opts.CommitAfterUnix}) } if opts.CommitBeforeUnix != 0 { - cond = cond.And(builder.Lte{"commit_time": opts.CommitBeforeUnix}) + cond = cond.And(builder.Lte{"branch.commit_time": opts.CommitBeforeUnix}) } return cond } From 0bfec1a3e8cb0dd9b0f4596922fa0cc15ba2359f Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 21 Jul 2023 01:19:13 +0000 Subject: [PATCH 15/97] add test --- models/fixtures/branch.yml | 138 ++++++++++++++++++++++++++++++++- models/fixtures/repository.yml | 92 +++++++++++++++++++++- models/fixtures/team.yml | 22 ++++++ models/fixtures/team_repo.yml | 14 +++- models/fixtures/team_unit.yml | 12 +++ models/fixtures/team_user.yml | 12 +++ models/fixtures/user.yml | 10 +-- models/git/branch_test.go | 36 ++++++--- 8 files changed, 314 insertions(+), 22 deletions(-) diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index 8233698cc0030..e12926ef321a3 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -49,11 +49,11 @@ - id: 5 repo_id: 1 - name: 'new-branch-notification' + name: 'new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1689838761 - pusher_id: 1 + pusher_id: 2 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -61,7 +61,55 @@ - id: 6 repo_id: 1 - name: 'new-branch-no-notification' + name: 'no-commit' + commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' + commit_message: 'Initial commit' + commit_time: 1489927679 + pusher_id: 2 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 7 + repo_id: 58 + name: 'master' + commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' + commit_message: 'Initial commit' + commit_time: 1489927679 + pusher_id: 1 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 8 + repo_id: 58 + name: 'user-fork-new-commit' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1689838761 + pusher_id: 1 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 9 + repo_id: 58 + name: 'user-fork-no-commit' + commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' + commit_message: 'Initial commit' + commit_time: 1489927679 + pusher_id: 1 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 10 + repo_id: 59 + name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 @@ -69,3 +117,87 @@ is_deleted: false deleted_by_id: 0 deleted_unix: 0 + +- + id: 11 + repo_id: 59 + name: 'org-fork-new-commit' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1689838761 + pusher_id: 2 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 12 + repo_id: 59 + name: 'org-fork-no-commit' + commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' + commit_message: 'Initial commit' + commit_time: 1489927679 + pusher_id: 2 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 13 + repo_id: 60 + name: 'master' + commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' + commit_message: 'Initial commit' + commit_time: 1489927679 + pusher_id: 1 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 14 + repo_id: 60 + name: 'private-org-fork-new-commit' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1689838761 + pusher_id: 4 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 15 + repo_id: 60 + name: 'private-org-fork-no-commit' + commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' + commit_message: 'Initial commit' + commit_time: 1489927679 + pusher_id: 4 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 16 + repo_id: 60 + name: 'private-org-fork-no-permission-new-commit' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1689838761 + pusher_id: 5 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 17 + repo_id: 60 + name: 'private-org-fork-no-permission-no-commit' + commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' + commit_message: 'Initial commit' + commit_time: 1489927679 + pusher_id: 5 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 \ No newline at end of file diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 050a9e2d06f4a..a49239a92701e 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -8,7 +8,7 @@ default_branch: master num_watches: 4 num_stars: 0 - num_forks: 0 + num_forks: 3 num_issues: 2 num_closed_issues: 1 num_pulls: 3 @@ -1662,3 +1662,93 @@ is_private: false status: 0 num_issues: 0 + +- + id: 58 + owner_id: 1 + owner_name: user1 + lower_name: user_fork_repo1 + name: user_fork_repo1 + num_watches: 0 + num_stars: 0 + num_forks: 0 + num_issues: 0 + num_closed_issues: 0 + num_pulls: 0 + num_closed_pulls: 0 + num_milestones: 0 + num_closed_milestones: 0 + num_projects: 0 + num_closed_projects: 0 + is_private: false + is_empty: false + is_archived: false + is_mirror: false + status: 0 + is_fork: true + fork_id: 1 + is_template: false + template_id: 0 + size: 0 + is_fsck_enabled: true + close_issues_via_commit_in_any_branch: false + +- + id: 59 + owner_id: 3 + owner_name: user3 + lower_name: org_fork_repo1 + name: org_fork_repo1 + num_watches: 0 + num_stars: 0 + num_forks: 0 + num_issues: 0 + num_closed_issues: 0 + num_pulls: 0 + num_closed_pulls: 0 + num_milestones: 0 + num_closed_milestones: 0 + num_projects: 0 + num_closed_projects: 0 + is_private: false + is_empty: false + is_archived: false + is_mirror: false + status: 0 + is_fork: true + fork_id: 1 + is_template: false + template_id: 0 + size: 0 + is_fsck_enabled: true + close_issues_via_commit_in_any_branch: false + +- + id: 60 + owner_id: 23 + owner_name: privated_org + lower_name: private_org_fork_repo1 + name: private_org_fork_repo1 + num_watches: 0 + num_stars: 0 + num_forks: 0 + num_issues: 0 + num_closed_issues: 0 + num_pulls: 0 + num_closed_pulls: 0 + num_milestones: 0 + num_closed_milestones: 0 + num_projects: 0 + num_closed_projects: 0 + is_private: true + is_empty: false + is_archived: false + is_mirror: false + status: 0 + is_fork: true + fork_id: 1 + is_template: false + template_id: 0 + size: 0 + is_fsck_enabled: true + close_issues_via_commit_in_any_branch: false \ No newline at end of file diff --git a/models/fixtures/team.yml b/models/fixtures/team.yml index 65326eedbf476..dfd6463c1acb8 100644 --- a/models/fixtures/team.yml +++ b/models/fixtures/team.yml @@ -217,3 +217,25 @@ num_members: 1 includes_all_repositories: false can_create_org_repo: true + +- + id: 21 + org_id: 23 + lower_name: team21readcode + name: team14WriteAuth + authorize: 1 # read + num_repos: 1 + num_members: 1 + includes_all_repositories: false + can_create_org_repo: true + +- + id: 22 + org_id: 23 + lower_name: team22noreadcode + name: team14WriteAuth + authorize: 0 # no access + num_repos: 1 + num_members: 1 + includes_all_repositories: false + can_create_org_repo: true \ No newline at end of file diff --git a/models/fixtures/team_repo.yml b/models/fixtures/team_repo.yml index a523a90b204d2..79af886a403ac 100644 --- a/models/fixtures/team_repo.yml +++ b/models/fixtures/team_repo.yml @@ -62,4 +62,16 @@ id: 11 org_id: 17 team_id: 9 - repo_id: 24 \ No newline at end of file + repo_id: 24 + +- + id: 12 + org_id: 23 + team_id: 21 + repo_id: 60 + +- + id: 13 + org_id: 23 + team_id: 22 + repo_id: 60 \ No newline at end of file diff --git a/models/fixtures/team_unit.yml b/models/fixtures/team_unit.yml index 5d2ba2fb6cbd7..afdda025ca4e1 100644 --- a/models/fixtures/team_unit.yml +++ b/models/fixtures/team_unit.yml @@ -280,3 +280,15 @@ team_id: 20 type: 9 # package access_mode: 2 + +- + id: 48 + team_id: 21 + type: 1 # code + access_mode: 1 + +- + id: 49 + team_id: 22 + type: 1 # code + access_mode: 0 \ No newline at end of file diff --git a/models/fixtures/team_user.yml b/models/fixtures/team_user.yml index feace5f2a531d..43249361949be 100644 --- a/models/fixtures/team_user.yml +++ b/models/fixtures/team_user.yml @@ -123,3 +123,15 @@ org_id: 36 team_id: 20 uid: 5 + +- + id: 22 + org_id: 23 + team_id: 21 + uid: 4 + +- + id: 23 + org_id: 23 + team_id: 22 + uid: 5 \ No newline at end of file diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 26bb7a9f4ba89..c340d3cb49ec4 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -29,7 +29,7 @@ num_followers: 0 num_following: 0 num_stars: 0 - num_repos: 0 + num_repos: 1 num_teams: 0 num_members: 0 visibility: 0 @@ -103,7 +103,7 @@ num_followers: 0 num_following: 0 num_stars: 0 - num_repos: 3 + num_repos: 4 num_teams: 5 num_members: 3 visibility: 0 @@ -843,9 +843,9 @@ num_followers: 0 num_following: 0 num_stars: 0 - num_repos: 2 - num_teams: 2 - num_members: 1 + num_repos: 3 + num_teams: 4 + num_members: 2 visibility: 2 repo_admin_change_team_access: false theme: "" diff --git a/models/git/branch_test.go b/models/git/branch_test.go index 75251864994bb..edeea0071eded 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -189,21 +189,33 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) - user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) - // test new branch of the repo - branches, err := git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user1, 1689838760) + // test new branch of the repo and org fork repo + // user2 is the owner of the repo and the organization + user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + branches, err := git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user2, 1689838760) assert.NoError(t, err) - assert.Equal(t, 1, len(branches)) - assert.Equal(t, "new-branch-notification", branches[0].Name) - - // TODO: test new branch from user fork repo + assert.Equal(t, 2, len(branches)) + assert.Equal(t, "new-commit", branches[0].Name) + assert.Equal(t, "org-fork-new-commit", branches[1].Name) - // TODO: test new branch from org fork repo - - // TODO: test new branch from private user repo + // test new branch from user public and private fork repo + user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) + branches, err = git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user1, 1689838760) + assert.NoError(t, err) + assert.Equal(t, 1, len(branches)) + assert.Equal(t, "user-fork-new-commit", branches[0].Name) - // TODO: test new branch from private org with code permisstion repo + // test new branch from private org with code permisstion repo + user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}) + branches, err = git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user4, 1689838760) + assert.NoError(t, err) + assert.Equal(t, 1, len(branches)) + assert.Equal(t, "private-org-fork-new-commit", branches[0].Name) - // TODO: test new branch from private org with no code permisstion repo + // test new branch from private org with no code permisstion repo + user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) + branches, err = git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user5, 1689838760) + assert.NoError(t, err) + assert.Equal(t, 0, len(branches)) } From f7295177bd2b37304ccf3ff2faae99a320da977d Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 21 Jul 2023 02:48:42 +0000 Subject: [PATCH 16/97] use searchrepo --- models/git/branch.go | 29 ++++++++++++++++++++--------- models/git/branch_test.go | 2 ++ models/repo/repo_list.go | 7 ++++++- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index 3b2f75954d90f..5ab97b2e3ddbb 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -401,20 +402,30 @@ func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Rep if err != nil { return nil, err } + // search all related repos - repoCond := builder.Select("id").From("repository"). - Where(builder.Or( - builder.Eq{"id": baseRepo.ID}, - builder.Eq{"is_fork": true, "fork_id": baseRepo.ID}, - )) + repoOpts := repo_model.SearchRepoOptions{ + Actor: doer, + Private: true, + AllPublic: false, // Include also all public repositories of users and public organisations + AllLimited: false, // Include also all public repositories of limited organisations + Fork: util.OptionalBoolTrue, + ForkID: baseRepo.ID, + Archived: util.OptionalBoolFalse, + } + repoCond := repo_model.SearchRepositoryCondition(&repoOpts). + And(repo_model.AccessibleRepositoryCondition(doer, unit.TypeCode)). + Or(builder.Eq{"id": baseRepo.ID}) + repoIds := builder.Select("id").From("repository").Where(repoCond) + // avoid check branches which have already created PRs // TODO add head_branch_id in pull_request table then we can get the branch id from pull_request table directly - invalidBranchCond := builder.Select("branch.id").From("branch"). + prBranchIds := builder.Select("branch.id").From("branch"). InnerJoin("pull_request", "branch.name = pull_request.head_branch AND branch.repo_id = pull_request.head_repo_id"). InnerJoin("issue", "issue.id = pull_request.issue_id"). Where(builder.Or( builder.Eq{"pull_request.has_merged": true}, - builder.In("pull_request.head_repo_id", repoCond), + builder.In("pull_request.head_repo_id", repoIds), builder.Eq{"branch.id": baseBranch.ID}, )) @@ -422,8 +433,8 @@ func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Rep commitAfterUnix = time.Now().Add(-time.Hour * 6).Unix() } opts := FindBranchOptions{ - IDCond: builder.NotIn("id", invalidBranchCond), - RepoCond: builder.In("repo_id", repoCond), + IDCond: builder.NotIn("id", prBranchIds), + RepoCond: builder.In("repo_id", repoIds), CommitCond: builder.Neq{"commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them, PusherID: doer.ID, IsDeletedBranch: util.OptionalBoolFalse, diff --git a/models/git/branch_test.go b/models/git/branch_test.go index edeea0071eded..c25e0b1f0bf8f 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -218,4 +218,6 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { branches, err = git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user5, 1689838760) assert.NoError(t, err) assert.Equal(t, 0, len(branches)) + + // TODO:test pr branch } diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go index 83ba02e31653a..170a7482841fd 100644 --- a/models/repo/repo_list.go +++ b/models/repo/repo_list.go @@ -133,7 +133,8 @@ type SearchRepoOptions struct { // None -> include forks AND non-forks // True -> include just forks // False -> include just non-forks - Fork util.OptionalBool + Fork util.OptionalBool + ForkID int64 // If Fork option is True, you can use this option to limit the forks of a special repo by repo id. // None -> include templates AND non-templates // True -> include just templates // False -> include just non-templates @@ -467,6 +468,10 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { cond = cond.And(builder.Eq{"is_fork": false}) } else { cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue}) + + if opts.ForkID > 0 && opts.Fork == util.OptionalBoolTrue { + cond = cond.And(builder.Eq{"fork_id": opts.ForkID}) + } } } From 1ecb6fbc3e7b4c0dc74b4c5b67c73814434b4432 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 21 Jul 2023 05:34:56 +0000 Subject: [PATCH 17/97] fix org_user --- models/fixtures/org_user.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/models/fixtures/org_user.yml b/models/fixtures/org_user.yml index 8d58169a32f17..21f4e5a5539dd 100644 --- a/models/fixtures/org_user.yml +++ b/models/fixtures/org_user.yml @@ -99,3 +99,9 @@ uid: 5 org_id: 36 is_public: true + +- + id: 18 + uid: 4 + org_id: 23 + is_public: false From f06e09151d1d7edec108698c78f3438e50475492 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 21 Jul 2023 06:45:23 +0000 Subject: [PATCH 18/97] fix test --- models/fixtures/branch.yml | 6 +-- models/fixtures/org_user.yml | 14 +++++- models/fixtures/repository.yml | 14 +++--- models/fixtures/team.yml | 38 +++++++++++---- models/fixtures/team_repo.yml | 10 ++-- models/fixtures/team_unit.yml | 12 +++-- models/fixtures/team_user.yml | 16 +++++-- models/fixtures/user.yml | 86 +++++++++++++++++++++++++++++++--- models/git/branch.go | 2 +- models/git/branch_test.go | 6 +-- 10 files changed, 162 insertions(+), 42 deletions(-) diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index e12926ef321a3..fe48431829b32 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -89,7 +89,7 @@ commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1689838761 - pusher_id: 1 + pusher_id: 8 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -101,7 +101,7 @@ commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 1 + pusher_id: 8 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -200,4 +200,4 @@ pusher_id: 5 is_deleted: false deleted_by_id: 0 - deleted_unix: 0 \ No newline at end of file + deleted_unix: 0 diff --git a/models/fixtures/org_user.yml b/models/fixtures/org_user.yml index 21f4e5a5539dd..5e541c93e2f1e 100644 --- a/models/fixtures/org_user.yml +++ b/models/fixtures/org_user.yml @@ -102,6 +102,18 @@ - id: 18 + uid: 2 + org_id: 37 + is_public: false + +- + id: 19 uid: 4 - org_id: 23 + org_id: 38 + is_public: false + +- + id: 20 + uid: 5 + org_id: 38 is_public: false diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index a49239a92701e..a14adb763b3f5 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -1665,8 +1665,8 @@ - id: 58 - owner_id: 1 - owner_name: user1 + owner_id: 8 + owner_name: user8 lower_name: user_fork_repo1 name: user_fork_repo1 num_watches: 0 @@ -1695,8 +1695,8 @@ - id: 59 - owner_id: 3 - owner_name: user3 + owner_id: 37 + owner_name: org37 lower_name: org_fork_repo1 name: org_fork_repo1 num_watches: 0 @@ -1725,8 +1725,8 @@ - id: 60 - owner_id: 23 - owner_name: privated_org + owner_id: 38 + owner_name: private_org38 lower_name: private_org_fork_repo1 name: private_org_fork_repo1 num_watches: 0 @@ -1751,4 +1751,4 @@ template_id: 0 size: 0 is_fsck_enabled: true - close_issues_via_commit_in_any_branch: false \ No newline at end of file + close_issues_via_commit_in_any_branch: false diff --git a/models/fixtures/team.yml b/models/fixtures/team.yml index dfd6463c1acb8..2d5b430cda4a9 100644 --- a/models/fixtures/team.yml +++ b/models/fixtures/team.yml @@ -220,9 +220,31 @@ - id: 21 - org_id: 23 - lower_name: team21readcode - name: team14WriteAuth + org_id: 37 + lower_name: owners + name: Owners + authorize: 4 # owner + num_repos: 0 + num_members: 1 + includes_all_repositories: false + can_create_org_repo: true + +- + id: 22 + org_id: 38 + lower_name: owners + name: Owners + authorize: 4 # owner + num_repos: 0 + num_members: 0 + includes_all_repositories: false + can_create_org_repo: true + +- + id: 23 + org_id: 38 + lower_name: team23readcode + name: team23readcode authorize: 1 # read num_repos: 1 num_members: 1 @@ -230,12 +252,12 @@ can_create_org_repo: true - - id: 22 - org_id: 23 - lower_name: team22noreadcode - name: team14WriteAuth + id: 24 + org_id: 38 + lower_name: team24noreadcode + name: team24noreadcode authorize: 0 # no access num_repos: 1 num_members: 1 includes_all_repositories: false - can_create_org_repo: true \ No newline at end of file + can_create_org_repo: true diff --git a/models/fixtures/team_repo.yml b/models/fixtures/team_repo.yml index 79af886a403ac..40064f3b1de63 100644 --- a/models/fixtures/team_repo.yml +++ b/models/fixtures/team_repo.yml @@ -66,12 +66,12 @@ - id: 12 - org_id: 23 - team_id: 21 + org_id: 38 + team_id: 23 repo_id: 60 - id: 13 - org_id: 23 - team_id: 22 - repo_id: 60 \ No newline at end of file + org_id: 38 + team_id: 24 + repo_id: 60 diff --git a/models/fixtures/team_unit.yml b/models/fixtures/team_unit.yml index afdda025ca4e1..6521ca2d70725 100644 --- a/models/fixtures/team_unit.yml +++ b/models/fixtures/team_unit.yml @@ -285,10 +285,16 @@ id: 48 team_id: 21 type: 1 # code - access_mode: 1 + access_mode: 4 - id: 49 - team_id: 22 + team_id: 23 + type: 1 # code + access_mode: 1 + +- + id: 50 + team_id: 24 type: 1 # code - access_mode: 0 \ No newline at end of file + access_mode: 0 diff --git a/models/fixtures/team_user.yml b/models/fixtures/team_user.yml index 43249361949be..5f8b4ecf409ce 100644 --- a/models/fixtures/team_user.yml +++ b/models/fixtures/team_user.yml @@ -126,12 +126,18 @@ - id: 22 - org_id: 23 + org_id: 37 team_id: 21 - uid: 4 + uid: 2 - id: 23 - org_id: 23 - team_id: 22 - uid: 5 \ No newline at end of file + org_id: 38 + team_id: 23 + uid: 4 + +- + id: 24 + org_id: 38 + team_id: 24 + uid: 5 diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index c340d3cb49ec4..44e7547c5e31c 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -29,7 +29,7 @@ num_followers: 0 num_following: 0 num_stars: 0 - num_repos: 1 + num_repos: 0 num_teams: 0 num_members: 0 visibility: 0 @@ -103,7 +103,7 @@ num_followers: 0 num_following: 0 num_stars: 0 - num_repos: 4 + num_repos: 3 num_teams: 5 num_members: 3 visibility: 0 @@ -288,7 +288,7 @@ num_followers: 1 num_following: 1 num_stars: 0 - num_repos: 0 + num_repos: 1 num_teams: 0 num_members: 0 visibility: 0 @@ -843,9 +843,9 @@ num_followers: 0 num_following: 0 num_stars: 0 - num_repos: 3 - num_teams: 4 - num_members: 2 + num_repos: 2 + num_teams: 2 + num_members: 1 visibility: 2 repo_admin_change_team_access: false theme: "" @@ -1332,3 +1332,77 @@ repo_admin_change_team_access: false theme: "" keep_activity_private: false + +- + id: 37 + lower_name: org37 + name: org37 + full_name: Org 37 + email: org37@example.com + keep_email_private: false + email_notifications_preference: enabled + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy + must_change_password: false + login_source: 0 + login_name: org37 + type: 1 + salt: ZogKvWdyEx + max_repo_creation: -1 + is_active: true + is_admin: false + is_restricted: false + allow_git_hook: false + allow_import_local: false + allow_create_organization: true + prohibit_login: false + avatar: avatar37 + avatar_email: org37@example.com + use_custom_avatar: false + num_followers: 0 + num_following: 0 + num_stars: 0 + num_repos: 1 + num_teams: 1 + num_members: 1 + visibility: 0 + repo_admin_change_team_access: false + theme: "" + keep_activity_private: false + +- + id: 38 + lower_name: private_org38 + name: private_org38 + full_name: Private Org 38 + email: private_org38@example.com + keep_email_private: false + email_notifications_preference: enabled + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy + must_change_password: false + login_source: 0 + login_name: private_org38 + type: 1 + salt: ZogKvWdyEx + max_repo_creation: -1 + is_active: true + is_admin: false + is_restricted: false + allow_git_hook: false + allow_import_local: false + allow_create_organization: true + prohibit_login: false + avatar: avatar38 + avatar_email: private_org38@example.com + use_custom_avatar: false + num_followers: 0 + num_following: 0 + num_stars: 0 + num_repos: 1 + num_teams: 3 + num_members: 2 + visibility: 2 + repo_admin_change_team_access: false + theme: "" + keep_activity_private: false diff --git a/models/git/branch.go b/models/git/branch.go index 5ab97b2e3ddbb..f97f87df9254d 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -395,7 +395,7 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created // doer should not be nil -// if commitAfterUnix is 0, will find the branches commited in recently 6 hours +// if commitAfterUnix is 0, will find the branches committed in recently 6 hours // TODO use options to find the branches func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Repository, doer *user_model.User, commitAfterUnix int64) (BranchList, error) { baseBranch, err := GetBranch(ctx, baseRepo.ID, baseRepo.DefaultBranch) diff --git a/models/git/branch_test.go b/models/git/branch_test.go index c25e0b1f0bf8f..a370fa09ebde0 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -199,9 +199,9 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { assert.Equal(t, "new-commit", branches[0].Name) assert.Equal(t, "org-fork-new-commit", branches[1].Name) - // test new branch from user public and private fork repo - user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) - branches, err = git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user1, 1689838760) + // test new branch from user fork repo + user8 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 8}) + branches, err = git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user8, 1689838760) assert.NoError(t, err) assert.Equal(t, 1, len(branches)) assert.Equal(t, "user-fork-new-commit", branches[0].Name) From d848876744196fc28e9ef292e713ad0c9289f3ae Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 21 Jul 2023 07:56:14 +0000 Subject: [PATCH 19/97] fix repo size --- models/fixtures/repository.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index a14adb763b3f5..62fe70cb0ef8c 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -26,7 +26,7 @@ fork_id: 0 is_template: false template_id: 0 - size: 7320 + size: 7659 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false From 5449bc139a6d2b247bb280e7e899952e1ad25646 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 21 Jul 2023 08:01:15 +0000 Subject: [PATCH 20/97] fix TestSearchUsers --- models/user/user_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/user/user_test.go b/models/user/user_test.go index 44eaf63556baa..897aa432949b7 100644 --- a/models/user/user_test.go +++ b/models/user/user_test.go @@ -89,7 +89,7 @@ func TestSearchUsers(t *testing.T) { []int64{19, 25}) testOrgSuccess(&user_model.SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 4, PageSize: 2}}, - []int64{26}) + []int64{26, 37}) testOrgSuccess(&user_model.SearchUserOptions{ListOptions: db.ListOptions{Page: 5, PageSize: 2}}, []int64{}) From 63562c31b81f91d9214ba80c08cb14b352d7de0d Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 21 Jul 2023 08:04:38 +0000 Subject: [PATCH 21/97] fix TestSearchRepository --- models/repo/repo_list_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/repo/repo_list_test.go b/models/repo/repo_list_test.go index 573281ea0b018..a411b1c8f18b8 100644 --- a/models/repo/repo_list_test.go +++ b/models/repo/repo_list_test.go @@ -235,12 +235,12 @@ func TestSearchRepository(t *testing.T) { { name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse}, - count: 30, + count: 32, }, { name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse}, - count: 35, + count: 37, }, { name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName", @@ -255,7 +255,7 @@ func TestSearchRepository(t *testing.T) { { name: "AllPublic/PublicRepositoriesOfOrganization", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse}, - count: 30, + count: 32, }, { name: "AllTemplates", From 4d42a638052d0cce3b1b76c4546aa282d0e4f91b Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 21 Jul 2023 08:20:20 +0000 Subject: [PATCH 22/97] fix TestFindOrgs --- models/fixtures/branch.yml | 4 ++-- models/fixtures/org_user.yml | 2 +- models/fixtures/team_user.yml | 2 +- models/git/branch_test.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index fe48431829b32..ad8d9260bfdf1 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -161,7 +161,7 @@ commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1689838761 - pusher_id: 4 + pusher_id: 18 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -173,7 +173,7 @@ commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 4 + pusher_id: 18 is_deleted: false deleted_by_id: 0 deleted_unix: 0 diff --git a/models/fixtures/org_user.yml b/models/fixtures/org_user.yml index 5e541c93e2f1e..ae3353b7446e4 100644 --- a/models/fixtures/org_user.yml +++ b/models/fixtures/org_user.yml @@ -108,7 +108,7 @@ - id: 19 - uid: 4 + uid: 18 org_id: 38 is_public: false diff --git a/models/fixtures/team_user.yml b/models/fixtures/team_user.yml index 5f8b4ecf409ce..035393dd641ae 100644 --- a/models/fixtures/team_user.yml +++ b/models/fixtures/team_user.yml @@ -134,7 +134,7 @@ id: 23 org_id: 38 team_id: 23 - uid: 4 + uid: 18 - id: 24 diff --git a/models/git/branch_test.go b/models/git/branch_test.go index a370fa09ebde0..c4ab4d77da981 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -207,8 +207,8 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { assert.Equal(t, "user-fork-new-commit", branches[0].Name) // test new branch from private org with code permisstion repo - user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}) - branches, err = git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user4, 1689838760) + user18 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 18}) + branches, err = git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user18, 1689838760) assert.NoError(t, err) assert.Equal(t, 1, len(branches)) assert.Equal(t, "private-org-fork-new-commit", branches[0].Name) From e263227a88e6e74ad83bc614ea152000e3058cf8 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 21 Jul 2023 08:29:22 +0000 Subject: [PATCH 23/97] fix TestFixtureGeneration --- models/fixtures/access.yml | 48 ++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index 446502843ef48..61c344d36c73b 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -24,114 +24,126 @@ - id: 5 + user_id: 2 + repo_id: 59 + mode: 4 + +- + id: 6 user_id: 4 repo_id: 3 mode: 2 - - id: 6 + id: 7 user_id: 4 repo_id: 4 mode: 2 - - id: 7 + id: 8 user_id: 4 repo_id: 40 mode: 2 - - id: 8 + id: 9 user_id: 15 repo_id: 21 mode: 2 - - id: 9 + id: 10 user_id: 15 repo_id: 22 mode: 2 - - id: 10 + id: 11 user_id: 15 repo_id: 23 mode: 4 - - id: 11 + id: 12 user_id: 15 repo_id: 24 mode: 4 - - id: 12 + id: 13 user_id: 15 repo_id: 32 mode: 2 - - id: 13 + id: 14 user_id: 18 repo_id: 21 mode: 2 - - id: 14 + id: 15 user_id: 18 repo_id: 22 mode: 2 - - id: 15 + id: 16 user_id: 18 repo_id: 23 mode: 4 - - id: 16 + id: 17 user_id: 18 repo_id: 24 mode: 4 - - id: 17 + id: 18 + user_id: 18 + repo_id: 60 + mode: 1 + +- + id: 19 user_id: 20 repo_id: 24 mode: 1 - - id: 18 + id: 20 user_id: 20 repo_id: 27 mode: 4 - - id: 19 + id: 21 user_id: 20 repo_id: 28 mode: 4 - - id: 20 + id: 22 user_id: 29 repo_id: 4 mode: 2 - - id: 21 + id: 23 user_id: 29 repo_id: 24 mode: 1 - - id: 22 + id: 24 user_id: 31 repo_id: 27 mode: 4 - - id: 23 + id: 25 user_id: 31 repo_id: 28 mode: 4 From 6517ad975f129c9e62778c346411680af9b3013e Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 24 Jul 2023 00:20:01 +0000 Subject: [PATCH 24/97] fix --- routers/web/repo/repo.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 0de804dbce6fa..c8f4bbb4d6bf5 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -630,7 +630,7 @@ type branchTagSearchResponse struct { // GetBranchesList get branches for current repo' func GetBranchesList(ctx *context.Context) { branchOpts := git_model.FindBranchOptions{ - RepoID: ctx.Repo.Repository.ID, + RepoIDs: []int64{ctx.Repo.Repository.ID}, IsDeletedBranch: util.OptionalBoolFalse, ListOptions: db.ListOptions{ ListAll: true, @@ -665,7 +665,7 @@ func GetTagList(ctx *context.Context) { func PrepareBranchList(ctx *context.Context) { branchOpts := git_model.FindBranchOptions{ - RepoID: ctx.Repo.Repository.ID, + RepoIDs: []int64{ctx.Repo.Repository.ID}, IsDeletedBranch: util.OptionalBoolFalse, ListOptions: db.ListOptions{ ListAll: true, From 9a33437cd69323a20eee01ee973d7ac329502a4f Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 24 Jul 2023 02:34:06 +0000 Subject: [PATCH 25/97] improve --- models/git/branch.go | 85 ++++++++++++++++++++++++--------------- models/git/branch_list.go | 12 ++++-- models/git/branch_test.go | 76 ++++++++++++++++++++++------------ models/repo/repo_list.go | 9 +++-- routers/web/repo/view.go | 10 +++-- 5 files changed, 123 insertions(+), 69 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index f97f87df9254d..ad4966339ca9f 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -393,55 +393,74 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str return committer.Commit() } -// FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created -// doer should not be nil -// if commitAfterUnix is 0, will find the branches committed in recently 6 hours -// TODO use options to find the branches -func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Repository, doer *user_model.User, commitAfterUnix int64) (BranchList, error) { - baseBranch, err := GetBranch(ctx, baseRepo.ID, baseRepo.DefaultBranch) - if err != nil { - return nil, err - } +type FindRecentlyPushedNewBranchesOptions struct { + Actor *user_model.User + Repo *repo_model.Repository + BaseRepo *repo_model.Repository + CommitAfterUnix int64 +} - // search all related repos +// FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created +// opts.Actor should not be nil +// if opts.CommitAfterUnix is 0, we will find the branches committed in recently 6 hours +func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushedNewBranchesOptions) (BranchList, error) { + // find all related repo ids repoOpts := repo_model.SearchRepoOptions{ - Actor: doer, + Actor: opts.Actor, Private: true, AllPublic: false, // Include also all public repositories of users and public organisations AllLimited: false, // Include also all public repositories of limited organisations Fork: util.OptionalBoolTrue, - ForkID: baseRepo.ID, + ForkFrom: opts.BaseRepo.ID, Archived: util.OptionalBoolFalse, } - repoCond := repo_model.SearchRepositoryCondition(&repoOpts). - And(repo_model.AccessibleRepositoryCondition(doer, unit.TypeCode)). - Or(builder.Eq{"id": baseRepo.ID}) - repoIds := builder.Select("id").From("repository").Where(repoCond) + repoCond := repo_model.SearchRepositoryCondition(&repoOpts).And(repo_model.AccessibleRepositoryCondition(opts.Actor, unit.TypeCode)) + if opts.Repo == opts.BaseRepo { + // should also include the brase repo's branches + repoCond = repoCond.Or(builder.Eq{"id": opts.BaseRepo.ID}) + } else { + // in fork repo, we only detect the fork repo's branch + repoCond = repoCond.And(builder.Eq{"id": opts.Repo.ID}) + } + repoIDs := builder.Select("id").From("repository").Where(repoCond) - // avoid check branches which have already created PRs - // TODO add head_branch_id in pull_request table then we can get the branch id from pull_request table directly + // find branches which have already created PRs prBranchIds := builder.Select("branch.id").From("branch"). InnerJoin("pull_request", "branch.name = pull_request.head_branch AND branch.repo_id = pull_request.head_repo_id"). InnerJoin("issue", "issue.id = pull_request.issue_id"). - Where(builder.Or( - builder.Eq{"pull_request.has_merged": true}, - builder.In("pull_request.head_repo_id", repoIds), - builder.Eq{"branch.id": baseBranch.ID}, + Where(builder.And( + builder.Eq{"pull_request.base_repo_id": opts.BaseRepo.ID}, + builder.Eq{"pull_request.base_branch": opts.BaseRepo.DefaultBranch}, + builder.In("pull_request.head_repo_id", repoIDs), + builder.Or( + builder.Eq{"issue.is_closed": true}, + builder.Eq{"pull_request.has_merged": true}, + ), )) - if commitAfterUnix == 0 { - commitAfterUnix = time.Now().Add(-time.Hour * 6).Unix() + if opts.CommitAfterUnix == 0 { + opts.CommitAfterUnix = time.Now().Add(-time.Hour * 6).Unix() } - opts := FindBranchOptions{ - IDCond: builder.NotIn("id", prBranchIds), - RepoCond: builder.In("repo_id", repoIds), - CommitCond: builder.Neq{"commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them, - PusherID: doer.ID, + + baseBranch, err := GetBranch(ctx, opts.BaseRepo.ID, opts.BaseRepo.DefaultBranch) + if err != nil { + return nil, err + } + + findBranchOpts := FindBranchOptions{ + RepoCond: builder.In("branch.repo_id", repoIDs), + CommitCond: builder.Neq{"branch.commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them, + PusherID: opts.Actor.ID, IsDeletedBranch: util.OptionalBoolFalse, - CommitAfterUnix: commitAfterUnix, + CommitAfterUnix: opts.CommitAfterUnix, OrderBy: "branch.updated_unix DESC", + // should not use branch name here, because if there are branches with same name in different repos, + // we can not detect them correctly + PullRequestCond: builder.NotIn("branch.id", prBranchIds), } - opts.PageSize = 2 - opts.Page = 1 - return FindBranches(ctx, opts) + // only display top 2 latest branch + findBranchOpts.PageSize = 2 + findBranchOpts.Page = 1 + + return FindBranches(ctx, findBranchOpts) } diff --git a/models/git/branch_list.go b/models/git/branch_list.go index 0299737488324..3ea74f2bf4980 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -87,7 +87,6 @@ func (branches BranchList) LoadRepo(ctx context.Context) error { type FindBranchOptions struct { db.ListOptions - IDCond builder.Cond RepoIDs []int64 // overwrites RepoCond if the length is not 0 RepoCond builder.Cond ExcludeBranchNames []string @@ -97,13 +96,13 @@ type FindBranchOptions struct { CommitAfterUnix int64 CommitBeforeUnix int64 OrderBy string + + // find branch by pull request + PullRequestCond builder.Cond } func (opts *FindBranchOptions) Cond() builder.Cond { cond := builder.NewCond() - if opts.IDCond != nil { - cond = cond.And(opts.IDCond) - } if len(opts.RepoIDs) == 1 { opts.RepoCond = builder.Eq{"branch.repo_id": opts.RepoIDs[0]} @@ -136,6 +135,11 @@ func (opts *FindBranchOptions) Cond() builder.Cond { if opts.CommitBeforeUnix != 0 { cond = cond.And(builder.Lte{"branch.commit_time": opts.CommitBeforeUnix}) } + + if opts.PullRequestCond != nil { + cond = cond.And(opts.PullRequestCond) + } + return cond } diff --git a/models/git/branch_test.go b/models/git/branch_test.go index c4ab4d77da981..4d22a5b46304f 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -189,35 +189,61 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) - - // test new branch of the repo and org fork repo - // user2 is the owner of the repo and the organization user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) - branches, err := git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user2, 1689838760) - assert.NoError(t, err) - assert.Equal(t, 2, len(branches)) - assert.Equal(t, "new-commit", branches[0].Name) - assert.Equal(t, "org-fork-new-commit", branches[1].Name) - - // test new branch from user fork repo + user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) user8 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 8}) - branches, err = git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user8, 1689838760) - assert.NoError(t, err) - assert.Equal(t, 1, len(branches)) - assert.Equal(t, "user-fork-new-commit", branches[0].Name) - - // test new branch from private org with code permisstion repo user18 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 18}) - branches, err = git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user18, 1689838760) - assert.NoError(t, err) - assert.Equal(t, 1, len(branches)) - assert.Equal(t, "private-org-fork-new-commit", branches[0].Name) - // test new branch from private org with no code permisstion repo - user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) - branches, err = git_model.FindRecentlyPushedNewBranches(db.DefaultContext, repo, user5, 1689838760) - assert.NoError(t, err) - assert.Equal(t, 0, len(branches)) + tests := []struct { + name string + actor *user_model.User + count int + want []string + }{ + // user2 is the owner of the repo and the organization + { + name: "new branch of the repo and org fork repo", + actor: user2, + count: 2, + want: []string{"new-commit", "org-fork-new-commit"}, + }, + { + name: "new branch from user fork repo", + actor: user8, + count: 1, + want: []string{"user-fork-new-commit"}, + }, + { + name: "new branch from private org with code permisstion repo", + actor: user18, + count: 1, + want: []string{"private-org-fork-new-commit"}, + }, + { + name: "new branch from private org with no code permisstion repo", + actor: user5, + count: 0, + want: []string{"new-commit", "org-fork-new-commit"}, + }, + } + + opts := &git_model.FindRecentlyPushedNewBranchesOptions{ + Repo: repo, + BaseRepo: repo, + CommitAfterUnix: 1689838760, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + opts.Actor = tt.actor + branches, err := git_model.FindRecentlyPushedNewBranches(db.DefaultContext, opts) + assert.NoError(t, err) + assert.Equal(t, tt.count, len(branches)) + + for i := 1; i < tt.count; i++ { + assert.Equal(t, tt.want[i], branches[i].Name) + } + }) + } // TODO:test pr branch } diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go index 170a7482841fd..86f5e8a49790e 100644 --- a/models/repo/repo_list.go +++ b/models/repo/repo_list.go @@ -133,8 +133,9 @@ type SearchRepoOptions struct { // None -> include forks AND non-forks // True -> include just forks // False -> include just non-forks - Fork util.OptionalBool - ForkID int64 // If Fork option is True, you can use this option to limit the forks of a special repo by repo id. + Fork util.OptionalBool + // If Fork option is True, you can use this option to limit the forks of a special repo by repo id. + ForkFrom int64 // None -> include templates AND non-templates // True -> include just templates // False -> include just non-templates @@ -469,8 +470,8 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { } else { cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue}) - if opts.ForkID > 0 && opts.Fork == util.OptionalBoolTrue { - cond = cond.And(builder.Eq{"fork_id": opts.ForkID}) + if opts.ForkFrom > 0 && opts.Fork == util.OptionalBoolTrue { + cond = cond.And(builder.Eq{"fork_id": opts.ForkFrom}) } } } diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index ba62521a41745..5eb24f48e21b5 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -983,11 +983,15 @@ func renderCode(ctx *context.Context) { return } - baseRepo := ctx.Repo.Repository + opts := &git_model.FindRecentlyPushedNewBranchesOptions{ + Actor: ctx.Doer, + Repo: ctx.Repo.Repository, + BaseRepo: ctx.Repo.Repository, + } if ctx.Repo.Repository.IsFork { - baseRepo = ctx.Repo.Repository.BaseRepo + opts.BaseRepo = ctx.Repo.Repository.BaseRepo } - branches, err := git_model.FindRecentlyPushedNewBranches(ctx, baseRepo, ctx.Doer, 0) + branches, err := git_model.FindRecentlyPushedNewBranches(ctx, opts) if err != nil { ctx.ServerError("FindRecentlyPushedNewBranches", err) return From 4de1b0514c25d366be826c2f5deb44f249ac04f4 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 24 Jul 2023 02:40:50 +0000 Subject: [PATCH 26/97] revert RepoIDs --- models/git/branch_list.go | 8 +++----- models/git/branch_test.go | 2 +- models/git/protected_branch_list.go | 2 +- modules/context/repo.go | 2 +- modules/repository/branch.go | 2 +- routers/api/v1/repo/branch.go | 4 ++-- routers/web/repo/compare.go | 4 ++-- routers/web/repo/repo.go | 4 ++-- services/repository/adopt.go | 2 +- services/repository/branch.go | 2 +- 10 files changed, 15 insertions(+), 17 deletions(-) diff --git a/models/git/branch_list.go b/models/git/branch_list.go index 3ea74f2bf4980..bd74371ffdef4 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -87,7 +87,7 @@ func (branches BranchList) LoadRepo(ctx context.Context) error { type FindBranchOptions struct { db.ListOptions - RepoIDs []int64 // overwrites RepoCond if the length is not 0 + RepoID int64 RepoCond builder.Cond ExcludeBranchNames []string CommitCond builder.Cond @@ -104,10 +104,8 @@ type FindBranchOptions struct { func (opts *FindBranchOptions) Cond() builder.Cond { cond := builder.NewCond() - if len(opts.RepoIDs) == 1 { - opts.RepoCond = builder.Eq{"branch.repo_id": opts.RepoIDs[0]} - } else if len(opts.RepoIDs) > 1 { - opts.RepoCond = builder.In("branch.repo_id", opts.RepoIDs) + if opts.RepoID > 0 { + cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) } if opts.RepoCond != nil { cond = cond.And(opts.RepoCond) diff --git a/models/git/branch_test.go b/models/git/branch_test.go index 4d22a5b46304f..5552fd8eb13be 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -50,7 +50,7 @@ func TestGetDeletedBranches(t *testing.T) { ListOptions: db.ListOptions{ ListAll: true, }, - RepoIDs: []int64{repo.ID}, + RepoID: repo.ID, IsDeletedBranch: util.OptionalBoolTrue, }) assert.NoError(t, err) diff --git a/models/git/protected_branch_list.go b/models/git/protected_branch_list.go index f67bb14d173db..eeb307e2454e7 100644 --- a/models/git/protected_branch_list.go +++ b/models/git/protected_branch_list.go @@ -55,7 +55,7 @@ func FindAllMatchedBranches(ctx context.Context, repoID int64, ruleName string) PageSize: 100, Page: page, }, - RepoIDs: []int64{repoID}, + RepoID: repoID, IsDeletedBranch: util.OptionalBoolFalse, }) if err != nil { diff --git a/modules/context/repo.go b/modules/context/repo.go index acd14d983ebe6..f5c56cf833234 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -661,7 +661,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc { } branchOpts := git_model.FindBranchOptions{ - RepoIDs: []int64{ctx.Repo.Repository.ID}, + RepoID: ctx.Repo.Repository.ID, IsDeletedBranch: util.OptionalBoolFalse, ListOptions: db.ListOptions{ ListAll: true, diff --git a/modules/repository/branch.go b/modules/repository/branch.go index 2c45dbb7f2707..bffadd62f4d92 100644 --- a/modules/repository/branch.go +++ b/modules/repository/branch.go @@ -53,7 +53,7 @@ func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository, ListOptions: db.ListOptions{ ListAll: true, }, - RepoIDs: []int64{repo.ID}, + RepoID: repo.ID, }) if err != nil { return 0, err diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go index b00472b55ea83..577776dadd36d 100644 --- a/routers/api/v1/repo/branch.go +++ b/routers/api/v1/repo/branch.go @@ -142,7 +142,7 @@ func DeleteBranch(ctx *context.APIContext) { // check whether branches of this repository has been synced totalNumOfBranches, err := git_model.CountBranches(ctx, git_model.FindBranchOptions{ - RepoIDs: []int64{ctx.Repo.Repository.ID}, + RepoID: ctx.Repo.Repository.ID, IsDeletedBranch: util.OptionalBoolFalse, }) if err != nil { @@ -349,7 +349,7 @@ func ListBranches(ctx *context.APIContext) { branchOpts := git_model.FindBranchOptions{ ListOptions: listOptions, - RepoIDs: []int64{ctx.Repo.Repository.ID}, + RepoID: ctx.Repo.Repository.ID, IsDeletedBranch: util.OptionalBoolFalse, } var err error diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 0432106056c0b..4ceb52d03994a 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -685,7 +685,7 @@ func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repositor defer gitRepo.Close() branches, err = git_model.FindBranchNames(ctx, git_model.FindBranchOptions{ - RepoIDs: []int64{repo.ID}, + RepoID: repo.ID, ListOptions: db.ListOptions{ ListAll: true, }, @@ -742,7 +742,7 @@ func CompareDiff(ctx *context.Context) { } headBranches, err := git_model.FindBranchNames(ctx, git_model.FindBranchOptions{ - RepoIDs: []int64{ci.HeadRepo.ID}, + RepoID: ci.HeadRepo.ID, ListOptions: db.ListOptions{ ListAll: true, }, diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index c8f4bbb4d6bf5..0de804dbce6fa 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -630,7 +630,7 @@ type branchTagSearchResponse struct { // GetBranchesList get branches for current repo' func GetBranchesList(ctx *context.Context) { branchOpts := git_model.FindBranchOptions{ - RepoIDs: []int64{ctx.Repo.Repository.ID}, + RepoID: ctx.Repo.Repository.ID, IsDeletedBranch: util.OptionalBoolFalse, ListOptions: db.ListOptions{ ListAll: true, @@ -665,7 +665,7 @@ func GetTagList(ctx *context.Context) { func PrepareBranchList(ctx *context.Context) { branchOpts := git_model.FindBranchOptions{ - RepoIDs: []int64{ctx.Repo.Repository.ID}, + RepoID: ctx.Repo.Repository.ID, IsDeletedBranch: util.OptionalBoolFalse, ListOptions: db.ListOptions{ ListAll: true, diff --git a/services/repository/adopt.go b/services/repository/adopt.go index 450c0371fc13a..f95fb5988f66b 100644 --- a/services/repository/adopt.go +++ b/services/repository/adopt.go @@ -149,7 +149,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r } branches, _ := git_model.FindBranchNames(ctx, git_model.FindBranchOptions{ - RepoIDs: []int64{repo.ID}, + RepoID: repo.ID, ListOptions: db.ListOptions{ ListAll: true, }, diff --git a/services/repository/branch.go b/services/repository/branch.go index 3dd42361291b9..11a8b20531578 100644 --- a/services/repository/branch.go +++ b/services/repository/branch.go @@ -73,7 +73,7 @@ func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git } branchOpts := git_model.FindBranchOptions{ - RepoIDs: []int64{repo.ID}, + RepoID: repo.ID, IsDeletedBranch: isDeletedBranch, ListOptions: db.ListOptions{ Page: page, From 94025efd44398316a66edc42ad57f0960ae2e44e Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 24 Jul 2023 08:09:29 +0000 Subject: [PATCH 27/97] improve --- models/git/branch.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index ad4966339ca9f..52d7cad19fc81 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -457,10 +457,12 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed // should not use branch name here, because if there are branches with same name in different repos, // we can not detect them correctly PullRequestCond: builder.NotIn("branch.id", prBranchIds), + // only display top 2 latest branch + ListOptions: db.ListOptions{ + PageSize: 2, + Page: 1, + }, } - // only display top 2 latest branch - findBranchOpts.PageSize = 2 - findBranchOpts.Page = 1 return FindBranches(ctx, findBranchOpts) } From 274e5abdac0ebfacdb9a31b82fda68f42958fae1 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 24 Jul 2023 08:17:54 +0000 Subject: [PATCH 28/97] fix test --- models/fixtures/branch.yml | 4 ++-- models/fixtures/repository.yml | 4 ++-- models/fixtures/user.yml | 37 +++++++++++++++++++++++++++++++ models/git/branch_test.go | 4 ++-- models/repo/repo_list_test.go | 2 +- tests/integration/api_org_test.go | 4 ++-- 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index ad8d9260bfdf1..58cdd1058514b 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -89,7 +89,7 @@ commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1689838761 - pusher_id: 8 + pusher_id: 39 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -101,7 +101,7 @@ commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 8 + pusher_id: 39 is_deleted: false deleted_by_id: 0 deleted_unix: 0 diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 62fe70cb0ef8c..f3e08fd330e06 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -1665,8 +1665,8 @@ - id: 58 - owner_id: 8 - owner_name: user8 + owner_id: 39 + owner_name: user39 lower_name: user_fork_repo1 name: user_fork_repo1 num_watches: 0 diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 44e7547c5e31c..159e72c3d7b7d 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -1406,3 +1406,40 @@ repo_admin_change_team_access: false theme: "" keep_activity_private: false + +- + id: 39 + lower_name: user39 + name: user39 + full_name: user39 + email: user39@example.com + keep_email_private: true + email_notifications_preference: enabled + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy + must_change_password: false + login_source: 0 + login_name: user39 + type: 0 + salt: ZogKvWdyEx + max_repo_creation: -1 + is_active: true + is_admin: false + is_restricted: false + allow_git_hook: false + allow_import_local: false + allow_create_organization: true + prohibit_login: false + avatar: avatar39 + avatar_email: user39@example.com + use_custom_avatar: false + num_followers: 0 + num_following: 0 + num_stars: 0 + num_repos: 1 + num_teams: 0 + num_members: 0 + visibility: 0 + repo_admin_change_team_access: false + theme: "" + keep_activity_private: false \ No newline at end of file diff --git a/models/git/branch_test.go b/models/git/branch_test.go index 5552fd8eb13be..5f20e9cae5867 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -191,8 +191,8 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) - user8 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 8}) user18 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 18}) + user39 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 39}) tests := []struct { name string @@ -209,7 +209,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { }, { name: "new branch from user fork repo", - actor: user8, + actor: user39, count: 1, want: []string{"user-fork-new-commit"}, }, diff --git a/models/repo/repo_list_test.go b/models/repo/repo_list_test.go index a411b1c8f18b8..87665e76478fa 100644 --- a/models/repo/repo_list_test.go +++ b/models/repo/repo_list_test.go @@ -205,7 +205,7 @@ func TestSearchRepository(t *testing.T) { { name: "PublicAndPrivateRepositoriesOfUser2IncludingCollaborative", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true}, - count: 4, + count: 5, }, { name: "PublicAndPrivateRepositoriesOfUser3IncludingCollaborative", diff --git a/tests/integration/api_org_test.go b/tests/integration/api_org_test.go index 83a101716b099..89bce0a01e733 100644 --- a/tests/integration/api_org_test.go +++ b/tests/integration/api_org_test.go @@ -170,7 +170,7 @@ func TestAPIGetAll(t *testing.T) { var apiOrgList []*api.Organization DecodeJSON(t, resp, &apiOrgList) - assert.Len(t, apiOrgList, 11) + assert.Len(t, apiOrgList, 13) assert.Equal(t, "Limited Org 36", apiOrgList[1].FullName) assert.Equal(t, "limited", apiOrgList[1].Visibility) @@ -179,7 +179,7 @@ func TestAPIGetAll(t *testing.T) { resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiOrgList) - assert.Len(t, apiOrgList, 7) + assert.Len(t, apiOrgList, 8) assert.Equal(t, "org25", apiOrgList[0].FullName) assert.Equal(t, "public", apiOrgList[0].Visibility) } From f9b4085b57f2051cfe9ceb2257466a9301a01577 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 24 Jul 2023 08:22:39 +0000 Subject: [PATCH 29/97] fix test --- tests/integration/api_repo_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go index fae1415568692..43fab43f5bbb3 100644 --- a/tests/integration/api_repo_test.go +++ b/tests/integration/api_repo_test.go @@ -93,9 +93,9 @@ func TestAPISearchRepo(t *testing.T) { }{ { name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{ - nil: {count: 32}, - user: {count: 32}, - user2: {count: 32}, + nil: {count: 34}, + user: {count: 34}, + user2: {count: 34}, }, }, { From 86892d458d0ec19f48affdf8d81c0e87b863274c Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 25 Jul 2023 02:05:43 +0000 Subject: [PATCH 30/97] fix tests --- models/fixture_test.go | 2 + models/fixtures/access.yml | 60 ++++----- models/fixtures/branch.yml | 32 ++--- models/fixtures/org_user.yml | 6 +- models/fixtures/repo_unit.yml | 12 ++ models/fixtures/repository.yml | 8 +- models/fixtures/team_user.yml | 6 +- models/fixtures/user.yml | 115 +++++++++++++++++- models/git/branch_test.go | 64 ++++++---- ...{new-branch-no-notification => new-commit} | 0 .../{new-branch-notification => no-commit} | 0 tests/integration/api_nodeinfo_test.go | 2 +- 12 files changed, 222 insertions(+), 85 deletions(-) rename tests/gitea-repositories-meta/user2/repo1.git/refs/heads/{new-branch-no-notification => new-commit} (100%) rename tests/gitea-repositories-meta/user2/repo1.git/refs/heads/{new-branch-notification => no-commit} (100%) diff --git a/models/fixture_test.go b/models/fixture_test.go index 8a28db8164921..7bff5115b7e44 100644 --- a/models/fixture_test.go +++ b/models/fixture_test.go @@ -4,6 +4,7 @@ package models import ( + "fmt" "os" "path/filepath" "testing" @@ -27,6 +28,7 @@ func TestFixtureGeneration(t *testing.T) { return } data := string(util.NormalizeEOL(bytes)) + fmt.Println(expected) assert.True(t, data == expected, "Differences detected for %s.yml", name) } diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index 61c344d36c73b..676aecb282f87 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -24,127 +24,127 @@ - id: 5 - user_id: 2 - repo_id: 59 - mode: 4 - -- - id: 6 user_id: 4 repo_id: 3 mode: 2 - - id: 7 + id: 6 user_id: 4 repo_id: 4 mode: 2 - - id: 8 + id: 7 user_id: 4 repo_id: 40 mode: 2 - - id: 9 + id: 8 user_id: 15 repo_id: 21 mode: 2 - - id: 10 + id: 9 user_id: 15 repo_id: 22 mode: 2 - - id: 11 + id: 10 user_id: 15 repo_id: 23 mode: 4 - - id: 12 + id: 11 user_id: 15 repo_id: 24 mode: 4 - - id: 13 + id: 12 user_id: 15 repo_id: 32 mode: 2 - - id: 14 + id: 13 user_id: 18 repo_id: 21 mode: 2 - - id: 15 + id: 14 user_id: 18 repo_id: 22 mode: 2 - - id: 16 + id: 15 user_id: 18 repo_id: 23 mode: 4 - - id: 17 + id: 16 user_id: 18 repo_id: 24 mode: 4 - - id: 18 - user_id: 18 - repo_id: 60 - mode: 1 - -- - id: 19 + id: 17 user_id: 20 repo_id: 24 mode: 1 - - id: 20 + id: 18 user_id: 20 repo_id: 27 mode: 4 - - id: 21 + id: 19 user_id: 20 repo_id: 28 mode: 4 - - id: 22 + id: 20 user_id: 29 repo_id: 4 mode: 2 - - id: 23 + id: 21 user_id: 29 repo_id: 24 mode: 1 - - id: 24 + id: 22 user_id: 31 repo_id: 27 mode: 4 - - id: 25 + id: 23 user_id: 31 repo_id: 28 mode: 4 +- + id: 24 + user_id: 40 + repo_id: 59 + mode: 4 + +- + id: 25 + user_id: 41 + repo_id: 60 + mode: 1 + diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index 58cdd1058514b..ae390ac4935b0 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -52,8 +52,8 @@ name: 'new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' - commit_time: 1689838761 - pusher_id: 2 + commit_time: 1489927680 + pusher_id: 39 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -65,7 +65,7 @@ commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 2 + pusher_id: 39 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -88,8 +88,8 @@ name: 'user-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' - commit_time: 1689838761 - pusher_id: 39 + commit_time: 1489927680 + pusher_id: 40 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -101,7 +101,7 @@ commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 39 + pusher_id: 40 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -124,8 +124,8 @@ name: 'org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' - commit_time: 1689838761 - pusher_id: 2 + commit_time: 1489927691 + pusher_id: 39 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -136,8 +136,8 @@ name: 'org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' - commit_time: 1489927679 - pusher_id: 2 + commit_time: 1489927691 + pusher_id: 39 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -160,8 +160,8 @@ name: 'private-org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' - commit_time: 1689838761 - pusher_id: 18 + commit_time: 1489927680 + pusher_id: 41 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -173,7 +173,7 @@ commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 18 + pusher_id: 41 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -184,8 +184,8 @@ name: 'private-org-fork-no-permission-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' - commit_time: 1689838761 - pusher_id: 5 + commit_time: 1489927680 + pusher_id: 42 is_deleted: false deleted_by_id: 0 deleted_unix: 0 @@ -197,7 +197,7 @@ commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 5 + pusher_id: 42 is_deleted: false deleted_by_id: 0 deleted_unix: 0 diff --git a/models/fixtures/org_user.yml b/models/fixtures/org_user.yml index ae3353b7446e4..8505744ed6ea1 100644 --- a/models/fixtures/org_user.yml +++ b/models/fixtures/org_user.yml @@ -102,18 +102,18 @@ - id: 18 - uid: 2 + uid: 39 org_id: 37 is_public: false - id: 19 - uid: 18 + uid: 41 org_id: 38 is_public: false - id: 20 - uid: 5 + uid: 42 org_id: 38 is_public: false diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index 5bb974a7d7088..ef27bde30d835 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -607,3 +607,15 @@ repo_id: 52 type: 1 created_unix: 946684810 + +- + id: 91 + repo_id: 59 + type: 1 + created_unix: 946684810 + +- + id: 92 + repo_id: 60 + type: 1 + created_unix: 946684810 diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index f3e08fd330e06..18886512c6428 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -1665,10 +1665,10 @@ - id: 58 - owner_id: 39 - owner_name: user39 - lower_name: user_fork_repo1 - name: user_fork_repo1 + owner_id: 40 + owner_name: user40 + lower_name: user_fork_repo + name: user_fork_repo num_watches: 0 num_stars: 0 num_forks: 0 diff --git a/models/fixtures/team_user.yml b/models/fixtures/team_user.yml index 035393dd641ae..ab6b87c0779d3 100644 --- a/models/fixtures/team_user.yml +++ b/models/fixtures/team_user.yml @@ -128,16 +128,16 @@ id: 22 org_id: 37 team_id: 21 - uid: 2 + uid: 40 - id: 23 org_id: 38 team_id: 23 - uid: 18 + uid: 41 - id: 24 org_id: 38 team_id: 24 - uid: 5 + uid: 42 diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 159e72c3d7b7d..a37e46f84f3bd 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -288,7 +288,7 @@ num_followers: 1 num_following: 1 num_stars: 0 - num_repos: 1 + num_repos: 0 num_teams: 0 num_members: 0 visibility: 0 @@ -1436,10 +1436,121 @@ num_followers: 0 num_following: 0 num_stars: 0 + num_repos: 0 + num_teams: 0 + num_members: 0 + visibility: 0 + repo_admin_change_team_access: false + theme: "" + keep_activity_private: false + +- + id: 40 + lower_name: user40 + name: user40 + full_name: user40 + email: user40@example.com + keep_email_private: true + email_notifications_preference: enabled + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy + must_change_password: false + login_source: 0 + login_name: user40 + type: 0 + salt: ZogKvWdyEx + max_repo_creation: -1 + is_active: true + is_admin: false + is_restricted: false + allow_git_hook: false + allow_import_local: false + allow_create_organization: true + prohibit_login: false + avatar: avatar40 + avatar_email: user40@example.com + use_custom_avatar: false + num_followers: 0 + num_following: 0 + num_stars: 0 num_repos: 1 num_teams: 0 num_members: 0 visibility: 0 repo_admin_change_team_access: false theme: "" - keep_activity_private: false \ No newline at end of file + keep_activity_private: false + +- + id: 41 + lower_name: user41 + name: user41 + full_name: user41 + email: user41@example.com + keep_email_private: true + email_notifications_preference: enabled + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy + must_change_password: false + login_source: 0 + login_name: user41 + type: 0 + salt: ZogKvWdyEx + max_repo_creation: -1 + is_active: true + is_admin: false + is_restricted: false + allow_git_hook: false + allow_import_local: false + allow_create_organization: true + prohibit_login: false + avatar: avatar41 + avatar_email: user41@example.com + use_custom_avatar: false + num_followers: 0 + num_following: 0 + num_stars: 0 + num_repos: 0 + num_teams: 0 + num_members: 0 + visibility: 0 + repo_admin_change_team_access: false + theme: "" + keep_activity_private: false + +- + id: 42 + lower_name: user42 + name: user42 + full_name: user42 + email: user42@example.com + keep_email_private: true + email_notifications_preference: enabled + passwd: ZogKvWdyEx:password + passwd_hash_algo: dummy + must_change_password: false + login_source: 0 + login_name: user42 + type: 0 + salt: ZogKvWdyEx + max_repo_creation: -1 + is_active: true + is_admin: false + is_restricted: false + allow_git_hook: false + allow_import_local: false + allow_create_organization: true + prohibit_login: false + avatar: avatar42 + avatar_email: user42@example.com + use_custom_avatar: false + num_followers: 0 + num_following: 0 + num_stars: 0 + num_repos: 0 + num_teams: 0 + num_members: 0 + visibility: 0 + repo_admin_change_team_access: false + theme: "" + keep_activity_private: false diff --git a/models/git/branch_test.go b/models/git/branch_test.go index 5f20e9cae5867..49f9ebb327dbd 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -189,52 +189,64 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) - user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) - user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) - user18 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 18}) user39 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 39}) + user40 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 40}) + user41 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 41}) + user42 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 42}) tests := []struct { - name string - actor *user_model.User - count int - want []string + name string + actor *user_model.User + count int + commitAfterUnix int64 + want []string }{ // user2 is the owner of the repo and the organization { - name: "new branch of the repo and org fork repo", - actor: user2, - count: 2, - want: []string{"new-commit", "org-fork-new-commit"}, + name: "new branch of the repo", + actor: user39, + count: 2, + commitAfterUnix: 1489927670, + want: []string{"new-commit", "org-fork-new-commit"}, }, { - name: "new branch from user fork repo", - actor: user39, - count: 1, - want: []string{"user-fork-new-commit"}, + name: "new branch of org fork repo", + actor: user39, + count: 1, + commitAfterUnix: 1489927690, + want: []string{"org-fork-new-commit"}, }, { - name: "new branch from private org with code permisstion repo", - actor: user18, - count: 1, - want: []string{"private-org-fork-new-commit"}, + name: "new branch from user fork repo", + actor: user40, + count: 1, + commitAfterUnix: 1489927670, + want: []string{"user-fork-new-commit"}, }, { - name: "new branch from private org with no code permisstion repo", - actor: user5, - count: 0, - want: []string{"new-commit", "org-fork-new-commit"}, + name: "new branch from private org with code permisstion repo", + actor: user41, + count: 1, + commitAfterUnix: 1489927670, + want: []string{"private-org-fork-new-commit"}, + }, + { + name: "new branch from private org with no code permisstion repo", + actor: user42, + count: 0, + commitAfterUnix: 1489927670, + want: []string{"new-commit", "org-fork-new-commit"}, }, } opts := &git_model.FindRecentlyPushedNewBranchesOptions{ - Repo: repo, - BaseRepo: repo, - CommitAfterUnix: 1689838760, + Repo: repo, + BaseRepo: repo, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { opts.Actor = tt.actor + opts.CommitAfterUnix = tt.commitAfterUnix branches, err := git_model.FindRecentlyPushedNewBranches(db.DefaultContext, opts) assert.NoError(t, err) assert.Equal(t, tt.count, len(branches)) diff --git a/tests/gitea-repositories-meta/user2/repo1.git/refs/heads/new-branch-no-notification b/tests/gitea-repositories-meta/user2/repo1.git/refs/heads/new-commit similarity index 100% rename from tests/gitea-repositories-meta/user2/repo1.git/refs/heads/new-branch-no-notification rename to tests/gitea-repositories-meta/user2/repo1.git/refs/heads/new-commit diff --git a/tests/gitea-repositories-meta/user2/repo1.git/refs/heads/new-branch-notification b/tests/gitea-repositories-meta/user2/repo1.git/refs/heads/no-commit similarity index 100% rename from tests/gitea-repositories-meta/user2/repo1.git/refs/heads/new-branch-notification rename to tests/gitea-repositories-meta/user2/repo1.git/refs/heads/no-commit diff --git a/tests/integration/api_nodeinfo_test.go b/tests/integration/api_nodeinfo_test.go index 158a8660914a4..1a579640abfa3 100644 --- a/tests/integration/api_nodeinfo_test.go +++ b/tests/integration/api_nodeinfo_test.go @@ -32,7 +32,7 @@ func TestNodeinfo(t *testing.T) { DecodeJSON(t, resp, &nodeinfo) assert.True(t, nodeinfo.OpenRegistrations) assert.Equal(t, "gitea", nodeinfo.Software.Name) - assert.Equal(t, 25, nodeinfo.Usage.Users.Total) + assert.Equal(t, 29, nodeinfo.Usage.Users.Total) assert.Equal(t, 18, nodeinfo.Usage.LocalPosts) assert.Equal(t, 2, nodeinfo.Usage.LocalComments) }) From 66071ac97b12ef83f4c5a46c3c4f61fb5e8d7ad8 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 26 Jul 2023 08:31:38 +0000 Subject: [PATCH 31/97] remove test code --- models/fixture_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/models/fixture_test.go b/models/fixture_test.go index 7bff5115b7e44..8a28db8164921 100644 --- a/models/fixture_test.go +++ b/models/fixture_test.go @@ -4,7 +4,6 @@ package models import ( - "fmt" "os" "path/filepath" "testing" @@ -28,7 +27,6 @@ func TestFixtureGeneration(t *testing.T) { return } data := string(util.NormalizeEOL(bytes)) - fmt.Println(expected) assert.True(t, data == expected, "Differences detected for %s.yml", name) } From 76f472dba8a23c92a79e0c5f45c5df5118afcb16 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 26 Jul 2023 08:40:20 +0000 Subject: [PATCH 32/97] move ListOptions --- models/git/branch.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index 52d7cad19fc81..a69b5b587b37a 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -394,6 +394,7 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str } type FindRecentlyPushedNewBranchesOptions struct { + db.ListOptions Actor *user_model.User Repo *repo_model.Repository BaseRepo *repo_model.Repository @@ -447,6 +448,12 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed return nil, err } + // defalutly we only display top 2 latest branch + if opts.ListOptions.PageSize == 0 && opts.ListOptions.Page == 0 { + opts.ListOptions.PageSize = 2 + opts.ListOptions.Page = 1 + } + findBranchOpts := FindBranchOptions{ RepoCond: builder.In("branch.repo_id", repoIDs), CommitCond: builder.Neq{"branch.commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them, @@ -457,11 +464,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed // should not use branch name here, because if there are branches with same name in different repos, // we can not detect them correctly PullRequestCond: builder.NotIn("branch.id", prBranchIds), - // only display top 2 latest branch - ListOptions: db.ListOptions{ - PageSize: 2, - Page: 1, - }, + ListOptions: opts.ListOptions, } return FindBranches(ctx, findBranchOpts) From b57883c31ce50b49d8b6f6ca989478c2857a3ec9 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 26 Jul 2023 08:44:47 +0000 Subject: [PATCH 33/97] improve --- models/git/branch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/git/branch.go b/models/git/branch.go index a69b5b587b37a..32e5c747cb1db 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -404,6 +404,7 @@ type FindRecentlyPushedNewBranchesOptions struct { // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created // opts.Actor should not be nil // if opts.CommitAfterUnix is 0, we will find the branches committed in recently 6 hours +// if opts.ListOptions is not set, we will only display top 2 latest branch func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushedNewBranchesOptions) (BranchList, error) { // find all related repo ids repoOpts := repo_model.SearchRepoOptions{ @@ -448,7 +449,6 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed return nil, err } - // defalutly we only display top 2 latest branch if opts.ListOptions.PageSize == 0 && opts.ListOptions.Page == 0 { opts.ListOptions.PageSize = 2 opts.ListOptions.Page = 1 From a583c64fd0ab9212e8525abd3f35e434599d899d Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 26 Jul 2023 23:55:46 +0000 Subject: [PATCH 34/97] fix test --- models/repo/repo_list_test.go | 2 +- models/user/user_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/repo/repo_list_test.go b/models/repo/repo_list_test.go index 87665e76478fa..a411b1c8f18b8 100644 --- a/models/repo/repo_list_test.go +++ b/models/repo/repo_list_test.go @@ -205,7 +205,7 @@ func TestSearchRepository(t *testing.T) { { name: "PublicAndPrivateRepositoriesOfUser2IncludingCollaborative", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true}, - count: 5, + count: 4, }, { name: "PublicAndPrivateRepositoriesOfUser3IncludingCollaborative", diff --git a/models/user/user_test.go b/models/user/user_test.go index 897aa432949b7..6b66f0623d9ab 100644 --- a/models/user/user_test.go +++ b/models/user/user_test.go @@ -101,13 +101,13 @@ func TestSearchUsers(t *testing.T) { } testUserSuccess(&user_model.SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}}, - []int64{1, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32, 34}) + []int64{1, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32, 34, 39, 40, 41, 42}) testUserSuccess(&user_model.SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolFalse}, []int64{9}) testUserSuccess(&user_model.SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolTrue}, - []int64{1, 2, 4, 5, 8, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32, 34}) + []int64{1, 2, 4, 5, 8, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32, 34, 39, 40, 41, 42}) testUserSuccess(&user_model.SearchUserOptions{Keyword: "user1", OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolTrue}, []int64{1, 10, 11, 12, 13, 14, 15, 16, 18}) From 3b6ff9ba0ac61a719dc7d8bf25ad1e436a4abc02 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 27 Jul 2023 01:49:52 +0000 Subject: [PATCH 35/97] improve test --- models/fixtures/branch.yml | 116 ++++++++++++++++++++++++++++--- models/fixtures/issue.yml | 102 +++++++++++++++++++++++++++ models/fixtures/issue_index.yml | 14 +++- models/fixtures/pull_request.yml | 78 +++++++++++++++++++++ models/fixtures/repository.yml | 2 +- models/git/branch.go | 7 +- models/git/branch_test.go | 97 +++++++++++++++----------- 7 files changed, 357 insertions(+), 59 deletions(-) diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index ae390ac4935b0..287ffdb8971c0 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -72,6 +72,78 @@ - id: 7 + repo_id: 1 + name: 'opening-pr' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1489927680 + pusher_id: 39 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 8 + repo_id: 1 + name: 'closed-pr' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1489927680 + pusher_id: 39 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 9 + repo_id: 1 + name: 'merged-pr' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1489927680 + pusher_id: 39 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 10 + repo_id: 1 + name: 'closed-pr-with-deleted-branch' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1489927680 + pusher_id: 39 + is_deleted: true + deleted_by_id: 39 + deleted_unix: 1489927700 + +- + id: 11 + repo_id: 1 + name: 'merged-pr-with-deleted-branch' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1489927680 + pusher_id: 39 + is_deleted: true + deleted_by_id: 39 + deleted_unix: 1489927700 + +- + id: 12 + repo_id: 1 + name: 'deleted-branch' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1489927680 + pusher_id: 39 + is_deleted: true + deleted_by_id: 39 + deleted_unix: 1489927700 + +- + id: 13 repo_id: 58 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' @@ -83,7 +155,7 @@ deleted_unix: 0 - - id: 8 + id: 14 repo_id: 58 name: 'user-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' @@ -95,7 +167,7 @@ deleted_unix: 0 - - id: 9 + id: 15 repo_id: 58 name: 'user-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' @@ -107,7 +179,7 @@ deleted_unix: 0 - - id: 10 + id: 16 repo_id: 59 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' @@ -119,7 +191,7 @@ deleted_unix: 0 - - id: 11 + id: 17 repo_id: 59 name: 'org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' @@ -131,7 +203,7 @@ deleted_unix: 0 - - id: 12 + id: 18 repo_id: 59 name: 'org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' @@ -143,7 +215,7 @@ deleted_unix: 0 - - id: 13 + id: 19 repo_id: 60 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' @@ -155,7 +227,7 @@ deleted_unix: 0 - - id: 14 + id: 20 repo_id: 60 name: 'private-org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' @@ -167,7 +239,7 @@ deleted_unix: 0 - - id: 15 + id: 21 repo_id: 60 name: 'private-org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' @@ -179,7 +251,7 @@ deleted_unix: 0 - - id: 16 + id: 22 repo_id: 60 name: 'private-org-fork-no-permission-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' @@ -191,7 +263,7 @@ deleted_unix: 0 - - id: 17 + id: 23 repo_id: 60 name: 'private-org-fork-no-permission-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' @@ -201,3 +273,27 @@ is_deleted: false deleted_by_id: 0 deleted_unix: 0 + +- + id: 24 + repo_id: 1 + name: 'same-name-branch-in-pr' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1489927680 + pusher_id: 40 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 25 + repo_id: 58 + name: 'same-name-branch-in-pr' + commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' + commit_message: 'add' + commit_time: 1489927680 + pusher_id: 40 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index 174345ff5a1fc..20f3a29d00ea1 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -304,3 +304,105 @@ created_unix: 946684830 updated_unix: 978307200 is_locked: false + +- + id: 19 + repo_id: 1 + index: 6 + poster_id: 39 + original_author_id: 0 + name: opening pr for recently new branch search test + content: content + milestone_id: 0 + priority: 0 + is_closed: false + is_pull: true + num_comments: 0 + created_unix: 946684830 + updated_unix: 978307200 + is_locked: false + +- + id: 20 + repo_id: 1 + index: 7 + poster_id: 39 + original_author_id: 0 + name: closed pr for recently new branch search test + content: content + milestone_id: 0 + priority: 0 + is_closed: true + is_pull: true + num_comments: 0 + created_unix: 946684830 + updated_unix: 978307200 + is_locked: false + +- + id: 21 + repo_id: 1 + index: 8 + poster_id: 39 + original_author_id: 0 + name: merged pr for recently new branch search test + content: content + milestone_id: 0 + priority: 0 + is_closed: false + is_pull: true + num_comments: 0 + created_unix: 946684830 + updated_unix: 978307200 + is_locked: false + +- + id: 22 + repo_id: 1 + index: 9 + poster_id: 39 + original_author_id: 0 + name: closed pr with deleted branch for recently new branch search test + content: content + milestone_id: 0 + priority: 0 + is_closed: true + is_pull: true + num_comments: 0 + created_unix: 946684830 + updated_unix: 978307200 + is_locked: false + +- + id: 23 + repo_id: 1 + index: 10 + poster_id: 39 + original_author_id: 0 + name: merged pr with deleted branch for recently new branch search test + content: content + milestone_id: 0 + priority: 0 + is_closed: false + is_pull: true + num_comments: 0 + created_unix: 946684830 + updated_unix: 978307200 + is_locked: false + +- + id: 24 + repo_id: 58 + index: 1 + poster_id: 40 + original_author_id: 0 + name: pr with same branch name for recently new branch search test + content: content + milestone_id: 0 + priority: 0 + is_closed: false + is_pull: true + num_comments: 0 + created_unix: 946684830 + updated_unix: 978307200 + is_locked: false \ No newline at end of file diff --git a/models/fixtures/issue_index.yml b/models/fixtures/issue_index.yml index de6e955804ab6..4ed80bc2bff6e 100644 --- a/models/fixtures/issue_index.yml +++ b/models/fixtures/issue_index.yml @@ -1,27 +1,39 @@ - group_id: 1 - max_index: 5 + max_index: 10 + - group_id: 2 max_index: 2 + - group_id: 3 max_index: 2 + - group_id: 10 max_index: 1 + - group_id: 32 max_index: 2 + - group_id: 48 max_index: 1 + - group_id: 42 max_index: 1 + - group_id: 50 max_index: 1 + - group_id: 51 max_index: 1 + +- + group_id: 58 + max_index: 1 diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index 165437f0328dd..11e619a22637c 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -76,3 +76,81 @@ base_branch: master merge_base: 2a47ca4b614a9f5a has_merged: false + +- + id: 7 + type: 0 # gitea pull request + status: 2 # mergable + issue_id: 19 + index: 4 + head_repo_id: 1 + base_repo_id: 1 + head_branch: opening-pr + base_branch: master + merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d + has_merged: false + +- + id: 8 + type: 0 # gitea pull request + status: 2 # mergable + issue_id: 20 + index: 5 + head_repo_id: 1 + base_repo_id: 1 + head_branch: closed-pr + base_branch: master + merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d + has_merged: false + +- + id: 9 + type: 0 # gitea pull request + status: 3 # manually merged + issue_id: 21 + index: 6 + head_repo_id: 1 + base_repo_id: 1 + head_branch: merged-pr + base_branch: master + merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d + has_merged: true + +- + id: 10 + type: 0 # gitea pull request + status: 2 # mergable + issue_id: 22 + index: 7 + head_repo_id: 1 + base_repo_id: 1 + head_branch: closed-pr-with-deleted-branch + base_branch: master + merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d + has_merged: false + +- + id: 11 + type: 0 # gitea pull request + status: 3 # manually merged + issue_id: 23 + index: 8 + head_repo_id: 1 + base_repo_id: 1 + head_branch: merged-pr-with-deleted-branch + base_branch: master + merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d + has_merged: true + +- + id: 12 + type: 0 # gitea pull request + status: 2 # mergable + issue_id: 25 + index: 1 + head_repo_id: 58 + base_repo_id: 1 + head_branch: same-name-branch-in-pr + base_branch: master + merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d + has_merged: false diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 18886512c6428..55737f1bdf046 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -12,7 +12,7 @@ num_issues: 2 num_closed_issues: 1 num_pulls: 3 - num_closed_pulls: 0 + num_closed_pulls: 1 num_milestones: 3 num_closed_milestones: 1 num_projects: 1 diff --git a/models/git/branch.go b/models/git/branch.go index 32e5c747cb1db..722904bd287b1 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -429,15 +429,10 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed // find branches which have already created PRs prBranchIds := builder.Select("branch.id").From("branch"). InnerJoin("pull_request", "branch.name = pull_request.head_branch AND branch.repo_id = pull_request.head_repo_id"). - InnerJoin("issue", "issue.id = pull_request.issue_id"). Where(builder.And( builder.Eq{"pull_request.base_repo_id": opts.BaseRepo.ID}, builder.Eq{"pull_request.base_branch": opts.BaseRepo.DefaultBranch}, builder.In("pull_request.head_repo_id", repoIDs), - builder.Or( - builder.Eq{"issue.is_closed": true}, - builder.Eq{"pull_request.has_merged": true}, - ), )) if opts.CommitAfterUnix == 0 { @@ -449,7 +444,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed return nil, err } - if opts.ListOptions.PageSize == 0 && opts.ListOptions.Page == 0 { + if opts.ListOptions.PageSize == 0 { opts.ListOptions.PageSize = 2 opts.ListOptions.Page = 1 } diff --git a/models/git/branch_test.go b/models/git/branch_test.go index 49f9ebb327dbd..654b13c027a4c 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -195,67 +195,82 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { user42 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 42}) tests := []struct { - name string - actor *user_model.User - count int - commitAfterUnix int64 - want []string + name string + opts *git_model.FindRecentlyPushedNewBranchesOptions + count int + want []int64 }{ - // user2 is the owner of the repo and the organization + // user39 is the owner of the repo and the organization + // in repo 1, user39 has opening/closed/merged pr and closed/merged pr with deleted branch { - name: "new branch of the repo", - actor: user39, - count: 2, - commitAfterUnix: 1489927670, - want: []string{"new-commit", "org-fork-new-commit"}, + name: "new branch of the repo, org fork repo, pr branches and deleted branch", + opts: &git_model.FindRecentlyPushedNewBranchesOptions{ + Actor: user39, + CommitAfterUnix: 1489927670, + ListOptions: db.ListOptions{ + PageSize: 10, + Page: 1, + }, + }, + count: 2, + want: []int64{5, 17}, // "new-commit", "org-fork-new-commit" }, + // we have 2 branches with the same name in repo1 and repo58 + // and repo58's branch has a pr, but repo1's branch doesn't + // in this case, we should get repo1's branch but not repo58's branch { - name: "new branch of org fork repo", - actor: user39, - count: 1, - commitAfterUnix: 1489927690, - want: []string{"org-fork-new-commit"}, + name: "new branch from user fork repo and same name branch", + opts: &git_model.FindRecentlyPushedNewBranchesOptions{ + Actor: user40, + CommitAfterUnix: 1489927670, + ListOptions: db.ListOptions{ + PageSize: 10, + Page: 1, + }, + }, + count: 2, + want: []int64{14, 24}, // "user-fork-new-commit", "same-name-branch-in-pr" }, { - name: "new branch from user fork repo", - actor: user40, - count: 1, - commitAfterUnix: 1489927670, - want: []string{"user-fork-new-commit"}, + name: "new branch from private org with code permisstion repo", + opts: &git_model.FindRecentlyPushedNewBranchesOptions{ + Actor: user41, + CommitAfterUnix: 1489927670, + }, + count: 1, + want: []int64{20}, // "private-org-fork-new-commit" }, { - name: "new branch from private org with code permisstion repo", - actor: user41, - count: 1, - commitAfterUnix: 1489927670, - want: []string{"private-org-fork-new-commit"}, + name: "new branch from private org with no code permisstion repo", + opts: &git_model.FindRecentlyPushedNewBranchesOptions{ + Actor: user42, + CommitAfterUnix: 1489927670, + }, + count: 0, + want: []int64{}, }, { - name: "new branch from private org with no code permisstion repo", - actor: user42, - count: 0, - commitAfterUnix: 1489927670, - want: []string{"new-commit", "org-fork-new-commit"}, + name: "test commitAfterUnix option", + opts: &git_model.FindRecentlyPushedNewBranchesOptions{ + Actor: user39, + CommitAfterUnix: 1489927690, + }, + count: 1, + want: []int64{17}, // "org-fork-new-commit" }, } - opts := &git_model.FindRecentlyPushedNewBranchesOptions{ - Repo: repo, - BaseRepo: repo, - } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - opts.Actor = tt.actor - opts.CommitAfterUnix = tt.commitAfterUnix - branches, err := git_model.FindRecentlyPushedNewBranches(db.DefaultContext, opts) + tt.opts.Repo = repo + tt.opts.BaseRepo = repo + branches, err := git_model.FindRecentlyPushedNewBranches(db.DefaultContext, tt.opts) assert.NoError(t, err) assert.Equal(t, tt.count, len(branches)) for i := 1; i < tt.count; i++ { - assert.Equal(t, tt.want[i], branches[i].Name) + assert.Equal(t, tt.want[i], branches[i].ID) } }) } - - // TODO:test pr branch } From 5cf3d9e5051b245a6a703b66d76a83b28855ac1d Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 27 Jul 2023 02:14:50 +0000 Subject: [PATCH 36/97] fix TestIssue_DeleteIssue --- services/issue/issue_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/issue/issue_test.go b/services/issue/issue_test.go index 1f6a77096e8c9..20b4b7d3883c8 100644 --- a/services/issue/issue_test.go +++ b/services/issue/issue_test.go @@ -35,9 +35,10 @@ func TestGetRefEndNamesAndURLs(t *testing.T) { func TestIssue_DeleteIssue(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) + issueCount := 10 issueIDs, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1) assert.NoError(t, err) - assert.Len(t, issueIDs, 5) + assert.Len(t, issueIDs, issueCount) issue := &issues_model.Issue{ RepoID: 1, @@ -48,7 +49,7 @@ func TestIssue_DeleteIssue(t *testing.T) { assert.NoError(t, err) issueIDs, err = issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1) assert.NoError(t, err) - assert.Len(t, issueIDs, 4) + assert.Len(t, issueIDs, issueCount-1) // check attachment removal attachments, err := repo_model.GetAttachmentsByIssueID(db.DefaultContext, 4) From 64ece1cbe51789bb90b7fa76f4e43e45d5d5f98b Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 27 Jul 2023 02:19:12 +0000 Subject: [PATCH 37/97] fix TestTeam_AddRepository --- models/fixtures/repository.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 55737f1bdf046..8eee41532e12f 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -11,8 +11,8 @@ num_forks: 3 num_issues: 2 num_closed_issues: 1 - num_pulls: 3 - num_closed_pulls: 1 + num_pulls: 8 + num_closed_pulls: 2 num_milestones: 3 num_closed_milestones: 1 num_projects: 1 @@ -1674,7 +1674,7 @@ num_forks: 0 num_issues: 0 num_closed_issues: 0 - num_pulls: 0 + num_pulls: 1 num_closed_pulls: 0 num_milestones: 0 num_closed_milestones: 0 From fb3afac3e5b4d8aa3513c982aa601d508213e2df Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 27 Jul 2023 02:56:28 +0000 Subject: [PATCH 38/97] fix TestSearchIssues --- models/fixtures/issue.yml | 2 +- models/fixtures/pull_request.yml | 2 +- tests/integration/issue_test.go | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index 20f3a29d00ea1..d393c26634b5f 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -405,4 +405,4 @@ num_comments: 0 created_unix: 946684830 updated_unix: 978307200 - is_locked: false \ No newline at end of file + is_locked: false diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index 11e619a22637c..fc9f6ae7fe669 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -146,7 +146,7 @@ id: 12 type: 0 # gitea pull request status: 2 # mergable - issue_id: 25 + issue_id: 24 index: 1 head_repo_id: 58 base_repo_id: 1 diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index ab2986906bfd4..8f498ad674c4f 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -356,7 +356,7 @@ func TestSearchIssues(t *testing.T) { session := loginUser(t, "user2") - expectedIssueCount := 16 // from the fixtures + expectedIssueCount := 20 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } @@ -377,7 +377,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 9) + assert.Len(t, apiIssues, 13) query.Del("since") query.Del("before") @@ -386,22 +386,22 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 2) + assert.Len(t, apiIssues, 4) query.Set("state", "all") link.RawQuery = query.Encode() req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count")) - assert.Len(t, apiIssues, 18) + assert.EqualValues(t, "24", resp.Header().Get("X-Total-Count")) + assert.Len(t, apiIssues, 20) query.Add("limit", "5") link.RawQuery = query.Encode() req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "24", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 5) query = url.Values{"assigned": {"true"}, "state": {"all"}} @@ -430,7 +430,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 7) + assert.Len(t, apiIssues, 10) query = url.Values{"owner": {"user3"}} // organization link.RawQuery = query.Encode() From 9a9dd060b0b84a260732f306198d6ded2be6f910 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 27 Jul 2023 06:12:54 +0000 Subject: [PATCH 39/97] improve test --- models/fixtures/access.yml | 4 +- models/fixtures/branch.yml | 100 ++++++++++++++----------- models/fixtures/issue.yml | 22 +++--- models/fixtures/issue_index.yml | 6 +- models/fixtures/pull_request.yml | 34 ++++----- models/fixtures/repo_unit.yml | 4 +- models/fixtures/repository.yml | 47 ++++++++++-- models/fixtures/team_repo.yml | 4 +- models/fixtures/user.yml | 2 +- models/git/branch_test.go | 16 ++-- models/issues/issue_test.go | 2 +- routers/web/user/home_test.go | 2 +- services/issue/issue_test.go | 2 +- tests/integration/api_issue_test.go | 16 ++-- tests/integration/api_nodeinfo_test.go | 2 +- tests/integration/issue_test.go | 2 +- 16 files changed, 156 insertions(+), 109 deletions(-) diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index 676aecb282f87..f928de89a5a22 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -139,12 +139,12 @@ - id: 24 user_id: 40 - repo_id: 59 + repo_id: 60 mode: 4 - id: 25 user_id: 41 - repo_id: 60 + repo_id: 61 mode: 1 diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index 287ffdb8971c0..3fee47dc813a9 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -48,7 +48,19 @@ - id: 5 - repo_id: 1 + repo_id: 58 + name: 'master' + commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' + commit_message: 'Initial commit' + commit_time: 1489927679 + pusher_id: 39 + is_deleted: false + deleted_by_id: 0 + deleted_unix: 0 + +- + id: 6 + repo_id: 58 name: 'new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -59,8 +71,8 @@ deleted_unix: 0 - - id: 6 - repo_id: 1 + id: 7 + repo_id: 58 name: 'no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -71,8 +83,8 @@ deleted_unix: 0 - - id: 7 - repo_id: 1 + id: 8 + repo_id: 58 name: 'opening-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -83,8 +95,8 @@ deleted_unix: 0 - - id: 8 - repo_id: 1 + id: 9 + repo_id: 58 name: 'closed-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -95,8 +107,8 @@ deleted_unix: 0 - - id: 9 - repo_id: 1 + id: 10 + repo_id: 58 name: 'merged-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -107,8 +119,8 @@ deleted_unix: 0 - - id: 10 - repo_id: 1 + id: 11 + repo_id: 58 name: 'closed-pr-with-deleted-branch' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -119,8 +131,8 @@ deleted_unix: 1489927700 - - id: 11 - repo_id: 1 + id: 12 + repo_id: 58 name: 'merged-pr-with-deleted-branch' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -131,8 +143,8 @@ deleted_unix: 1489927700 - - id: 12 - repo_id: 1 + id: 13 + repo_id: 58 name: 'deleted-branch' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -143,20 +155,20 @@ deleted_unix: 1489927700 - - id: 13 - repo_id: 58 + id: 14 + repo_id: 59 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 1 + pusher_id: 40 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - - id: 14 - repo_id: 58 + id: 15 + repo_id: 59 name: 'user-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -167,8 +179,8 @@ deleted_unix: 0 - - id: 15 - repo_id: 58 + id: 16 + repo_id: 59 name: 'user-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -179,20 +191,20 @@ deleted_unix: 0 - - id: 16 - repo_id: 59 + id: 17 + repo_id: 60 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 1 + pusher_id: 39 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - - id: 17 - repo_id: 59 + id: 18 + repo_id: 60 name: 'org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -203,8 +215,8 @@ deleted_unix: 0 - - id: 18 - repo_id: 59 + id: 19 + repo_id: 60 name: 'org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -215,20 +227,20 @@ deleted_unix: 0 - - id: 19 - repo_id: 60 + id: 20 + repo_id: 61 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 1 + pusher_id: 41 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - - id: 20 - repo_id: 60 + id: 21 + repo_id: 61 name: 'private-org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -239,8 +251,8 @@ deleted_unix: 0 - - id: 21 - repo_id: 60 + id: 22 + repo_id: 61 name: 'private-org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -251,8 +263,8 @@ deleted_unix: 0 - - id: 22 - repo_id: 60 + id: 23 + repo_id: 61 name: 'private-org-fork-no-permission-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -263,8 +275,8 @@ deleted_unix: 0 - - id: 23 - repo_id: 60 + id: 24 + repo_id: 61 name: 'private-org-fork-no-permission-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -275,8 +287,8 @@ deleted_unix: 0 - - id: 24 - repo_id: 1 + id: 25 + repo_id: 58 name: 'same-name-branch-in-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -287,8 +299,8 @@ deleted_unix: 0 - - id: 25 - repo_id: 58 + id: 26 + repo_id: 59 name: 'same-name-branch-in-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index d393c26634b5f..f4fea2fe9fec8 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -307,8 +307,8 @@ - id: 19 - repo_id: 1 - index: 6 + repo_id: 58 + index: 1 poster_id: 39 original_author_id: 0 name: opening pr for recently new branch search test @@ -324,8 +324,8 @@ - id: 20 - repo_id: 1 - index: 7 + repo_id: 58 + index: 2 poster_id: 39 original_author_id: 0 name: closed pr for recently new branch search test @@ -341,8 +341,8 @@ - id: 21 - repo_id: 1 - index: 8 + repo_id: 58 + index: 3 poster_id: 39 original_author_id: 0 name: merged pr for recently new branch search test @@ -358,8 +358,8 @@ - id: 22 - repo_id: 1 - index: 9 + repo_id: 58 + index: 4 poster_id: 39 original_author_id: 0 name: closed pr with deleted branch for recently new branch search test @@ -375,8 +375,8 @@ - id: 23 - repo_id: 1 - index: 10 + repo_id: 58 + index: 5 poster_id: 39 original_author_id: 0 name: merged pr with deleted branch for recently new branch search test @@ -392,7 +392,7 @@ - id: 24 - repo_id: 58 + repo_id: 59 index: 1 poster_id: 40 original_author_id: 0 diff --git a/models/fixtures/issue_index.yml b/models/fixtures/issue_index.yml index 4ed80bc2bff6e..46f06d003c043 100644 --- a/models/fixtures/issue_index.yml +++ b/models/fixtures/issue_index.yml @@ -1,6 +1,6 @@ - group_id: 1 - max_index: 10 + max_index: 5 - group_id: 2 @@ -36,4 +36,8 @@ - group_id: 58 + max_index: 5 + +- + group_id: 59 max_index: 1 diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index fc9f6ae7fe669..9e54be69d3779 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -82,9 +82,9 @@ type: 0 # gitea pull request status: 2 # mergable issue_id: 19 - index: 4 - head_repo_id: 1 - base_repo_id: 1 + index: 1 + head_repo_id: 58 + base_repo_id: 58 head_branch: opening-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d @@ -95,9 +95,9 @@ type: 0 # gitea pull request status: 2 # mergable issue_id: 20 - index: 5 - head_repo_id: 1 - base_repo_id: 1 + index: 2 + head_repo_id: 58 + base_repo_id: 58 head_branch: closed-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d @@ -108,9 +108,9 @@ type: 0 # gitea pull request status: 3 # manually merged issue_id: 21 - index: 6 - head_repo_id: 1 - base_repo_id: 1 + index: 3 + head_repo_id: 58 + base_repo_id: 58 head_branch: merged-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d @@ -121,9 +121,9 @@ type: 0 # gitea pull request status: 2 # mergable issue_id: 22 - index: 7 - head_repo_id: 1 - base_repo_id: 1 + index: 4 + head_repo_id: 58 + base_repo_id: 58 head_branch: closed-pr-with-deleted-branch base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d @@ -134,9 +134,9 @@ type: 0 # gitea pull request status: 3 # manually merged issue_id: 23 - index: 8 - head_repo_id: 1 - base_repo_id: 1 + index: 5 + head_repo_id: 58 + base_repo_id: 58 head_branch: merged-pr-with-deleted-branch base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d @@ -148,8 +148,8 @@ status: 2 # mergable issue_id: 24 index: 1 - head_repo_id: 58 - base_repo_id: 1 + head_repo_id: 59 + base_repo_id: 58 head_branch: same-name-branch-in-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index ef27bde30d835..a7abf2aa6ecfd 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -610,12 +610,12 @@ - id: 91 - repo_id: 59 + repo_id: 60 type: 1 created_unix: 946684810 - id: 92 - repo_id: 60 + repo_id: 61 type: 1 created_unix: 946684810 diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 8eee41532e12f..e133a0e5d08d2 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -8,11 +8,11 @@ default_branch: master num_watches: 4 num_stars: 0 - num_forks: 3 + num_forks: 0 num_issues: 2 num_closed_issues: 1 - num_pulls: 8 - num_closed_pulls: 2 + num_pulls: 3 + num_closed_pulls: 0 num_milestones: 3 num_closed_milestones: 1 num_projects: 1 @@ -1665,6 +1665,37 @@ - id: 58 + owner_id: 2 + owner_name: user2 + lower_name: repo58 + name: repo58 + default_branch: master + num_watches: 0 + num_stars: 0 + num_forks: 3 + num_issues: 0 + num_closed_issues: 0 + num_pulls: 5 + num_closed_pulls: 2 + num_milestones: 0 + num_closed_milestones: 0 + num_projects: 0 + num_closed_projects: 0 + is_private: true + is_empty: false + is_archived: false + is_mirror: false + status: 0 + is_fork: false + fork_id: 0 + is_template: false + template_id: 0 + size: 0 + is_fsck_enabled: true + close_issues_via_commit_in_any_branch: false + +- + id: 59 owner_id: 40 owner_name: user40 lower_name: user_fork_repo @@ -1686,7 +1717,7 @@ is_mirror: false status: 0 is_fork: true - fork_id: 1 + fork_id: 58 is_template: false template_id: 0 size: 0 @@ -1694,7 +1725,7 @@ close_issues_via_commit_in_any_branch: false - - id: 59 + id: 60 owner_id: 37 owner_name: org37 lower_name: org_fork_repo1 @@ -1716,7 +1747,7 @@ is_mirror: false status: 0 is_fork: true - fork_id: 1 + fork_id: 58 is_template: false template_id: 0 size: 0 @@ -1724,7 +1755,7 @@ close_issues_via_commit_in_any_branch: false - - id: 60 + id: 61 owner_id: 38 owner_name: private_org38 lower_name: private_org_fork_repo1 @@ -1746,7 +1777,7 @@ is_mirror: false status: 0 is_fork: true - fork_id: 1 + fork_id: 58 is_template: false template_id: 0 size: 0 diff --git a/models/fixtures/team_repo.yml b/models/fixtures/team_repo.yml index 40064f3b1de63..ff8279536dd9e 100644 --- a/models/fixtures/team_repo.yml +++ b/models/fixtures/team_repo.yml @@ -68,10 +68,10 @@ id: 12 org_id: 38 team_id: 23 - repo_id: 60 + repo_id: 61 - id: 13 org_id: 38 team_id: 24 - repo_id: 60 + repo_id: 61 diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index a37e46f84f3bd..66627b7ab579e 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -66,7 +66,7 @@ num_followers: 2 num_following: 1 num_stars: 2 - num_repos: 13 + num_repos: 14 num_teams: 0 num_members: 0 visibility: 0 diff --git a/models/git/branch_test.go b/models/git/branch_test.go index 654b13c027a4c..65e50e83d2a79 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -188,7 +188,7 @@ func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) { func TestFindRecentlyPushedNewBranches(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 58}) user39 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 39}) user40 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 40}) user41 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 41}) @@ -213,11 +213,11 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { }, }, count: 2, - want: []int64{5, 17}, // "new-commit", "org-fork-new-commit" + want: []int64{6, 18}, // "new-commit", "org-fork-new-commit" }, - // we have 2 branches with the same name in repo1 and repo58 - // and repo58's branch has a pr, but repo1's branch doesn't - // in this case, we should get repo1's branch but not repo58's branch + // we have 2 branches with the same name in repo58 and repo59 + // and repo59's branch has a pr, but repo58's branch doesn't + // in this case, we should get repo58's branch but not repo59's branch { name: "new branch from user fork repo and same name branch", opts: &git_model.FindRecentlyPushedNewBranchesOptions{ @@ -229,7 +229,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { }, }, count: 2, - want: []int64{14, 24}, // "user-fork-new-commit", "same-name-branch-in-pr" + want: []int64{15, 25}, // "user-fork-new-commit", "same-name-branch-in-pr" }, { name: "new branch from private org with code permisstion repo", @@ -238,7 +238,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { CommitAfterUnix: 1489927670, }, count: 1, - want: []int64{20}, // "private-org-fork-new-commit" + want: []int64{21}, // "private-org-fork-new-commit" }, { name: "new branch from private org with no code permisstion repo", @@ -256,7 +256,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { CommitAfterUnix: 1489927690, }, count: 1, - want: []int64{17}, // "org-fork-new-commit" + want: []int64{18}, // "org-fork-new-commit" }, } diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go index 7f1eab1971378..784c7aa17cac8 100644 --- a/models/issues/issue_test.go +++ b/models/issues/issue_test.go @@ -538,7 +538,7 @@ func TestCountIssues(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) count, err := issues_model.CountIssues(db.DefaultContext, &issues_model.IssuesOptions{}) assert.NoError(t, err) - assert.EqualValues(t, 18, count) + assert.EqualValues(t, 24, count) } func TestIssueLoadAttributes(t *testing.T) { diff --git a/routers/web/user/home_test.go b/routers/web/user/home_test.go index 3a06a38c2450d..f931b3821faf5 100644 --- a/routers/web/user/home_test.go +++ b/routers/web/user/home_test.go @@ -75,7 +75,7 @@ func TestPulls(t *testing.T) { Pulls(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) - assert.Len(t, ctx.Data["Issues"], 4) + assert.Len(t, ctx.Data["Issues"], 7) } func TestMilestones(t *testing.T) { diff --git a/services/issue/issue_test.go b/services/issue/issue_test.go index 20b4b7d3883c8..fc33941acc809 100644 --- a/services/issue/issue_test.go +++ b/services/issue/issue_test.go @@ -35,7 +35,7 @@ func TestGetRefEndNamesAndURLs(t *testing.T) { func TestIssue_DeleteIssue(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - issueCount := 10 + issueCount := 5 issueIDs, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1) assert.NoError(t, err) assert.Len(t, issueIDs, issueCount) diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go index 8b02342d8805b..0eabd65c3250c 100644 --- a/tests/integration/api_issue_test.go +++ b/tests/integration/api_issue_test.go @@ -219,7 +219,7 @@ func TestAPISearchIssues(t *testing.T) { token := getUserToken(t, "user2", auth_model.AccessTokenScopeReadIssue) // as this API was used in the frontend, it uses UI page size - expectedIssueCount := 16 // from the fixtures + expectedIssueCount := 20 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } @@ -243,7 +243,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 9) + assert.Len(t, apiIssues, 13) query.Del("since") query.Del("before") @@ -252,22 +252,22 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 2) + assert.Len(t, apiIssues, 4) query.Set("state", "all") link.RawQuery = query.Encode() req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count")) - assert.Len(t, apiIssues, 18) + assert.EqualValues(t, "24", resp.Header().Get("X-Total-Count")) + assert.Len(t, apiIssues, 20) query.Add("limit", "10") link.RawQuery = query.Encode() req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "24", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 10) query = url.Values{"assigned": {"true"}, "state": {"all"}, "token": {token}} @@ -296,7 +296,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 7) + assert.Len(t, apiIssues, 10) query = url.Values{"owner": {"user3"}, "token": {token}} // organization link.RawQuery = query.Encode() @@ -317,7 +317,7 @@ func TestAPISearchIssuesWithLabels(t *testing.T) { defer tests.PrepareTestEnv(t)() // as this API was used in the frontend, it uses UI page size - expectedIssueCount := 16 // from the fixtures + expectedIssueCount := 21 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } diff --git a/tests/integration/api_nodeinfo_test.go b/tests/integration/api_nodeinfo_test.go index 1a579640abfa3..8ca3cf6e1aee5 100644 --- a/tests/integration/api_nodeinfo_test.go +++ b/tests/integration/api_nodeinfo_test.go @@ -33,7 +33,7 @@ func TestNodeinfo(t *testing.T) { assert.True(t, nodeinfo.OpenRegistrations) assert.Equal(t, "gitea", nodeinfo.Software.Name) assert.Equal(t, 29, nodeinfo.Usage.Users.Total) - assert.Equal(t, 18, nodeinfo.Usage.LocalPosts) + assert.Equal(t, 24, nodeinfo.Usage.LocalPosts) assert.Equal(t, 2, nodeinfo.Usage.LocalComments) }) } diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 8f498ad674c4f..50a1640872cec 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -450,7 +450,7 @@ func TestSearchIssues(t *testing.T) { func TestSearchIssuesWithLabels(t *testing.T) { defer tests.PrepareTestEnv(t)() - expectedIssueCount := 16 // from the fixtures + expectedIssueCount := 20 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } From dcc91fbb708b29434e8dafd9d57f436f15570d97 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 27 Jul 2023 06:14:59 +0000 Subject: [PATCH 40/97] fix --- models/git/branch_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/git/branch_test.go b/models/git/branch_test.go index 65e50e83d2a79..366aa63936dfc 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -201,7 +201,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { want []int64 }{ // user39 is the owner of the repo and the organization - // in repo 1, user39 has opening/closed/merged pr and closed/merged pr with deleted branch + // in repo58, user39 has opening/closed/merged pr and closed/merged pr with deleted branch { name: "new branch of the repo, org fork repo, pr branches and deleted branch", opts: &git_model.FindRecentlyPushedNewBranchesOptions{ From 4df1529e2eba4955bd5681520ab5acb46a27518f Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 31 Jul 2023 01:58:30 +0000 Subject: [PATCH 41/97] fix conflicts --- models/fixtures/branch.yml | 44 +++++++-------- models/fixtures/issue.yml | 37 ++++++++---- models/fixtures/pull_request.yml | 53 +++++++++++------- models/fixtures/repo_unit.yml | 32 ++++++++++- models/fixtures/repository.yml | 39 +++++++++++-- models/fixtures/team_repo.yml | 4 +- models/fixtures/team_unit.yml | 10 +++- models/fixtures/user.yml | 2 +- models/issues/issue_test.go | 2 +- models/repo/repo_list_test.go | 6 +- routers/web/user/home_test.go | 2 +- tests/integration/api_issue_test.go | 12 ++-- tests/integration/api_nodeinfo_test.go | 2 +- tests/integration/api_repo_test.go | 6 +- tests/integration/issue_test.go | 12 ++-- .../gitea-integration-sqlite/gitea.db-journal | Bin 0 -> 16928 bytes 16 files changed, 180 insertions(+), 83 deletions(-) create mode 100644 tests/integration/tests/integration/gitea-integration-sqlite/gitea.db-journal diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index 3fee47dc813a9..6db299496a602 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -48,7 +48,7 @@ - id: 5 - repo_id: 58 + repo_id: 59 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -60,7 +60,7 @@ - id: 6 - repo_id: 58 + repo_id: 59 name: 'new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -72,7 +72,7 @@ - id: 7 - repo_id: 58 + repo_id: 59 name: 'no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -84,7 +84,7 @@ - id: 8 - repo_id: 58 + repo_id: 59 name: 'opening-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -96,7 +96,7 @@ - id: 9 - repo_id: 58 + repo_id: 59 name: 'closed-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -108,7 +108,7 @@ - id: 10 - repo_id: 58 + repo_id: 59 name: 'merged-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -120,7 +120,7 @@ - id: 11 - repo_id: 58 + repo_id: 59 name: 'closed-pr-with-deleted-branch' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -132,7 +132,7 @@ - id: 12 - repo_id: 58 + repo_id: 59 name: 'merged-pr-with-deleted-branch' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -144,7 +144,7 @@ - id: 13 - repo_id: 58 + repo_id: 59 name: 'deleted-branch' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -156,7 +156,7 @@ - id: 14 - repo_id: 59 + repo_id: 60 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -168,7 +168,7 @@ - id: 15 - repo_id: 59 + repo_id: 60 name: 'user-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -180,7 +180,7 @@ - id: 16 - repo_id: 59 + repo_id: 60 name: 'user-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -192,7 +192,7 @@ - id: 17 - repo_id: 60 + repo_id: 61 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -204,7 +204,7 @@ - id: 18 - repo_id: 60 + repo_id: 61 name: 'org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -216,7 +216,7 @@ - id: 19 - repo_id: 60 + repo_id: 61 name: 'org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -228,7 +228,7 @@ - id: 20 - repo_id: 61 + repo_id: 62 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -240,7 +240,7 @@ - id: 21 - repo_id: 61 + repo_id: 62 name: 'private-org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -252,7 +252,7 @@ - id: 22 - repo_id: 61 + repo_id: 62 name: 'private-org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -264,7 +264,7 @@ - id: 23 - repo_id: 61 + repo_id: 62 name: 'private-org-fork-no-permission-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -276,7 +276,7 @@ - id: 24 - repo_id: 61 + repo_id: 62 name: 'private-org-fork-no-permission-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -288,7 +288,7 @@ - id: 25 - repo_id: 58 + repo_id: 59 name: 'same-name-branch-in-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -300,7 +300,7 @@ - id: 26 - repo_id: 59 + repo_id: 60 name: 'same-name-branch-in-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index f4fea2fe9fec8..f2242acd6017a 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -309,6 +309,23 @@ id: 19 repo_id: 58 index: 1 + poster_id: 2 + original_author_id: 0 + name: issue for pr + content: content + milestone_id: 0 + priority: 0 + is_closed: false + is_pull: true + num_comments: 0 + created_unix: 946684830 + updated_unix: 978307200 + is_locked: false + +- + id: 20 + repo_id: 59 + index: 1 poster_id: 39 original_author_id: 0 name: opening pr for recently new branch search test @@ -323,8 +340,8 @@ is_locked: false - - id: 20 - repo_id: 58 + id: 21 + repo_id: 59 index: 2 poster_id: 39 original_author_id: 0 @@ -340,8 +357,8 @@ is_locked: false - - id: 21 - repo_id: 58 + id: 22 + repo_id: 59 index: 3 poster_id: 39 original_author_id: 0 @@ -357,8 +374,8 @@ is_locked: false - - id: 22 - repo_id: 58 + id: 23 + repo_id: 59 index: 4 poster_id: 39 original_author_id: 0 @@ -374,8 +391,8 @@ is_locked: false - - id: 23 - repo_id: 58 + id: 24 + repo_id: 59 index: 5 poster_id: 39 original_author_id: 0 @@ -391,8 +408,8 @@ is_locked: false - - id: 24 - repo_id: 59 + id: 25 + repo_id: 60 index: 1 poster_id: 40 original_author_id: 0 diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index 9e54be69d3779..c4ad5f06bf8c1 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -85,71 +85,84 @@ index: 1 head_repo_id: 58 base_repo_id: 58 + head_branch: branch1 + base_branch: main + merge_base: cbff181af4c9c7fee3cf6c106699e07d9a3f54e6 + has_merged: false + +- + id: 8 + type: 0 # gitea pull request + status: 2 # mergable + issue_id: 20 + index: 1 + head_repo_id: 59 + base_repo_id: 59 head_branch: opening-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d has_merged: false - - id: 8 + id: 9 type: 0 # gitea pull request status: 2 # mergable - issue_id: 20 + issue_id: 21 index: 2 - head_repo_id: 58 - base_repo_id: 58 + head_repo_id: 59 + base_repo_id: 59 head_branch: closed-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d has_merged: false - - id: 9 + id: 10 type: 0 # gitea pull request status: 3 # manually merged - issue_id: 21 + issue_id: 22 index: 3 - head_repo_id: 58 - base_repo_id: 58 + head_repo_id: 59 + base_repo_id: 59 head_branch: merged-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d has_merged: true - - id: 10 + id: 11 type: 0 # gitea pull request status: 2 # mergable - issue_id: 22 + issue_id: 23 index: 4 - head_repo_id: 58 - base_repo_id: 58 + head_repo_id: 59 + base_repo_id: 59 head_branch: closed-pr-with-deleted-branch base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d has_merged: false - - id: 11 + id: 12 type: 0 # gitea pull request status: 3 # manually merged - issue_id: 23 + issue_id: 24 index: 5 - head_repo_id: 58 - base_repo_id: 58 + head_repo_id: 59 + base_repo_id: 59 head_branch: merged-pr-with-deleted-branch base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d has_merged: true - - id: 12 + id: 13 type: 0 # gitea pull request status: 2 # mergable - issue_id: 24 + issue_id: 25 index: 1 - head_repo_id: 59 - base_repo_id: 58 + head_repo_id: 60 + base_repo_id: 59 head_branch: same-name-branch-in-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index a7abf2aa6ecfd..01c31f50942d0 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -610,12 +610,42 @@ - id: 91 - repo_id: 60 + repo_id: 58 type: 1 created_unix: 946684810 - id: 92 + repo_id: 58 + type: 2 + created_unix: 946684810 + +- + id: 93 + repo_id: 58 + type: 3 + created_unix: 946684810 + +- + id: 94 + repo_id: 58 + type: 4 + created_unix: 946684810 + +- + id: 95 + repo_id: 58 + type: 5 + created_unix: 946684810 + +- + id: 96 + repo_id: 60 + type: 1 + created_unix: 946684810 + +- + id: 97 repo_id: 61 type: 1 created_unix: 946684810 diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index e133a0e5d08d2..348370b65d398 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -1664,7 +1664,38 @@ num_issues: 0 - - id: 58 + id: 58 # org public repo + owner_id: 2 + owner_name: user2 + lower_name: commitsonpr + name: commitsonpr + default_branch: main + num_watches: 0 + num_stars: 0 + num_forks: 0 + num_issues: 0 + num_closed_issues: 0 + num_pulls: 1 + num_closed_pulls: 0 + num_milestones: 0 + num_closed_milestones: 0 + num_projects: 0 + num_closed_projects: 0 + is_private: false + is_empty: false + is_archived: false + is_mirror: false + status: 0 + is_fork: false + fork_id: 0 + is_template: false + template_id: 0 + size: 0 + is_fsck_enabled: true + close_issues_via_commit_in_any_branch: false + +- + id: 59 owner_id: 2 owner_name: user2 lower_name: repo58 @@ -1695,7 +1726,7 @@ close_issues_via_commit_in_any_branch: false - - id: 59 + id: 60 owner_id: 40 owner_name: user40 lower_name: user_fork_repo @@ -1725,7 +1756,7 @@ close_issues_via_commit_in_any_branch: false - - id: 60 + id: 61 owner_id: 37 owner_name: org37 lower_name: org_fork_repo1 @@ -1755,7 +1786,7 @@ close_issues_via_commit_in_any_branch: false - - id: 61 + id: 62 owner_id: 38 owner_name: private_org38 lower_name: private_org_fork_repo1 diff --git a/models/fixtures/team_repo.yml b/models/fixtures/team_repo.yml index ff8279536dd9e..62919797e503f 100644 --- a/models/fixtures/team_repo.yml +++ b/models/fixtures/team_repo.yml @@ -68,10 +68,10 @@ id: 12 org_id: 38 team_id: 23 - repo_id: 61 + repo_id: 62 - id: 13 org_id: 38 team_id: 24 - repo_id: 61 + repo_id: 62 diff --git a/models/fixtures/team_unit.yml b/models/fixtures/team_unit.yml index 6521ca2d70725..9642daddf06a4 100644 --- a/models/fixtures/team_unit.yml +++ b/models/fixtures/team_unit.yml @@ -283,18 +283,24 @@ - id: 48 + team_id: 2 + type: 8 + access_mode: 2 + +- + id: 49 team_id: 21 type: 1 # code access_mode: 4 - - id: 49 + id: 50 team_id: 23 type: 1 # code access_mode: 1 - - id: 50 + id: 51 team_id: 24 type: 1 # code access_mode: 0 diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 66627b7ab579e..eb665e8514989 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -66,7 +66,7 @@ num_followers: 2 num_following: 1 num_stars: 2 - num_repos: 14 + num_repos: 15 num_teams: 0 num_members: 0 visibility: 0 diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go index 784c7aa17cac8..f3c8dabe2a707 100644 --- a/models/issues/issue_test.go +++ b/models/issues/issue_test.go @@ -538,7 +538,7 @@ func TestCountIssues(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) count, err := issues_model.CountIssues(db.DefaultContext, &issues_model.IssuesOptions{}) assert.NoError(t, err) - assert.EqualValues(t, 24, count) + assert.EqualValues(t, 25, count) } func TestIssueLoadAttributes(t *testing.T) { diff --git a/models/repo/repo_list_test.go b/models/repo/repo_list_test.go index a411b1c8f18b8..e70fdb18a4ca7 100644 --- a/models/repo/repo_list_test.go +++ b/models/repo/repo_list_test.go @@ -235,12 +235,12 @@ func TestSearchRepository(t *testing.T) { { name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse}, - count: 32, + count: 33, }, { name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse}, - count: 37, + count: 38, }, { name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName", @@ -255,7 +255,7 @@ func TestSearchRepository(t *testing.T) { { name: "AllPublic/PublicRepositoriesOfOrganization", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse}, - count: 32, + count: 33, }, { name: "AllTemplates", diff --git a/routers/web/user/home_test.go b/routers/web/user/home_test.go index f931b3821faf5..8674dd58511a5 100644 --- a/routers/web/user/home_test.go +++ b/routers/web/user/home_test.go @@ -75,7 +75,7 @@ func TestPulls(t *testing.T) { Pulls(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) - assert.Len(t, ctx.Data["Issues"], 7) + assert.Len(t, ctx.Data["Issues"], 8) } func TestMilestones(t *testing.T) { diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go index 0eabd65c3250c..fc75c529b2c91 100644 --- a/tests/integration/api_issue_test.go +++ b/tests/integration/api_issue_test.go @@ -219,7 +219,7 @@ func TestAPISearchIssues(t *testing.T) { token := getUserToken(t, "user2", auth_model.AccessTokenScopeReadIssue) // as this API was used in the frontend, it uses UI page size - expectedIssueCount := 20 // from the fixtures + expectedIssueCount := 21 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } @@ -243,7 +243,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 13) + assert.Len(t, apiIssues, 14) query.Del("since") query.Del("before") @@ -259,7 +259,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "24", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "25", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 20) query.Add("limit", "10") @@ -267,7 +267,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "24", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "25", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 10) query = url.Values{"assigned": {"true"}, "state": {"all"}, "token": {token}} @@ -296,7 +296,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 10) + assert.Len(t, apiIssues, 11) query = url.Values{"owner": {"user3"}, "token": {token}} // organization link.RawQuery = query.Encode() @@ -317,7 +317,7 @@ func TestAPISearchIssuesWithLabels(t *testing.T) { defer tests.PrepareTestEnv(t)() // as this API was used in the frontend, it uses UI page size - expectedIssueCount := 21 // from the fixtures + expectedIssueCount := 22 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } diff --git a/tests/integration/api_nodeinfo_test.go b/tests/integration/api_nodeinfo_test.go index 8ca3cf6e1aee5..dea24c01a0cc7 100644 --- a/tests/integration/api_nodeinfo_test.go +++ b/tests/integration/api_nodeinfo_test.go @@ -33,7 +33,7 @@ func TestNodeinfo(t *testing.T) { assert.True(t, nodeinfo.OpenRegistrations) assert.Equal(t, "gitea", nodeinfo.Software.Name) assert.Equal(t, 29, nodeinfo.Usage.Users.Total) - assert.Equal(t, 24, nodeinfo.Usage.LocalPosts) + assert.Equal(t, 25, nodeinfo.Usage.LocalPosts) assert.Equal(t, 2, nodeinfo.Usage.LocalComments) }) } diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go index 43fab43f5bbb3..ebbe007775310 100644 --- a/tests/integration/api_repo_test.go +++ b/tests/integration/api_repo_test.go @@ -93,9 +93,9 @@ func TestAPISearchRepo(t *testing.T) { }{ { name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{ - nil: {count: 34}, - user: {count: 34}, - user2: {count: 34}, + nil: {count: 35}, + user: {count: 35}, + user2: {count: 35}, }, }, { diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 50a1640872cec..c945be59903de 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -356,7 +356,7 @@ func TestSearchIssues(t *testing.T) { session := loginUser(t, "user2") - expectedIssueCount := 20 // from the fixtures + expectedIssueCount := 21 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } @@ -377,7 +377,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 13) + assert.Len(t, apiIssues, 14) query.Del("since") query.Del("before") @@ -393,7 +393,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "24", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "25", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 20) query.Add("limit", "5") @@ -401,7 +401,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "24", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "25", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 5) query = url.Values{"assigned": {"true"}, "state": {"all"}} @@ -430,7 +430,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 10) + assert.Len(t, apiIssues, 11) query = url.Values{"owner": {"user3"}} // organization link.RawQuery = query.Encode() @@ -450,7 +450,7 @@ func TestSearchIssues(t *testing.T) { func TestSearchIssuesWithLabels(t *testing.T) { defer tests.PrepareTestEnv(t)() - expectedIssueCount := 20 // from the fixtures + expectedIssueCount := 21 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } diff --git a/tests/integration/tests/integration/gitea-integration-sqlite/gitea.db-journal b/tests/integration/tests/integration/gitea-integration-sqlite/gitea.db-journal new file mode 100644 index 0000000000000000000000000000000000000000..b9364696f7256af69364875ad3072b183e7dec7a GIT binary patch literal 16928 zcmeHPYit|WmF93pqWBnI$+AVujw33zY|~cgc|Y2uj$Lb0Beonn^2XjG7~PqBq$ol;fUO@fioUk**EZRvX@H_=ffjviQ1nNUVt3QDc{FX&Zm_!z7P~+e=x$mR zMSJFw6o;1O(Ed}PWsF?jbMCq4@tt#DH0YncIPkmt=bV>gu^9K}p;x{ii!raoVsRjc z;s5@Be+39!NkNcXkPt%xx(nTl=Ft)|(4**G=>6yv`Yc*NUqKhpH_&DD1N2e!3i={? z9X*SlN54hCLT|vIN#H#X{nxWEWM9p`mi;dndE>7Dw|!%W`6~A@ zO7G)7N@ZKK)$!W9fyoo*qoSlzJjnOC3y& zB>ye>mE@zzW64{G{%7dhfA&)7JJ3g?ymXpQP#sef9Y=9R8*8>s2z*MCflVw(wjkKL zu4t|y$a3-0DLO&ZWycd_*Vc$bWQB;5?U^Dm3{`d=)$lak@FdTW+~TGC=>$Vp6jxFd zk*KQe2!bfMnk_4WD+{s*l!i4)$F5}Fe(7%qV#x=FG}RMrPtt8iwmn_&G(}T&O*J%G zC7LFf3UO`6R=~i?(7;e!6lBS^JyG{SziT?CYTK$J8g3Z6XE>%Q>4q){w_lnI4J3Ov za33|mN?6eytk{~UVAE5vB4gWjRqPt7h*bq^qUL#oXvIq>XvjT#RJ?SYTHqYrab?F9 z6@_T7Bs-?7d9o|$M3rpG5wWRi1d?DBi*%VjsImtxnxZI}vH{>| z7|>O9({qcLZ=)u9^{KeBml~LqF@{vjifP)OCnzSC!54){nyTumtjkbIifx#D z*bNx~dx|dTP=ksfI|>HS6i<{iY-^^dNZ3(LhZI)|)WQza5Co6thJ$TSfsU?tjwkDy zXX+l7us~cvGY#D?uI#233L4R&UOmHfp*~I9grGfHBbo@3rsU~Z)Fjo$LUCmmwJ_Cl zrdM`S3wwyC*@hTqT5t{UNYpVFJYDo`q8f^1J06T`re0i`q84_V0#O9Xkxg00iYA-7 zq zkhm>$!VTnMoVwKeR=l#ATDXBcj z$_8qo=b+y_^t1cmg23|W@5K(LpNXU2pw}~d(R1jV=nLqB=ps6gTy#G=gr?Cr;X^Kp%lV0(}Jf2=o!?BhW|SW)K*?i`~mCVdpG9L#%V8S}XY#Co>frPPUm| zsXTmuomv&L%f6i)J{aME1UctdHs8t0@hVyJty0A$7f98r1vseJxTitHY#Ej<5M|QCVkg4EBh{pyoXCb{4@T`(D z!8MZ2OtIU5fY>3;8-{m;NvxO40Ns1)q!u84JHWG4x638RI!hiJxefBRRP`SORIO62 zRwvxZWQ1k=xaxB0JXmN+ahVCQ;8)L3%r*|+3Ksk@dy;hq+zGgC+t~eWPRRGGrH66o zjpg_*iI3gFimSs*OW+3`j1O-GMHN3Nc`eRBY6~D2avZ{@#-YDhs#g8#0KXYfTZD=P zxGN+(nuGc-do^p31laQJFcdC121zc%x0_{zHnH0o8k$9O!(}%@7MhGO?JOEy6`(WH zqZ>eDQvla$r85;mYFu&zG*aedW|*BwhSh5YxOO&$z%|b=m;LkHNEWaoi?~#_uA~6df;vOMaC?luRYTQZwgfb_jyN zL4ciwP&|zi5JWTU)T@1?gKPm79tFNyuUHTIcI;U+z)nV(Y%axt%BEBrHkSb=y+2HK zbGL9(aXK0<-YqGH-I{D|A8#Id^%0O}?mK>@6p*~NAj8)^t*gW7C;jKA~5%z?R? z{M>sk!{UCk`JyaN>0So|)76*<*A0*^@_(Oy}oa9N_u< z!6U~GwmIa&QmG2F4$scb+&y!GvJ1D559SVRWny##t-YrV_*t+@d`iP^LcOuXR%c5i zolE5InPM6;6*zq8loefU7VfMd*ao9Rn_HnAo;@^kDnI`gGw1WiX7lsW`C-uA+UE=B z#uB+Z!I|8(ouNB&w->p$@S-*4+UDDXg+_i;B6kc7pQeUS9-rw(feJ>Pjm9z7^5Ep` z;o~P~AQ=>nw^VU`kEYi^v%GI(A~!X~JT^(oD(XSBzp1;xqC+9zCAU*9(K>0Q*~{Kx{3^{F#-nEMMr6?SRKD!2}rfWKQ!|<2TmTD%ZpLvH3yE@R@JvA zR^aY%6${R69Kc}&N7#jq!j^n}3D(6m2MY~tG?BCRGmUp&T}^9G4eJ~(mqHUksocVB ztmN3X8NwUgV-2VN{V@$Lv*J@qY!wuK0*R=|6s(9&r;o9X1&Np}4)q-`2|2Yw9zy=|&5@jbdkbWc`xt2w71b z-Kp&eg#dTSfq$q6|DvmNt$)Kk`4`o3J^#Ao3XOO+kvjnROj*#$)(Y;nWo_8&-7Q03u|G`x={EAm< zz35u#bdHGjnKO3+&gICN7G12htMuLES>vY@Idzh0Y+9{?<|Tar*A^_=?a-NZGv1MD z&S_@3!wsRQ)O;aGCUTQtP^O9Ph;(|X?nHJ5LM@?Rt;nO-fCxxUJFPsl?gIrmHJH15 za=puC$Al$z`sv2VP$GA@z%=e$1*iLM+kWGQ@5SzsedQ~bK6yQ!gW9J>c^YB5AT=_>U00Gt{1tCmLVVbm$^_PNz8*fsptR^H7o zEDk1eZy#qGqpLe+^Z6ToFS2@#YO)foup`&|YsfaiZVrT4MD+m5dj}G^@o{EZq$oGV zn(bgWsvQl{%Ve}P*S(lDJ+q9VJ-$2(?H$W+gLdcg4rsH>;XmK-yT-%N{<`5o`;*3LXrFByg!ais5!%a* fF=*@IQ{OrZ&C&2L|J87O+cY${ Date: Mon, 31 Jul 2023 08:59:43 +0000 Subject: [PATCH 42/97] fix test --- models/fixtures/repository.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 348370b65d398..10311b910728e 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -1748,7 +1748,7 @@ is_mirror: false status: 0 is_fork: true - fork_id: 58 + fork_id: 59 is_template: false template_id: 0 size: 0 @@ -1778,7 +1778,7 @@ is_mirror: false status: 0 is_fork: true - fork_id: 58 + fork_id: 59 is_template: false template_id: 0 size: 0 @@ -1808,7 +1808,7 @@ is_mirror: false status: 0 is_fork: true - fork_id: 58 + fork_id: 59 is_template: false template_id: 0 size: 0 From 08b0159874a6e70e33fa13004f89e31eda585c7c Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 31 Jul 2023 23:47:25 +0000 Subject: [PATCH 43/97] fix test --- models/fixtures/access.yml | 4 ++-- models/git/branch_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index f928de89a5a22..791c65b6cb0d5 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -139,12 +139,12 @@ - id: 24 user_id: 40 - repo_id: 60 + repo_id: 61 mode: 4 - id: 25 user_id: 41 - repo_id: 61 + repo_id: 62 mode: 1 diff --git a/models/git/branch_test.go b/models/git/branch_test.go index 366aa63936dfc..55e696e66eec5 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -188,7 +188,7 @@ func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) { func TestFindRecentlyPushedNewBranches(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 58}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 59}) user39 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 39}) user40 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 40}) user41 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 41}) From d7cb37c8bae723a7fd3687107bd9d6a17eb485fb Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 1 Aug 2023 01:28:15 +0000 Subject: [PATCH 44/97] improve --- models/fixtures/repository.yml | 16 +++++----- models/git/branch.go | 32 +++++++++++++++++-- models/git/branch_test.go | 23 ++++++------- routers/web/repo/view.go | 7 +--- .../code/recently_pushed_new_branches.tmpl | 16 ++-------- 5 files changed, 52 insertions(+), 42 deletions(-) diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 10311b910728e..c69fe2d7f2d45 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -1698,8 +1698,8 @@ id: 59 owner_id: 2 owner_name: user2 - lower_name: repo58 - name: repo58 + lower_name: repo59 + name: repo59 default_branch: master num_watches: 0 num_stars: 0 @@ -1729,8 +1729,8 @@ id: 60 owner_id: 40 owner_name: user40 - lower_name: user_fork_repo - name: user_fork_repo + lower_name: user_fork_repo60 + name: user_fork_repo60 num_watches: 0 num_stars: 0 num_forks: 0 @@ -1759,8 +1759,8 @@ id: 61 owner_id: 37 owner_name: org37 - lower_name: org_fork_repo1 - name: org_fork_repo1 + lower_name: org_fork_repo61 + name: org_fork_repo61 num_watches: 0 num_stars: 0 num_forks: 0 @@ -1789,8 +1789,8 @@ id: 62 owner_id: 38 owner_name: private_org38 - lower_name: private_org_fork_repo1 - name: private_org_fork_repo1 + lower_name: private_org_fork_repo62 + name: private_org_fork_repo62 num_watches: 0 num_stars: 0 num_forks: 0 diff --git a/models/git/branch.go b/models/git/branch.go index 722904bd287b1..f3ca2e085b284 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -401,11 +401,17 @@ type FindRecentlyPushedNewBranchesOptions struct { CommitAfterUnix int64 } +type RecentlyPushedNewBranch struct { + BranchName string + BranchCompareURL string + UpdatedUnix timeutil.TimeStamp +} + // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created // opts.Actor should not be nil // if opts.CommitAfterUnix is 0, we will find the branches committed in recently 6 hours // if opts.ListOptions is not set, we will only display top 2 latest branch -func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushedNewBranchesOptions) (BranchList, error) { +func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushedNewBranchesOptions) ([]*RecentlyPushedNewBranch, error) { // find all related repo ids repoOpts := repo_model.SearchRepoOptions{ Actor: opts.Actor, @@ -418,7 +424,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed } repoCond := repo_model.SearchRepositoryCondition(&repoOpts).And(repo_model.AccessibleRepositoryCondition(opts.Actor, unit.TypeCode)) if opts.Repo == opts.BaseRepo { - // should also include the brase repo's branches + // should also include the base repo's branches repoCond = repoCond.Or(builder.Eq{"id": opts.BaseRepo.ID}) } else { // in fork repo, we only detect the fork repo's branch @@ -462,5 +468,25 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed ListOptions: opts.ListOptions, } - return FindBranches(ctx, findBranchOpts) + branches, err := FindBranches(ctx, findBranchOpts) + if err != nil { + return nil, err + } + if err := branches.LoadRepo(ctx); err != nil { + return nil, err + } + + newBranches := make([]*RecentlyPushedNewBranch, 0, len(branches)) + for _, branch := range branches { + branchName := branch.Name + if branch.Repo.ID != opts.BaseRepo.ID && branch.Repo.ID != opts.Repo.ID { + branchName = fmt.Sprintf("%s:%s", branch.Repo.FullName(), branchName) + } + newBranches = append(newBranches, &RecentlyPushedNewBranch{ + BranchName: branchName, + BranchCompareURL: branch.Repo.ComposeBranchCompareURL(opts.BaseRepo, branch.Name), + UpdatedUnix: branch.UpdatedUnix, + }) + } + return newBranches, nil } diff --git a/models/git/branch_test.go b/models/git/branch_test.go index 55e696e66eec5..39c07f919bf67 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -198,7 +198,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { name string opts *git_model.FindRecentlyPushedNewBranchesOptions count int - want []int64 + want []string }{ // user39 is the owner of the repo and the organization // in repo58, user39 has opening/closed/merged pr and closed/merged pr with deleted branch @@ -213,11 +213,11 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { }, }, count: 2, - want: []int64{6, 18}, // "new-commit", "org-fork-new-commit" + want: []string{"new-commit", "org37/org_fork_repo61:org-fork-new-commit"}, }, - // we have 2 branches with the same name in repo58 and repo59 - // and repo59's branch has a pr, but repo58's branch doesn't - // in this case, we should get repo58's branch but not repo59's branch + // we have 2 branches with the same name in repo59 and repo60 + // and repo60's branch has a pr, but repo59's branch doesn't + // in this case, we should get repo59's branch but not repo60's branch { name: "new branch from user fork repo and same name branch", opts: &git_model.FindRecentlyPushedNewBranchesOptions{ @@ -229,7 +229,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { }, }, count: 2, - want: []int64{15, 25}, // "user-fork-new-commit", "same-name-branch-in-pr" + want: []string{"user40/user_fork_repo60:user-fork-new-commit", "same-name-branch-in-pr"}, }, { name: "new branch from private org with code permisstion repo", @@ -238,7 +238,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { CommitAfterUnix: 1489927670, }, count: 1, - want: []int64{21}, // "private-org-fork-new-commit" + want: []string{"private_org38/private_org_fork_repo62:private-org-fork-new-commit"}, }, { name: "new branch from private org with no code permisstion repo", @@ -247,7 +247,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { CommitAfterUnix: 1489927670, }, count: 0, - want: []int64{}, + want: []string{}, }, { name: "test commitAfterUnix option", @@ -256,7 +256,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { CommitAfterUnix: 1489927690, }, count: 1, - want: []int64{18}, // "org-fork-new-commit" + want: []string{"org37/org_fork_repo61:org-fork-new-commit"}, }, } @@ -265,11 +265,12 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { tt.opts.Repo = repo tt.opts.BaseRepo = repo branches, err := git_model.FindRecentlyPushedNewBranches(db.DefaultContext, tt.opts) + assert.NoError(t, err) assert.Equal(t, tt.count, len(branches)) - for i := 1; i < tt.count; i++ { - assert.Equal(t, tt.want[i], branches[i].ID) + for i := 0; i < tt.count; i++ { + assert.Equal(t, tt.want[i], branches[i].BranchName) } }) } diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 258aa94dd9aba..2e3ec67ed1561 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -991,16 +991,11 @@ func renderCode(ctx *context.Context) { if ctx.Repo.Repository.IsFork { opts.BaseRepo = ctx.Repo.Repository.BaseRepo } - branches, err := git_model.FindRecentlyPushedNewBranches(ctx, opts) + ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, opts) if err != nil { ctx.ServerError("FindRecentlyPushedNewBranches", err) return } - if err := branches.LoadRepo(ctx); err != nil { - ctx.ServerError("branches.LoadRepo", err) - return - } - ctx.Data["RecentlyPushedNewBranches"] = branches } var treeNames []string diff --git a/templates/repo/code/recently_pushed_new_branches.tmpl b/templates/repo/code/recently_pushed_new_branches.tmpl index 177dc5ee8e141..e83c2e517e00f 100644 --- a/templates/repo/code/recently_pushed_new_branches.tmpl +++ b/templates/repo/code/recently_pushed_new_branches.tmpl @@ -1,22 +1,10 @@ {{range .RecentlyPushedNewBranches}} - {{$pullRepo := $.Repository}} - {{$baseRepo := $.Repository}} - {{$branchName := .Name}} - {{if .Repo}} - {{$pullRepo = .Repo}} - {{if and $.Repository.IsFork}} - {{$baseRepo = $.Repository.BaseRepo}} - {{end}} - {{if not (eq .Repo.ID $.Repository.ID)}} - {{$branchName = (print .Repo.FullName ":" .Name)}} - {{end}} - {{end}}
{{$timeSince := TimeSince .UpdatedUnix.AsTime $.locale}} - {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" $branchName $timeSince | Safe}} + {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" .BranchName $timeSince | Safe}}
- + {{$.locale.Tr "repo.pulls.compare_changes"}}
From aa2b8c48552486b0902a2f2ccac144954527e922 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 15 Aug 2023 00:16:42 +0000 Subject: [PATCH 45/97] fix conflicts --- models/fixtures/repo_unit.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index 01c31f50942d0..fe8a119973d9e 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -640,12 +640,24 @@ - id: 96 - repo_id: 60 + repo_id: 49 type: 1 created_unix: 946684810 - id: 97 + repo_id: 49 + type: 2 + created_unix: 946684810 + +- + id: 98 + repo_id: 60 + type: 1 + created_unix: 946684810 + +- + id: 99 repo_id: 61 type: 1 created_unix: 946684810 From 5bfa11ba03c3f30a41ceedaa0bc9605363bc2aaa Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 15 Aug 2023 00:43:35 +0000 Subject: [PATCH 46/97] follow 26257 --- routers/web/repo/view.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 2e3ec67ed1561..04ce891e484f5 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -991,10 +991,14 @@ func renderCode(ctx *context.Context) { if ctx.Repo.Repository.IsFork { opts.BaseRepo = ctx.Repo.Repository.BaseRepo } - ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, opts) - if err != nil { - ctx.ServerError("FindRecentlyPushedNewBranches", err) - return + + if !opts.Repo.IsMirror && !opts.BaseRepo.IsMirror && + opts.BaseRepo.UnitEnabled(ctx, unit_model.TypePullRequests) { + ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, opts) + if err != nil { + ctx.ServerError("FindRecentlyPushedNewBranches", err) + return + } } } From 2e93f87122dd388325cac5dddc09e4bd9afed2ed Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 15 Aug 2023 00:50:58 +0000 Subject: [PATCH 47/97] follow 26257 --- models/git/branch.go | 4 ++-- templates/repo/code/recently_pushed_new_branches.tmpl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index f3ca2e085b284..81e146105c97c 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -404,7 +404,7 @@ type FindRecentlyPushedNewBranchesOptions struct { type RecentlyPushedNewBranch struct { BranchName string BranchCompareURL string - UpdatedUnix timeutil.TimeStamp + CommitTime timeutil.TimeStamp } // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created @@ -485,7 +485,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed newBranches = append(newBranches, &RecentlyPushedNewBranch{ BranchName: branchName, BranchCompareURL: branch.Repo.ComposeBranchCompareURL(opts.BaseRepo, branch.Name), - UpdatedUnix: branch.UpdatedUnix, + CommitTime: branch.CommitTime, }) } return newBranches, nil diff --git a/templates/repo/code/recently_pushed_new_branches.tmpl b/templates/repo/code/recently_pushed_new_branches.tmpl index a58edbeb7b15d..318dee1d939ad 100644 --- a/templates/repo/code/recently_pushed_new_branches.tmpl +++ b/templates/repo/code/recently_pushed_new_branches.tmpl @@ -2,7 +2,7 @@
{{$timeSince := TimeSince .CommitTime.AsTime $.locale}} - {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" (PathEscapeSegments .Name) $timeSince | Safe}} + {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" .BranchName $timeSince | Safe}}
{{$.locale.Tr "repo.pulls.compare_changes"}} From 6248701203c27cf21459bc3022f9a3ca297d782a Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 15 Aug 2023 01:11:39 +0000 Subject: [PATCH 48/97] add permission check --- routers/web/repo/view.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 50d7434ffec55..33eac1e92b2b6 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -27,6 +27,7 @@ import ( "code.gitea.io/gitea/models/db" git_model "code.gitea.io/gitea/models/git" issue_model "code.gitea.io/gitea/models/issues" + access_model "code.gitea.io/gitea/models/perm/access" repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" @@ -1009,8 +1010,15 @@ func renderCode(ctx *context.Context) { opts.BaseRepo = ctx.Repo.Repository.BaseRepo } + baseRepoPerm, err := access_model.GetUserRepoPermission(ctx, opts.BaseRepo, ctx.Doer) + if err != nil { + ctx.ServerError("GetUserRepoPermission", err) + return + } + if !opts.Repo.IsMirror && !opts.BaseRepo.IsMirror && - opts.BaseRepo.UnitEnabled(ctx, unit_model.TypePullRequests) { + opts.BaseRepo.UnitEnabled(ctx, unit_model.TypePullRequests) && + baseRepoPerm.CanRead(unit_model.TypePullRequests) { ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, opts) if err != nil { ctx.ServerError("FindRecentlyPushedNewBranches", err) From 44c80aed1500cc8c46546258628f3a8869b6128d Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 22 Aug 2023 23:50:50 +0000 Subject: [PATCH 49/97] remove unnecessary file --- .../gitea-integration-sqlite/gitea.db-journal | Bin 16928 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/integration/tests/integration/gitea-integration-sqlite/gitea.db-journal diff --git a/tests/integration/tests/integration/gitea-integration-sqlite/gitea.db-journal b/tests/integration/tests/integration/gitea-integration-sqlite/gitea.db-journal deleted file mode 100644 index b9364696f7256af69364875ad3072b183e7dec7a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16928 zcmeHPYit|WmF93pqWBnI$+AVujw33zY|~cgc|Y2uj$Lb0Beonn^2XjG7~PqBq$ol;fUO@fioUk**EZRvX@H_=ffjviQ1nNUVt3QDc{FX&Zm_!z7P~+e=x$mR zMSJFw6o;1O(Ed}PWsF?jbMCq4@tt#DH0YncIPkmt=bV>gu^9K}p;x{ii!raoVsRjc z;s5@Be+39!NkNcXkPt%xx(nTl=Ft)|(4**G=>6yv`Yc*NUqKhpH_&DD1N2e!3i={? z9X*SlN54hCLT|vIN#H#X{nxWEWM9p`mi;dndE>7Dw|!%W`6~A@ zO7G)7N@ZKK)$!W9fyoo*qoSlzJjnOC3y& zB>ye>mE@zzW64{G{%7dhfA&)7JJ3g?ymXpQP#sef9Y=9R8*8>s2z*MCflVw(wjkKL zu4t|y$a3-0DLO&ZWycd_*Vc$bWQB;5?U^Dm3{`d=)$lak@FdTW+~TGC=>$Vp6jxFd zk*KQe2!bfMnk_4WD+{s*l!i4)$F5}Fe(7%qV#x=FG}RMrPtt8iwmn_&G(}T&O*J%G zC7LFf3UO`6R=~i?(7;e!6lBS^JyG{SziT?CYTK$J8g3Z6XE>%Q>4q){w_lnI4J3Ov za33|mN?6eytk{~UVAE5vB4gWjRqPt7h*bq^qUL#oXvIq>XvjT#RJ?SYTHqYrab?F9 z6@_T7Bs-?7d9o|$M3rpG5wWRi1d?DBi*%VjsImtxnxZI}vH{>| z7|>O9({qcLZ=)u9^{KeBml~LqF@{vjifP)OCnzSC!54){nyTumtjkbIifx#D z*bNx~dx|dTP=ksfI|>HS6i<{iY-^^dNZ3(LhZI)|)WQza5Co6thJ$TSfsU?tjwkDy zXX+l7us~cvGY#D?uI#233L4R&UOmHfp*~I9grGfHBbo@3rsU~Z)Fjo$LUCmmwJ_Cl zrdM`S3wwyC*@hTqT5t{UNYpVFJYDo`q8f^1J06T`re0i`q84_V0#O9Xkxg00iYA-7 zq zkhm>$!VTnMoVwKeR=l#ATDXBcj z$_8qo=b+y_^t1cmg23|W@5K(LpNXU2pw}~d(R1jV=nLqB=ps6gTy#G=gr?Cr;X^Kp%lV0(}Jf2=o!?BhW|SW)K*?i`~mCVdpG9L#%V8S}XY#Co>frPPUm| zsXTmuomv&L%f6i)J{aME1UctdHs8t0@hVyJty0A$7f98r1vseJxTitHY#Ej<5M|QCVkg4EBh{pyoXCb{4@T`(D z!8MZ2OtIU5fY>3;8-{m;NvxO40Ns1)q!u84JHWG4x638RI!hiJxefBRRP`SORIO62 zRwvxZWQ1k=xaxB0JXmN+ahVCQ;8)L3%r*|+3Ksk@dy;hq+zGgC+t~eWPRRGGrH66o zjpg_*iI3gFimSs*OW+3`j1O-GMHN3Nc`eRBY6~D2avZ{@#-YDhs#g8#0KXYfTZD=P zxGN+(nuGc-do^p31laQJFcdC121zc%x0_{zHnH0o8k$9O!(}%@7MhGO?JOEy6`(WH zqZ>eDQvla$r85;mYFu&zG*aedW|*BwhSh5YxOO&$z%|b=m;LkHNEWaoi?~#_uA~6df;vOMaC?luRYTQZwgfb_jyN zL4ciwP&|zi5JWTU)T@1?gKPm79tFNyuUHTIcI;U+z)nV(Y%axt%BEBrHkSb=y+2HK zbGL9(aXK0<-YqGH-I{D|A8#Id^%0O}?mK>@6p*~NAj8)^t*gW7C;jKA~5%z?R? z{M>sk!{UCk`JyaN>0So|)76*<*A0*^@_(Oy}oa9N_u< z!6U~GwmIa&QmG2F4$scb+&y!GvJ1D559SVRWny##t-YrV_*t+@d`iP^LcOuXR%c5i zolE5InPM6;6*zq8loefU7VfMd*ao9Rn_HnAo;@^kDnI`gGw1WiX7lsW`C-uA+UE=B z#uB+Z!I|8(ouNB&w->p$@S-*4+UDDXg+_i;B6kc7pQeUS9-rw(feJ>Pjm9z7^5Ep` z;o~P~AQ=>nw^VU`kEYi^v%GI(A~!X~JT^(oD(XSBzp1;xqC+9zCAU*9(K>0Q*~{Kx{3^{F#-nEMMr6?SRKD!2}rfWKQ!|<2TmTD%ZpLvH3yE@R@JvA zR^aY%6${R69Kc}&N7#jq!j^n}3D(6m2MY~tG?BCRGmUp&T}^9G4eJ~(mqHUksocVB ztmN3X8NwUgV-2VN{V@$Lv*J@qY!wuK0*R=|6s(9&r;o9X1&Np}4)q-`2|2Yw9zy=|&5@jbdkbWc`xt2w71b z-Kp&eg#dTSfq$q6|DvmNt$)Kk`4`o3J^#Ao3XOO+kvjnROj*#$)(Y;nWo_8&-7Q03u|G`x={EAm< zz35u#bdHGjnKO3+&gICN7G12htMuLES>vY@Idzh0Y+9{?<|Tar*A^_=?a-NZGv1MD z&S_@3!wsRQ)O;aGCUTQtP^O9Ph;(|X?nHJ5LM@?Rt;nO-fCxxUJFPsl?gIrmHJH15 za=puC$Al$z`sv2VP$GA@z%=e$1*iLM+kWGQ@5SzsedQ~bK6yQ!gW9J>c^YB5AT=_>U00Gt{1tCmLVVbm$^_PNz8*fsptR^H7o zEDk1eZy#qGqpLe+^Z6ToFS2@#YO)foup`&|YsfaiZVrT4MD+m5dj}G^@o{EZq$oGV zn(bgWsvQl{%Ve}P*S(lDJ+q9VJ-$2(?H$W+gLdcg4rsH>;XmK-yT-%N{<`5o`;*3LXrFByg!ais5!%a* fF=*@IQ{OrZ&C&2L|J87O+cY${ Date: Mon, 28 Aug 2023 01:26:18 +0000 Subject: [PATCH 50/97] remove test repo meta data --- .../2a/e4cd61145dbece4166c20a7f683e41d5ee5a8b | Bin 55 -> 0 bytes .../96/cac303b24be71685d77202689de5a751b972d3 | Bin 54 -> 0 bytes .../cb/24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d | Bin 148 -> 0 bytes .../user2/repo1.git/refs/heads/new-commit | 1 - .../user2/repo1.git/refs/heads/no-commit | 1 - 5 files changed, 2 deletions(-) delete mode 100644 tests/gitea-repositories-meta/user2/repo1.git/objects/2a/e4cd61145dbece4166c20a7f683e41d5ee5a8b delete mode 100644 tests/gitea-repositories-meta/user2/repo1.git/objects/96/cac303b24be71685d77202689de5a751b972d3 delete mode 100644 tests/gitea-repositories-meta/user2/repo1.git/objects/cb/24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d delete mode 100644 tests/gitea-repositories-meta/user2/repo1.git/refs/heads/new-commit delete mode 100644 tests/gitea-repositories-meta/user2/repo1.git/refs/heads/no-commit diff --git a/tests/gitea-repositories-meta/user2/repo1.git/objects/2a/e4cd61145dbece4166c20a7f683e41d5ee5a8b b/tests/gitea-repositories-meta/user2/repo1.git/objects/2a/e4cd61145dbece4166c20a7f683e41d5ee5a8b deleted file mode 100644 index f3271266444f56b0b43aa0ff66b009188f4c0421..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 55 zcmV-70LcG%0ZYosPf{?kU{F>lN-fAYZaql`QKEzwcVg K%wW2O|04hjX%!Rz diff --git a/tests/gitea-repositories-meta/user2/repo1.git/objects/cb/24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d b/tests/gitea-repositories-meta/user2/repo1.git/objects/cb/24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d deleted file mode 100644 index 5f318261228bae266b08c7819b1fe880ca9603b5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 148 zcmV;F0Biqv0hNwB4gxU@1*vn2^hn70*iNJs7omz1M^G&LQ7E`QxdQFejONvCU0=g` zh?jAy+Dx_706}~dWk(4cvj Date: Mon, 28 Aug 2023 04:48:12 +0000 Subject: [PATCH 51/97] rewrite test --- models/fixtures/access.yml | 68 +++---- models/fixtures/branch.yml | 94 +++++----- models/fixtures/issue.yml | 34 ++-- models/fixtures/issue_index.yml | 10 +- models/fixtures/org_user.yml | 14 +- models/fixtures/pull_request.yml | 34 ++-- models/fixtures/repo_unit.yml | 4 +- models/fixtures/repository.yml | 95 ++-------- models/fixtures/team.yml | 36 +--- models/fixtures/team_repo.yml | 12 +- models/fixtures/team_unit.yml | 8 +- models/fixtures/team_user.yml | 16 +- models/fixtures/user.yml | 236 +----------------------- models/git/branch_test.go | 44 ++--- models/organization/org_user_test.go | 6 +- models/repo/repo_list_test.go | 6 +- models/user/user_test.go | 6 +- routers/web/user/home_test.go | 2 +- tests/integration/api_issue_test.go | 4 +- tests/integration/api_nodeinfo_test.go | 2 +- tests/integration/api_org_test.go | 4 +- tests/integration/api_repo_test.go | 10 +- tests/integration/api_user_orgs_test.go | 26 +++ tests/integration/issue_test.go | 2 +- 24 files changed, 247 insertions(+), 526 deletions(-) diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index 791c65b6cb0d5..0389b51b7d2c8 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -1,150 +1,150 @@ - id: 1 + user_id: 1 + repo_id: 60 + mode: 4 + +- + id: 2 user_id: 2 repo_id: 3 mode: 4 - - id: 2 + id: 3 user_id: 2 repo_id: 5 mode: 4 - - id: 3 + id: 4 user_id: 2 repo_id: 24 mode: 2 - - id: 4 + id: 5 user_id: 2 repo_id: 32 mode: 4 - - id: 5 + id: 6 user_id: 4 repo_id: 3 mode: 2 - - id: 6 + id: 7 user_id: 4 repo_id: 4 mode: 2 - - id: 7 + id: 8 user_id: 4 repo_id: 40 mode: 2 - - id: 8 + id: 9 + user_id: 12 + repo_id: 59 + mode: 4 + +- + id: 10 user_id: 15 repo_id: 21 mode: 2 - - id: 9 + id: 11 user_id: 15 repo_id: 22 mode: 2 - - id: 10 + id: 12 user_id: 15 repo_id: 23 mode: 4 - - id: 11 + id: 13 user_id: 15 repo_id: 24 mode: 4 - - id: 12 + id: 14 user_id: 15 repo_id: 32 mode: 2 - - id: 13 + id: 15 user_id: 18 repo_id: 21 mode: 2 - - id: 14 + id: 16 user_id: 18 repo_id: 22 mode: 2 - - id: 15 + id: 17 user_id: 18 repo_id: 23 mode: 4 - - id: 16 + id: 18 user_id: 18 repo_id: 24 mode: 4 - - id: 17 + id: 19 user_id: 20 repo_id: 24 mode: 1 - - id: 18 + id: 20 user_id: 20 repo_id: 27 mode: 4 - - id: 19 + id: 21 user_id: 20 repo_id: 28 mode: 4 - - id: 20 + id: 22 user_id: 29 repo_id: 4 mode: 2 - - id: 21 + id: 23 user_id: 29 repo_id: 24 mode: 1 - - id: 22 + id: 24 user_id: 31 repo_id: 27 mode: 4 - - id: 23 + id: 25 user_id: 31 repo_id: 28 mode: 4 -- - id: 24 - user_id: 40 - repo_id: 61 - mode: 4 - -- - id: 25 - user_id: 41 - repo_id: 62 - mode: 1 - diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index 6db299496a602..f4b13a173761a 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -48,264 +48,264 @@ - id: 5 - repo_id: 59 + repo_id: 10 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 39 + pusher_id: 12 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 6 - repo_id: 59 + repo_id: 10 name: 'new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927680 - pusher_id: 39 + pusher_id: 12 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 7 - repo_id: 59 + repo_id: 10 name: 'no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 39 + pusher_id: 12 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 8 - repo_id: 59 + repo_id: 10 name: 'opening-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927680 - pusher_id: 39 + pusher_id: 12 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 9 - repo_id: 59 + repo_id: 10 name: 'closed-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927680 - pusher_id: 39 + pusher_id: 12 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 10 - repo_id: 59 + repo_id: 10 name: 'merged-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927680 - pusher_id: 39 + pusher_id: 12 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 11 - repo_id: 59 + repo_id: 10 name: 'closed-pr-with-deleted-branch' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927680 - pusher_id: 39 + pusher_id: 12 is_deleted: true - deleted_by_id: 39 + deleted_by_id: 12 deleted_unix: 1489927700 - id: 12 - repo_id: 59 + repo_id: 10 name: 'merged-pr-with-deleted-branch' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927680 - pusher_id: 39 + pusher_id: 12 is_deleted: true - deleted_by_id: 39 + deleted_by_id: 12 deleted_unix: 1489927700 - id: 13 - repo_id: 59 + repo_id: 10 name: 'deleted-branch' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927680 - pusher_id: 39 + pusher_id: 12 is_deleted: true - deleted_by_id: 39 + deleted_by_id: 12 deleted_unix: 1489927700 - id: 14 - repo_id: 60 + repo_id: 11 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 40 + pusher_id: 13 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 15 - repo_id: 60 + repo_id: 11 name: 'user-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927680 - pusher_id: 40 + pusher_id: 13 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 16 - repo_id: 60 + repo_id: 11 name: 'user-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 40 + pusher_id: 13 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 17 - repo_id: 61 + repo_id: 59 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 39 + pusher_id: 12 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 18 - repo_id: 61 + repo_id: 59 name: 'org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927691 - pusher_id: 39 + pusher_id: 12 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 19 - repo_id: 61 + repo_id: 59 name: 'org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927691 - pusher_id: 39 + pusher_id: 12 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 20 - repo_id: 62 + repo_id: 60 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 41 + pusher_id: 1 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 21 - repo_id: 62 + repo_id: 60 name: 'private-org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927680 - pusher_id: 41 + pusher_id: 1 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 22 - repo_id: 62 + repo_id: 60 name: 'private-org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 41 + pusher_id: 1 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 23 - repo_id: 62 + repo_id: 60 name: 'private-org-fork-no-permission-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927680 - pusher_id: 42 + pusher_id: 2 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 24 - repo_id: 62 + repo_id: 60 name: 'private-org-fork-no-permission-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' commit_time: 1489927679 - pusher_id: 42 + pusher_id: 2 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 25 - repo_id: 59 + repo_id: 10 name: 'same-name-branch-in-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927680 - pusher_id: 40 + pusher_id: 13 is_deleted: false deleted_by_id: 0 deleted_unix: 0 - id: 26 - repo_id: 60 + repo_id: 11 name: 'same-name-branch-in-pr' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' commit_time: 1489927680 - pusher_id: 40 + pusher_id: 13 is_deleted: false deleted_by_id: 0 deleted_unix: 0 diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index f2242acd6017a..07ec722bbb9d3 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -324,9 +324,9 @@ - id: 20 - repo_id: 59 - index: 1 - poster_id: 39 + repo_id: 10 + index: 2 + poster_id: 12 original_author_id: 0 name: opening pr for recently new branch search test content: content @@ -341,9 +341,9 @@ - id: 21 - repo_id: 59 - index: 2 - poster_id: 39 + repo_id: 10 + index: 3 + poster_id: 12 original_author_id: 0 name: closed pr for recently new branch search test content: content @@ -358,9 +358,9 @@ - id: 22 - repo_id: 59 - index: 3 - poster_id: 39 + repo_id: 10 + index: 4 + poster_id: 12 original_author_id: 0 name: merged pr for recently new branch search test content: content @@ -375,9 +375,9 @@ - id: 23 - repo_id: 59 - index: 4 - poster_id: 39 + repo_id: 10 + index: 5 + poster_id: 12 original_author_id: 0 name: closed pr with deleted branch for recently new branch search test content: content @@ -392,9 +392,9 @@ - id: 24 - repo_id: 59 - index: 5 - poster_id: 39 + repo_id: 10 + index: 6 + poster_id: 12 original_author_id: 0 name: merged pr with deleted branch for recently new branch search test content: content @@ -409,9 +409,9 @@ - id: 25 - repo_id: 60 + repo_id: 11 index: 1 - poster_id: 40 + poster_id: 13 original_author_id: 0 name: pr with same branch name for recently new branch search test content: content diff --git a/models/fixtures/issue_index.yml b/models/fixtures/issue_index.yml index 46f06d003c043..27d2be824235f 100644 --- a/models/fixtures/issue_index.yml +++ b/models/fixtures/issue_index.yml @@ -12,7 +12,7 @@ - group_id: 10 - max_index: 1 + max_index: 6 - group_id: 32 @@ -33,11 +33,3 @@ - group_id: 51 max_index: 1 - -- - group_id: 58 - max_index: 5 - -- - group_id: 59 - max_index: 1 diff --git a/models/fixtures/org_user.yml b/models/fixtures/org_user.yml index 8505744ed6ea1..7886d1581493b 100644 --- a/models/fixtures/org_user.yml +++ b/models/fixtures/org_user.yml @@ -102,7 +102,7 @@ - id: 18 - uid: 39 + uid: 12 org_id: 37 is_public: false @@ -117,3 +117,15 @@ uid: 42 org_id: 38 is_public: false + +- + id: 21 + uid: 12 + org_id: 25 + is_public: true + +- + id: 22 + uid: 2 + org_id: 35 + is_public: true diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index c4ad5f06bf8c1..6909e4a01ddc3 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -95,9 +95,9 @@ type: 0 # gitea pull request status: 2 # mergable issue_id: 20 - index: 1 - head_repo_id: 59 - base_repo_id: 59 + index: 2 + head_repo_id: 10 + base_repo_id: 10 head_branch: opening-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d @@ -108,9 +108,9 @@ type: 0 # gitea pull request status: 2 # mergable issue_id: 21 - index: 2 - head_repo_id: 59 - base_repo_id: 59 + index: 3 + head_repo_id: 10 + base_repo_id: 10 head_branch: closed-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d @@ -121,9 +121,9 @@ type: 0 # gitea pull request status: 3 # manually merged issue_id: 22 - index: 3 - head_repo_id: 59 - base_repo_id: 59 + index: 4 + head_repo_id: 10 + base_repo_id: 10 head_branch: merged-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d @@ -134,9 +134,9 @@ type: 0 # gitea pull request status: 2 # mergable issue_id: 23 - index: 4 - head_repo_id: 59 - base_repo_id: 59 + index: 5 + head_repo_id: 10 + base_repo_id: 10 head_branch: closed-pr-with-deleted-branch base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d @@ -147,9 +147,9 @@ type: 0 # gitea pull request status: 3 # manually merged issue_id: 24 - index: 5 - head_repo_id: 59 - base_repo_id: 59 + index: 6 + head_repo_id: 10 + base_repo_id: 10 head_branch: merged-pr-with-deleted-branch base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d @@ -161,8 +161,8 @@ status: 2 # mergable issue_id: 25 index: 1 - head_repo_id: 60 - base_repo_id: 59 + head_repo_id: 11 + base_repo_id: 10 head_branch: same-name-branch-in-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index fe8a119973d9e..93cfd8a975e40 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -652,12 +652,12 @@ - id: 98 - repo_id: 60 + repo_id: 59 type: 1 created_unix: 946684810 - id: 99 - repo_id: 61 + repo_id: 60 type: 1 created_unix: 946684810 diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index c69fe2d7f2d45..b8a860e8f4a3a 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -26,7 +26,7 @@ fork_id: 0 is_template: false template_id: 0 - size: 7659 + size: 7320 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false @@ -282,11 +282,11 @@ default_branch: master num_watches: 0 num_stars: 0 - num_forks: 1 + num_forks: 3 num_issues: 0 num_closed_issues: 0 - num_pulls: 1 - num_closed_pulls: 0 + num_pulls: 6 + num_closed_pulls: 2 num_milestones: 1 num_closed_milestones: 0 num_projects: 0 @@ -316,7 +316,7 @@ num_forks: 0 num_issues: 0 num_closed_issues: 0 - num_pulls: 0 + num_pulls: 1 num_closed_pulls: 0 num_milestones: 0 num_closed_milestones: 0 @@ -327,7 +327,7 @@ is_archived: false is_mirror: false status: 0 - is_fork: false + is_fork: true fork_id: 10 is_template: false template_id: 0 @@ -1696,71 +1696,10 @@ - id: 59 - owner_id: 2 - owner_name: user2 - lower_name: repo59 - name: repo59 - default_branch: master - num_watches: 0 - num_stars: 0 - num_forks: 3 - num_issues: 0 - num_closed_issues: 0 - num_pulls: 5 - num_closed_pulls: 2 - num_milestones: 0 - num_closed_milestones: 0 - num_projects: 0 - num_closed_projects: 0 - is_private: true - is_empty: false - is_archived: false - is_mirror: false - status: 0 - is_fork: false - fork_id: 0 - is_template: false - template_id: 0 - size: 0 - is_fsck_enabled: true - close_issues_via_commit_in_any_branch: false - -- - id: 60 - owner_id: 40 - owner_name: user40 - lower_name: user_fork_repo60 - name: user_fork_repo60 - num_watches: 0 - num_stars: 0 - num_forks: 0 - num_issues: 0 - num_closed_issues: 0 - num_pulls: 1 - num_closed_pulls: 0 - num_milestones: 0 - num_closed_milestones: 0 - num_projects: 0 - num_closed_projects: 0 - is_private: false - is_empty: false - is_archived: false - is_mirror: false - status: 0 - is_fork: true - fork_id: 59 - is_template: false - template_id: 0 - size: 0 - is_fsck_enabled: true - close_issues_via_commit_in_any_branch: false - -- - id: 61 - owner_id: 37 - owner_name: org37 - lower_name: org_fork_repo61 - name: org_fork_repo61 + owner_id: 25 + owner_name: org25 + lower_name: org_fork_repo59 + name: org_fork_repo59 num_watches: 0 num_stars: 0 num_forks: 0 @@ -1778,7 +1717,7 @@ is_mirror: false status: 0 is_fork: true - fork_id: 59 + fork_id: 10 is_template: false template_id: 0 size: 0 @@ -1786,11 +1725,11 @@ close_issues_via_commit_in_any_branch: false - - id: 62 - owner_id: 38 - owner_name: private_org38 - lower_name: private_org_fork_repo62 - name: private_org_fork_repo62 + id: 60 + owner_id: 35 + owner_name: private_org35 + lower_name: private_org_fork_repo60 + name: private_org_fork_repo60 num_watches: 0 num_stars: 0 num_forks: 0 @@ -1808,7 +1747,7 @@ is_mirror: false status: 0 is_fork: true - fork_id: 59 + fork_id: 10 is_template: false template_id: 0 size: 0 diff --git a/models/fixtures/team.yml b/models/fixtures/team.yml index 2d5b430cda4a9..3be2bedcab152 100644 --- a/models/fixtures/team.yml +++ b/models/fixtures/team.yml @@ -191,7 +191,7 @@ lower_name: owners name: Owners authorize: 4 # owner - num_repos: 0 + num_repos: 1 num_members: 1 includes_all_repositories: false can_create_org_repo: true @@ -220,10 +220,10 @@ - id: 21 - org_id: 37 + org_id: 25 lower_name: owners name: Owners - authorize: 4 # owner + authorize: 4 # read num_repos: 0 num_members: 1 includes_all_repositories: false @@ -231,33 +231,11 @@ - id: 22 - org_id: 38 - lower_name: owners - name: Owners - authorize: 4 # owner - num_repos: 0 - num_members: 0 - includes_all_repositories: false - can_create_org_repo: true - -- - id: 23 - org_id: 38 - lower_name: team23readcode - name: team23readcode - authorize: 1 # read - num_repos: 1 - num_members: 1 - includes_all_repositories: false - can_create_org_repo: true - -- - id: 24 - org_id: 38 - lower_name: team24noreadcode - name: team24noreadcode + org_id: 35 + lower_name: team22noreadcode + name: team22noreadcode authorize: 0 # no access num_repos: 1 num_members: 1 includes_all_repositories: false - can_create_org_repo: true + can_create_org_repo: false diff --git a/models/fixtures/team_repo.yml b/models/fixtures/team_repo.yml index 62919797e503f..a745b3f6ccf74 100644 --- a/models/fixtures/team_repo.yml +++ b/models/fixtures/team_repo.yml @@ -66,12 +66,12 @@ - id: 12 - org_id: 38 - team_id: 23 - repo_id: 62 + org_id: 35 + team_id: 18 + repo_id: 60 - id: 13 - org_id: 38 - team_id: 24 - repo_id: 62 + org_id: 35 + team_id: 22 + repo_id: 60 diff --git a/models/fixtures/team_unit.yml b/models/fixtures/team_unit.yml index 9642daddf06a4..911b4d3f9a364 100644 --- a/models/fixtures/team_unit.yml +++ b/models/fixtures/team_unit.yml @@ -289,18 +289,18 @@ - id: 49 - team_id: 21 + team_id: 18 type: 1 # code access_mode: 4 - id: 50 - team_id: 23 + team_id: 21 type: 1 # code - access_mode: 1 + access_mode: 4 - id: 51 - team_id: 24 + team_id: 22 type: 1 # code access_mode: 0 diff --git a/models/fixtures/team_user.yml b/models/fixtures/team_user.yml index ab6b87c0779d3..db9f342044cbb 100644 --- a/models/fixtures/team_user.yml +++ b/models/fixtures/team_user.yml @@ -126,18 +126,12 @@ - id: 22 - org_id: 37 + org_id: 25 team_id: 21 - uid: 40 + uid: 12 - id: 23 - org_id: 38 - team_id: 23 - uid: 41 - -- - id: 24 - org_id: 38 - team_id: 24 - uid: 42 + org_id: 35 + team_id: 22 + uid: 2 diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index eb665e8514989..459b45ec8a922 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -66,7 +66,7 @@ num_followers: 2 num_following: 1 num_stars: 2 - num_repos: 15 + num_repos: 14 num_teams: 0 num_members: 0 visibility: 0 @@ -917,9 +917,9 @@ num_followers: 0 num_following: 0 num_stars: 0 - num_repos: 0 - num_teams: 1 - num_members: 1 + num_repos: 1 + num_teams: 2 + num_members: 2 visibility: 0 repo_admin_change_team_access: false theme: "" @@ -1288,9 +1288,9 @@ num_followers: 0 num_following: 0 num_stars: 0 - num_repos: 0 - num_teams: 1 - num_members: 1 + num_repos: 1 + num_teams: 2 + num_members: 2 visibility: 2 repo_admin_change_team_access: false theme: "" @@ -1332,225 +1332,3 @@ repo_admin_change_team_access: false theme: "" keep_activity_private: false - -- - id: 37 - lower_name: org37 - name: org37 - full_name: Org 37 - email: org37@example.com - keep_email_private: false - email_notifications_preference: enabled - passwd: ZogKvWdyEx:password - passwd_hash_algo: dummy - must_change_password: false - login_source: 0 - login_name: org37 - type: 1 - salt: ZogKvWdyEx - max_repo_creation: -1 - is_active: true - is_admin: false - is_restricted: false - allow_git_hook: false - allow_import_local: false - allow_create_organization: true - prohibit_login: false - avatar: avatar37 - avatar_email: org37@example.com - use_custom_avatar: false - num_followers: 0 - num_following: 0 - num_stars: 0 - num_repos: 1 - num_teams: 1 - num_members: 1 - visibility: 0 - repo_admin_change_team_access: false - theme: "" - keep_activity_private: false - -- - id: 38 - lower_name: private_org38 - name: private_org38 - full_name: Private Org 38 - email: private_org38@example.com - keep_email_private: false - email_notifications_preference: enabled - passwd: ZogKvWdyEx:password - passwd_hash_algo: dummy - must_change_password: false - login_source: 0 - login_name: private_org38 - type: 1 - salt: ZogKvWdyEx - max_repo_creation: -1 - is_active: true - is_admin: false - is_restricted: false - allow_git_hook: false - allow_import_local: false - allow_create_organization: true - prohibit_login: false - avatar: avatar38 - avatar_email: private_org38@example.com - use_custom_avatar: false - num_followers: 0 - num_following: 0 - num_stars: 0 - num_repos: 1 - num_teams: 3 - num_members: 2 - visibility: 2 - repo_admin_change_team_access: false - theme: "" - keep_activity_private: false - -- - id: 39 - lower_name: user39 - name: user39 - full_name: user39 - email: user39@example.com - keep_email_private: true - email_notifications_preference: enabled - passwd: ZogKvWdyEx:password - passwd_hash_algo: dummy - must_change_password: false - login_source: 0 - login_name: user39 - type: 0 - salt: ZogKvWdyEx - max_repo_creation: -1 - is_active: true - is_admin: false - is_restricted: false - allow_git_hook: false - allow_import_local: false - allow_create_organization: true - prohibit_login: false - avatar: avatar39 - avatar_email: user39@example.com - use_custom_avatar: false - num_followers: 0 - num_following: 0 - num_stars: 0 - num_repos: 0 - num_teams: 0 - num_members: 0 - visibility: 0 - repo_admin_change_team_access: false - theme: "" - keep_activity_private: false - -- - id: 40 - lower_name: user40 - name: user40 - full_name: user40 - email: user40@example.com - keep_email_private: true - email_notifications_preference: enabled - passwd: ZogKvWdyEx:password - passwd_hash_algo: dummy - must_change_password: false - login_source: 0 - login_name: user40 - type: 0 - salt: ZogKvWdyEx - max_repo_creation: -1 - is_active: true - is_admin: false - is_restricted: false - allow_git_hook: false - allow_import_local: false - allow_create_organization: true - prohibit_login: false - avatar: avatar40 - avatar_email: user40@example.com - use_custom_avatar: false - num_followers: 0 - num_following: 0 - num_stars: 0 - num_repos: 1 - num_teams: 0 - num_members: 0 - visibility: 0 - repo_admin_change_team_access: false - theme: "" - keep_activity_private: false - -- - id: 41 - lower_name: user41 - name: user41 - full_name: user41 - email: user41@example.com - keep_email_private: true - email_notifications_preference: enabled - passwd: ZogKvWdyEx:password - passwd_hash_algo: dummy - must_change_password: false - login_source: 0 - login_name: user41 - type: 0 - salt: ZogKvWdyEx - max_repo_creation: -1 - is_active: true - is_admin: false - is_restricted: false - allow_git_hook: false - allow_import_local: false - allow_create_organization: true - prohibit_login: false - avatar: avatar41 - avatar_email: user41@example.com - use_custom_avatar: false - num_followers: 0 - num_following: 0 - num_stars: 0 - num_repos: 0 - num_teams: 0 - num_members: 0 - visibility: 0 - repo_admin_change_team_access: false - theme: "" - keep_activity_private: false - -- - id: 42 - lower_name: user42 - name: user42 - full_name: user42 - email: user42@example.com - keep_email_private: true - email_notifications_preference: enabled - passwd: ZogKvWdyEx:password - passwd_hash_algo: dummy - must_change_password: false - login_source: 0 - login_name: user42 - type: 0 - salt: ZogKvWdyEx - max_repo_creation: -1 - is_active: true - is_admin: false - is_restricted: false - allow_git_hook: false - allow_import_local: false - allow_create_organization: true - prohibit_login: false - avatar: avatar42 - avatar_email: user42@example.com - use_custom_avatar: false - num_followers: 0 - num_following: 0 - num_stars: 0 - num_repos: 0 - num_teams: 0 - num_members: 0 - visibility: 0 - repo_admin_change_team_access: false - theme: "" - keep_activity_private: false diff --git a/models/git/branch_test.go b/models/git/branch_test.go index 39c07f919bf67..79887cdddcb5f 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -188,11 +188,11 @@ func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) { func TestFindRecentlyPushedNewBranches(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 59}) - user39 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 39}) - user40 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 40}) - user41 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 41}) - user42 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 42}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10}) + user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) + user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + user12 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 12}) + user13 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 13}) tests := []struct { name string @@ -200,12 +200,12 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { count int want []string }{ - // user39 is the owner of the repo and the organization - // in repo58, user39 has opening/closed/merged pr and closed/merged pr with deleted branch + // user12 is the owner of the repo10 and the organization org25 + // in repo10, user12 has opening/closed/merged pr and closed/merged pr with deleted branch { name: "new branch of the repo, org fork repo, pr branches and deleted branch", opts: &git_model.FindRecentlyPushedNewBranchesOptions{ - Actor: user39, + Actor: user12, CommitAfterUnix: 1489927670, ListOptions: db.ListOptions{ PageSize: 10, @@ -213,15 +213,15 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { }, }, count: 2, - want: []string{"new-commit", "org37/org_fork_repo61:org-fork-new-commit"}, + want: []string{"new-commit", "org25/org_fork_repo59:org-fork-new-commit"}, }, - // we have 2 branches with the same name in repo59 and repo60 - // and repo60's branch has a pr, but repo59's branch doesn't - // in this case, we should get repo59's branch but not repo60's branch + // user13 pushed 2 branches with the same name in repo10 and repo11 + // and repo11's branch has a pr, but repo10's branch doesn't + // in this case, we should get repo10's branch but not repo11's branch { name: "new branch from user fork repo and same name branch", opts: &git_model.FindRecentlyPushedNewBranchesOptions{ - Actor: user40, + Actor: user13, CommitAfterUnix: 1489927670, ListOptions: db.ListOptions{ PageSize: 10, @@ -229,21 +229,23 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { }, }, count: 2, - want: []string{"user40/user_fork_repo60:user-fork-new-commit", "same-name-branch-in-pr"}, + want: []string{"user13/repo11:user-fork-new-commit", "same-name-branch-in-pr"}, }, + // user1 is the owner of private_org35 { - name: "new branch from private org with code permisstion repo", + name: "new branch from private org with code permission repo", opts: &git_model.FindRecentlyPushedNewBranchesOptions{ - Actor: user41, + Actor: user1, CommitAfterUnix: 1489927670, }, count: 1, - want: []string{"private_org38/private_org_fork_repo62:private-org-fork-new-commit"}, + want: []string{"private_org35/private_org_fork_repo60:private-org-fork-new-commit"}, }, + // user2 does not have code permission in private_org35 { - name: "new branch from private org with no code permisstion repo", + name: "new branch from private org with no code permission repo", opts: &git_model.FindRecentlyPushedNewBranchesOptions{ - Actor: user42, + Actor: user2, CommitAfterUnix: 1489927670, }, count: 0, @@ -252,11 +254,11 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { { name: "test commitAfterUnix option", opts: &git_model.FindRecentlyPushedNewBranchesOptions{ - Actor: user39, + Actor: user12, CommitAfterUnix: 1489927690, }, count: 1, - want: []string{"org37/org_fork_repo61:org-fork-new-commit"}, + want: []string{"org25/org_fork_repo59:org-fork-new-commit"}, }, } diff --git a/models/organization/org_user_test.go b/models/organization/org_user_test.go index b6477f859c795..b4fc0cd5d4826 100644 --- a/models/organization/org_user_test.go +++ b/models/organization/org_user_test.go @@ -81,7 +81,7 @@ func TestUserListIsPublicMember(t *testing.T) { {3, map[int64]bool{2: true, 4: false, 28: true}}, {6, map[int64]bool{5: true, 28: true}}, {7, map[int64]bool{5: false}}, - {25, map[int64]bool{24: true}}, + {25, map[int64]bool{12: true, 24: true}}, {22, map[int64]bool{}}, } for _, v := range tt { @@ -108,8 +108,8 @@ func TestUserListIsUserOrgOwner(t *testing.T) { {3, map[int64]bool{2: true, 4: false, 28: false}}, {6, map[int64]bool{5: true, 28: false}}, {7, map[int64]bool{5: true}}, - {25, map[int64]bool{24: false}}, // ErrTeamNotExist - {22, map[int64]bool{}}, // No member + {25, map[int64]bool{12: true, 24: false}}, // ErrTeamNotExist + {22, map[int64]bool{}}, // No member } for _, v := range tt { t.Run(fmt.Sprintf("IsUserOrgOwnerOfOrgId%d", v.orgid), func(t *testing.T) { diff --git a/models/repo/repo_list_test.go b/models/repo/repo_list_test.go index f4b8ac1bc69cd..3be1ebb3c95cb 100644 --- a/models/repo/repo_list_test.go +++ b/models/repo/repo_list_test.go @@ -138,12 +138,12 @@ func getTestCases() []struct { { name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse}, - count: 33, + count: 32, }, { name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse}, - count: 38, + count: 37, }, { name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName", @@ -158,7 +158,7 @@ func getTestCases() []struct { { name: "AllPublic/PublicRepositoriesOfOrganization", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse}, - count: 33, + count: 32, }, { name: "AllTemplates", diff --git a/models/user/user_test.go b/models/user/user_test.go index 6b66f0623d9ab..44eaf63556baa 100644 --- a/models/user/user_test.go +++ b/models/user/user_test.go @@ -89,7 +89,7 @@ func TestSearchUsers(t *testing.T) { []int64{19, 25}) testOrgSuccess(&user_model.SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 4, PageSize: 2}}, - []int64{26, 37}) + []int64{26}) testOrgSuccess(&user_model.SearchUserOptions{ListOptions: db.ListOptions{Page: 5, PageSize: 2}}, []int64{}) @@ -101,13 +101,13 @@ func TestSearchUsers(t *testing.T) { } testUserSuccess(&user_model.SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}}, - []int64{1, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32, 34, 39, 40, 41, 42}) + []int64{1, 2, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32, 34}) testUserSuccess(&user_model.SearchUserOptions{ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolFalse}, []int64{9}) testUserSuccess(&user_model.SearchUserOptions{OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolTrue}, - []int64{1, 2, 4, 5, 8, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32, 34, 39, 40, 41, 42}) + []int64{1, 2, 4, 5, 8, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 24, 27, 28, 29, 30, 32, 34}) testUserSuccess(&user_model.SearchUserOptions{Keyword: "user1", OrderBy: "id ASC", ListOptions: db.ListOptions{Page: 1}, IsActive: util.OptionalBoolTrue}, []int64{1, 10, 11, 12, 13, 14, 15, 16, 18}) diff --git a/routers/web/user/home_test.go b/routers/web/user/home_test.go index 8674dd58511a5..634a91545e9cf 100644 --- a/routers/web/user/home_test.go +++ b/routers/web/user/home_test.go @@ -75,7 +75,7 @@ func TestPulls(t *testing.T) { Pulls(ctx) assert.EqualValues(t, http.StatusOK, ctx.Resp.Status()) - assert.Len(t, ctx.Data["Issues"], 8) + assert.Len(t, ctx.Data["Issues"], 5) } func TestMilestones(t *testing.T) { diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go index fc75c529b2c91..713edee2cbe4f 100644 --- a/tests/integration/api_issue_test.go +++ b/tests/integration/api_issue_test.go @@ -296,7 +296,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 11) + assert.Len(t, apiIssues, 8) query = url.Values{"owner": {"user3"}, "token": {token}} // organization link.RawQuery = query.Encode() @@ -317,7 +317,7 @@ func TestAPISearchIssuesWithLabels(t *testing.T) { defer tests.PrepareTestEnv(t)() // as this API was used in the frontend, it uses UI page size - expectedIssueCount := 22 // from the fixtures + expectedIssueCount := 21 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } diff --git a/tests/integration/api_nodeinfo_test.go b/tests/integration/api_nodeinfo_test.go index d8a1f369030d5..29efcba5f106d 100644 --- a/tests/integration/api_nodeinfo_test.go +++ b/tests/integration/api_nodeinfo_test.go @@ -32,7 +32,7 @@ func TestNodeinfo(t *testing.T) { DecodeJSON(t, resp, &nodeinfo) assert.True(t, nodeinfo.OpenRegistrations) assert.Equal(t, "gitea", nodeinfo.Software.Name) - assert.Equal(t, 29, nodeinfo.Usage.Users.Total) + assert.Equal(t, 25, nodeinfo.Usage.Users.Total) assert.Equal(t, 25, nodeinfo.Usage.LocalPosts) assert.Equal(t, 2, nodeinfo.Usage.LocalComments) }) diff --git a/tests/integration/api_org_test.go b/tests/integration/api_org_test.go index 89bce0a01e733..83a101716b099 100644 --- a/tests/integration/api_org_test.go +++ b/tests/integration/api_org_test.go @@ -170,7 +170,7 @@ func TestAPIGetAll(t *testing.T) { var apiOrgList []*api.Organization DecodeJSON(t, resp, &apiOrgList) - assert.Len(t, apiOrgList, 13) + assert.Len(t, apiOrgList, 11) assert.Equal(t, "Limited Org 36", apiOrgList[1].FullName) assert.Equal(t, "limited", apiOrgList[1].Visibility) @@ -179,7 +179,7 @@ func TestAPIGetAll(t *testing.T) { resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiOrgList) - assert.Len(t, apiOrgList, 8) + assert.Len(t, apiOrgList, 7) assert.Equal(t, "org25", apiOrgList[0].FullName) assert.Equal(t, "public", apiOrgList[0].Visibility) } diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go index ebbe007775310..b87ba983f546b 100644 --- a/tests/integration/api_repo_test.go +++ b/tests/integration/api_repo_test.go @@ -93,9 +93,9 @@ func TestAPISearchRepo(t *testing.T) { }{ { name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{ - nil: {count: 35}, - user: {count: 35}, - user2: {count: 35}, + nil: {count: 34}, + user: {count: 34}, + user2: {count: 34}, }, }, { @@ -274,8 +274,8 @@ func TestAPIViewRepo(t *testing.T) { DecodeJSON(t, resp, &repo) assert.EqualValues(t, 10, repo.ID) assert.EqualValues(t, "repo10", repo.Name) - assert.EqualValues(t, 1, repo.OpenPulls) - assert.EqualValues(t, 1, repo.Forks) + assert.EqualValues(t, 4, repo.OpenPulls) + assert.EqualValues(t, 3, repo.Forks) req = NewRequest(t, "GET", "/api/v1/repos/user5/repo4") resp = MakeRequest(t, req, http.StatusOK) diff --git a/tests/integration/api_user_orgs_test.go b/tests/integration/api_user_orgs_test.go index f76c61f818f5e..70835f137c0b5 100644 --- a/tests/integration/api_user_orgs_test.go +++ b/tests/integration/api_user_orgs_test.go @@ -29,8 +29,21 @@ func TestUserOrgs(t *testing.T) { user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user3"}) user17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user17"}) + user35 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "private_org35"}) assert.Equal(t, []*api.Organization{ + { + ID: 35, + Name: user35.Name, + UserName: user35.Name, + FullName: user35.FullName, + Email: user35.Email, + AvatarURL: user35.AvatarLink(db.DefaultContext), + Description: "", + Website: "", + Location: "", + Visibility: "private", + }, { ID: 17, Name: user17.Name, @@ -101,8 +114,21 @@ func TestMyOrgs(t *testing.T) { DecodeJSON(t, resp, &orgs) user3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user3"}) user17 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "user17"}) + user35 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "private_org35"}) assert.Equal(t, []*api.Organization{ + { + ID: 35, + Name: user35.Name, + UserName: user35.Name, + FullName: user35.FullName, + Email: user35.Email, + AvatarURL: user35.AvatarLink(db.DefaultContext), + Description: "", + Website: "", + Location: "", + Visibility: "private", + }, { ID: 17, Name: user17.Name, diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 41f6f84fb1e0b..cdcebe132a923 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -430,7 +430,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 11) + assert.Len(t, apiIssues, 8) query = url.Values{"owner": {"user3"}} // organization link.RawQuery = query.Encode() From 8f3d5c9bc30add37de3ce266994d9136c1d37cfd Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 28 Aug 2023 05:23:28 +0000 Subject: [PATCH 52/97] fix --- templates/repo/code/recently_pushed_new_branches.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/code/recently_pushed_new_branches.tmpl b/templates/repo/code/recently_pushed_new_branches.tmpl index 9bda43ffa94e2..c79b0ad8e5ac7 100644 --- a/templates/repo/code/recently_pushed_new_branches.tmpl +++ b/templates/repo/code/recently_pushed_new_branches.tmpl @@ -2,7 +2,7 @@
{{$timeSince := TimeSince .CommitTime.AsTime $.locale}} - {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" .BranchName $timeSince | Safe}} + {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" (Escape .BranchName) $timeSince | Safe}}
{{$.locale.Tr "repo.pulls.compare_changes"}} From e79c8e0b58b01b44c332b4cb3c1cbc6995f289f1 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 28 Aug 2023 07:49:32 +0000 Subject: [PATCH 53/97] fix ci --- models/fixtures/org_user.yml | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/models/fixtures/org_user.yml b/models/fixtures/org_user.yml index 7886d1581493b..757775daeb8b1 100644 --- a/models/fixtures/org_user.yml +++ b/models/fixtures/org_user.yml @@ -103,29 +103,11 @@ - id: 18 uid: 12 - org_id: 37 - is_public: false - -- - id: 19 - uid: 41 - org_id: 38 - is_public: false - -- - id: 20 - uid: 42 - org_id: 38 - is_public: false - -- - id: 21 - uid: 12 org_id: 25 is_public: true - - id: 22 + id: 19 uid: 2 org_id: 35 is_public: true From 34734c2265552934d8c26980ef0b6c4f7f7dc8fb Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 28 Aug 2023 07:49:42 +0000 Subject: [PATCH 54/97] fix comment --- models/fixtures/team.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/fixtures/team.yml b/models/fixtures/team.yml index 3be2bedcab152..4fc420cc2e43b 100644 --- a/models/fixtures/team.yml +++ b/models/fixtures/team.yml @@ -223,7 +223,7 @@ org_id: 25 lower_name: owners name: Owners - authorize: 4 # read + authorize: 4 # owner num_repos: 0 num_members: 1 includes_all_repositories: false From 7fa0362d3637537d7c6fbc1064af0a0c2acc6b54 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 6 Sep 2023 07:22:48 +0000 Subject: [PATCH 55/97] remove ignore no repo error --- models/git/branch.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index 81e146105c97c..7f5691e0bb953 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -142,12 +142,10 @@ func (b *Branch) LoadPusher(ctx context.Context) (err error) { } func (b *Branch) LoadRepo(ctx context.Context) (err error) { - if b.Repo == nil && b.RepoID > 0 { - b.Repo, err = repo_model.GetRepositoryByID(ctx, b.RepoID) - if repo_model.IsErrRepoNotExist(err) { - err = nil - } + if b.Repo != nil && b.RepoID == 0 { + return nil } + b.Repo, err = repo_model.GetRepositoryByID(ctx, b.RepoID) return err } From a2425ce6ac3140105214e0a5512eb050b6923719 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 10 Nov 2023 11:40:36 +0900 Subject: [PATCH 56/97] Update models/git/branch.go Co-authored-by: silverwind --- models/git/branch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/git/branch.go b/models/git/branch.go index 7f5691e0bb953..edefa18074ac6 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -440,7 +440,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed )) if opts.CommitAfterUnix == 0 { - opts.CommitAfterUnix = time.Now().Add(-time.Hour * 6).Unix() + opts.CommitAfterUnix = time.Now().Add(-time.Hour * 2).Unix() } baseBranch, err := GetBranch(ctx, opts.BaseRepo.ID, opts.BaseRepo.DefaultBranch) From 2549c33632a7d9c3778aa88ca9aa131da09f2627 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 10 Nov 2023 11:40:44 +0900 Subject: [PATCH 57/97] Update models/git/branch.go Co-authored-by: silverwind --- models/git/branch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/git/branch.go b/models/git/branch.go index edefa18074ac6..1deac314ee0d3 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -405,7 +405,7 @@ type RecentlyPushedNewBranch struct { CommitTime timeutil.TimeStamp } -// FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 6 hours which has no opened PRs created +// FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 2 hours which has no opened PRs created // opts.Actor should not be nil // if opts.CommitAfterUnix is 0, we will find the branches committed in recently 6 hours // if opts.ListOptions is not set, we will only display top 2 latest branch From 2b677fc2aea1c1ba8e75761ef13dc4df1c12502c Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 10 Nov 2023 11:40:53 +0900 Subject: [PATCH 58/97] Update models/git/branch.go Co-authored-by: silverwind --- models/git/branch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/git/branch.go b/models/git/branch.go index 1deac314ee0d3..c41cc40052d63 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -407,7 +407,7 @@ type RecentlyPushedNewBranch struct { // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 2 hours which has no opened PRs created // opts.Actor should not be nil -// if opts.CommitAfterUnix is 0, we will find the branches committed in recently 6 hours +// if opts.CommitAfterUnix is 0, we will find the branches that were committed to in the last 2 hours // if opts.ListOptions is not set, we will only display top 2 latest branch func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushedNewBranchesOptions) ([]*RecentlyPushedNewBranch, error) { // find all related repo ids From 3d98673fd6937ecb1a0c5627deb399ffb84bc586 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 17 Nov 2023 01:03:30 +0000 Subject: [PATCH 59/97] fix api user orgs test --- tests/integration/api_user_orgs_test.go | 48 ++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/integration/api_user_orgs_test.go b/tests/integration/api_user_orgs_test.go index 605ff0e9bd380..5c3620845aad8 100644 --- a/tests/integration/api_user_orgs_test.go +++ b/tests/integration/api_user_orgs_test.go @@ -32,18 +32,6 @@ func TestUserOrgs(t *testing.T) { org35 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "private_org35"}) assert.Equal(t, []*api.Organization{ - { - ID: 35, - Name: org35.Name, - UserName: org35.Name, - FullName: org35.FullName, - Email: org35.Email, - AvatarURL: org35.AvatarLink(db.DefaultContext), - Description: "", - Website: "", - Location: "", - Visibility: "private", - }, { ID: 17, Name: org17.Name, @@ -68,6 +56,18 @@ func TestUserOrgs(t *testing.T) { Location: "", Visibility: "public", }, + { + ID: 35, + Name: org35.Name, + UserName: org35.Name, + FullName: org35.FullName, + Email: org35.Email, + AvatarURL: org35.AvatarLink(db.DefaultContext), + Description: "", + Website: "", + Location: "", + Visibility: "private", + }, }, orgs) // user itself should get it's org's he is a member of @@ -117,18 +117,6 @@ func TestMyOrgs(t *testing.T) { org35 := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: "private_org35"}) assert.Equal(t, []*api.Organization{ - { - ID: 35, - Name: org35.Name, - UserName: org35.Name, - FullName: org35.FullName, - Email: org35.Email, - AvatarURL: org35.AvatarLink(db.DefaultContext), - Description: "", - Website: "", - Location: "", - Visibility: "private", - }, { ID: 17, Name: org17.Name, @@ -153,5 +141,17 @@ func TestMyOrgs(t *testing.T) { Location: "", Visibility: "public", }, + { + ID: 35, + Name: org35.Name, + UserName: org35.Name, + FullName: org35.FullName, + Email: org35.Email, + AvatarURL: org35.AvatarLink(db.DefaultContext), + Description: "", + Website: "", + Location: "", + Visibility: "private", + }, }, orgs) } From e44cec43f632403ca59faf20c5b1116dcc2f3d6a Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 17 Nov 2023 01:20:31 +0000 Subject: [PATCH 60/97] fix indexer test --- modules/indexer/issues/indexer_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index da4fc9b878999..6913494c13bbc 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -218,7 +218,7 @@ func searchIssueIsPull(t *testing.T) { SearchOptions{ IsPull: util.OptionalBoolTrue, }, - []int64{12, 11, 20, 19, 9, 8, 3, 2}, + []int64{12, 11, 20, 26, 25, 24, 23, 22, 21, 19, 9, 8, 3, 2}, }, } for _, test := range tests { @@ -239,13 +239,13 @@ func searchIssueIsClosed(t *testing.T) { SearchOptions{ IsClosed: util.OptionalBoolFalse, }, - []int64{17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1}, + []int64{17, 16, 15, 14, 13, 12, 11, 20, 6, 26, 25, 23, 21, 19, 18, 10, 7, 9, 8, 3, 2, 1}, }, { SearchOptions{ IsClosed: util.OptionalBoolTrue, }, - []int64{5, 4}, + []int64{5, 24, 22, 4}, }, } for _, test := range tests { @@ -305,7 +305,7 @@ func searchIssueByLabelID(t *testing.T) { SearchOptions{ ExcludedLabelIDs: []int64{1}, }, - []int64{17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3}, + []int64{17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 26, 25, 24, 23, 22, 21, 19, 18, 10, 7, 4, 9, 8, 3}, }, } for _, test := range tests { @@ -329,7 +329,7 @@ func searchIssueByTime(t *testing.T) { SearchOptions{ UpdatedAfterUnix: int64Pointer(0), }, - []int64{17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1}, + []int64{17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 26, 25, 24, 23, 22, 21, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1}, }, } for _, test := range tests { @@ -350,7 +350,7 @@ func searchIssueWithOrder(t *testing.T) { SearchOptions{ SortBy: internal.SortByCreatedAsc, }, - []int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17}, + []int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 21, 22, 23, 24, 25, 26, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17}, }, } for _, test := range tests { @@ -411,7 +411,7 @@ func searchIssueWithPaginator(t *testing.T) { }, }, []int64{17, 16, 15, 14, 13}, - 20, + 26, }, } for _, test := range tests { From 39220110443ff1c1b9ba81e026a121b5fad03b6f Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 17 Nov 2023 01:26:07 +0000 Subject: [PATCH 61/97] fix lint --- models/fixtures/issue.yml | 2 +- models/fixtures/pull_request.yml | 2 +- models/fixtures/repo_unit.yml | 2 +- models/fixtures/team_repo.yml | 2 +- models/fixtures/team_user.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index 255a636fab72b..9ce3e51ec93f8 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -439,4 +439,4 @@ num_comments: 0 created_unix: 946684830 updated_unix: 978307200 - is_locked: false \ No newline at end of file + is_locked: false diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index 6f1b61cf53400..9673561eb3638 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -175,4 +175,4 @@ head_branch: same-name-branch-in-pr base_branch: master merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d - has_merged: false \ No newline at end of file + has_merged: false diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index 03effc6eca758..29346f0e0eb6a 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -680,4 +680,4 @@ id: 102 repo_id: 60 type: 1 - created_unix: 946684810 \ No newline at end of file + created_unix: 946684810 diff --git a/models/fixtures/team_repo.yml b/models/fixtures/team_repo.yml index 368b6c1ea0ff4..a745b3f6ccf74 100644 --- a/models/fixtures/team_repo.yml +++ b/models/fixtures/team_repo.yml @@ -74,4 +74,4 @@ id: 13 org_id: 35 team_id: 22 - repo_id: 60 \ No newline at end of file + repo_id: 60 diff --git a/models/fixtures/team_user.yml b/models/fixtures/team_user.yml index 2e0301fb515cb..45f681e4c7a0e 100644 --- a/models/fixtures/team_user.yml +++ b/models/fixtures/team_user.yml @@ -140,4 +140,4 @@ id: 24 org_id: 35 team_id: 22 - uid: 2 \ No newline at end of file + uid: 2 From b3d6bed21db8a94a20fcb2d9a23c3775c93bf297 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 17 Nov 2023 01:36:20 +0000 Subject: [PATCH 62/97] fix lint --- models/fixtures/issue.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index 9ce3e51ec93f8..fe3e98f70db2c 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -345,7 +345,7 @@ index: 2 poster_id: 12 original_author_id: 0 - name: opening pr for recently new branch search test + name: opening pr for recently new branch search test content: content milestone_id: 0 priority: 0 @@ -362,7 +362,7 @@ index: 3 poster_id: 12 original_author_id: 0 - name: closed pr for recently new branch search test + name: closed pr for recently new branch search test content: content milestone_id: 0 priority: 0 @@ -379,7 +379,7 @@ index: 4 poster_id: 12 original_author_id: 0 - name: merged pr for recently new branch search test + name: merged pr for recently new branch search test content: content milestone_id: 0 priority: 0 @@ -396,7 +396,7 @@ index: 5 poster_id: 12 original_author_id: 0 - name: closed pr with deleted branch for recently new branch search test + name: closed pr with deleted branch for recently new branch search test content: content milestone_id: 0 priority: 0 @@ -413,7 +413,7 @@ index: 6 poster_id: 12 original_author_id: 0 - name: merged pr with deleted branch for recently new branch search test + name: merged pr with deleted branch for recently new branch search test content: content milestone_id: 0 priority: 0 @@ -430,7 +430,7 @@ index: 1 poster_id: 13 original_author_id: 0 - name: pr with same branch name for recently new branch search test + name: pr with same branch name for recently new branch search test content: content milestone_id: 0 priority: 0 From 4bd9cdba223fa874ccd820c33b1f8518064b3a30 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Mon, 20 Nov 2023 08:35:29 +0900 Subject: [PATCH 63/97] Update models/git/branch.go Co-authored-by: Lunny Xiao --- models/git/branch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/git/branch.go b/models/git/branch.go index c41cc40052d63..f2adc521f6afd 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -142,7 +142,7 @@ func (b *Branch) LoadPusher(ctx context.Context) (err error) { } func (b *Branch) LoadRepo(ctx context.Context) (err error) { - if b.Repo != nil && b.RepoID == 0 { + if b.Repo != nil || b.RepoID == 0 { return nil } b.Repo, err = repo_model.GetRepositoryByID(ctx, b.RepoID) From 2e860edbd472ecca58bb6710e81afdbd150c4c06 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 24 Jan 2024 08:35:53 +0000 Subject: [PATCH 64/97] fix fixture --- models/fixtures/access.yml | 4 ++-- models/fixtures/branch.yml | 16 ++++++++-------- models/fixtures/repo_unit.yml | 7 +++++++ models/fixtures/repository.yml | 15 ++++++++++++++- models/fixtures/team_repo.yml | 4 ++-- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index d2e5ba19ad96e..3a59f3a74fd5c 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -1,7 +1,7 @@ - id: 1 user_id: 1 - repo_id: 60 + repo_id: 61 mode: 4 - @@ -49,7 +49,7 @@ - id: 9 user_id: 12 - repo_id: 59 + repo_id: 60 mode: 4 - diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index f4b13a173761a..b9ac2c95a17ec 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -192,7 +192,7 @@ - id: 17 - repo_id: 59 + repo_id: 60 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -204,7 +204,7 @@ - id: 18 - repo_id: 59 + repo_id: 60 name: 'org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -216,7 +216,7 @@ - id: 19 - repo_id: 59 + repo_id: 60 name: 'org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -228,7 +228,7 @@ - id: 20 - repo_id: 60 + repo_id: 61 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -240,7 +240,7 @@ - id: 21 - repo_id: 60 + repo_id: 61 name: 'private-org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -252,7 +252,7 @@ - id: 22 - repo_id: 60 + repo_id: 61 name: 'private-org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -264,7 +264,7 @@ - id: 23 - repo_id: 60 + repo_id: 61 name: 'private-org-fork-no-permission-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -276,7 +276,7 @@ - id: 24 - repo_id: 60 + repo_id: 61 name: 'private-org-fork-no-permission-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index 29346f0e0eb6a..01d52a97d3e54 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -674,6 +674,7 @@ id: 101 repo_id: 59 type: 1 + config: "{}" created_unix: 946684810 - @@ -681,3 +682,9 @@ repo_id: 60 type: 1 created_unix: 946684810 + +- + id: 103 + repo_id: 61 + type: 1 + created_unix: 946684810 diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index e5047b30ce4dd..f2bf047b6d310 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -1696,6 +1696,19 @@ - id: 59 + owner_id: 2 + owner_name: user2 + lower_name: test_commit_revert + name: test_commit_revert + default_branch: main + is_empty: false + is_archived: false + is_private: true + status: 0 + num_issues: 0 + +- + id: 60 owner_id: 25 owner_name: org25 lower_name: org_fork_repo59 @@ -1725,7 +1738,7 @@ close_issues_via_commit_in_any_branch: false - - id: 60 + id: 61 owner_id: 35 owner_name: private_org35 lower_name: private_org_fork_repo60 diff --git a/models/fixtures/team_repo.yml b/models/fixtures/team_repo.yml index a745b3f6ccf74..753f228bb8d20 100644 --- a/models/fixtures/team_repo.yml +++ b/models/fixtures/team_repo.yml @@ -68,10 +68,10 @@ id: 12 org_id: 35 team_id: 18 - repo_id: 60 + repo_id: 61 - id: 13 org_id: 35 team_id: 22 - repo_id: 60 + repo_id: 61 From ba4406ff2c118f610d463a6dea18d5ee2184733e Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 24 Jan 2024 08:43:53 +0000 Subject: [PATCH 65/97] use db.Find instead of FindBranch --- models/git/branch.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index b015dc44a4ca0..a59a63fb69215 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -448,7 +448,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed opts.ListOptions.Page = 1 } - findBranchOpts := FindBranchOptions{ + branches, err := db.Find[Branch](ctx, FindBranchOptions{ RepoCond: builder.In("branch.repo_id", repoIDs), CommitCond: builder.Neq{"branch.commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them, PusherID: opts.Actor.ID, @@ -459,13 +459,11 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed // we can not detect them correctly PullRequestCond: builder.NotIn("branch.id", prBranchIds), ListOptions: opts.ListOptions, - } - - branches, err := FindBranches(ctx, findBranchOpts) + }) if err != nil { return nil, err } - if err := branches.LoadRepo(ctx); err != nil { + if err := BranchList(branches).LoadRepo(ctx); err != nil { return nil, err } From 66f96761e8a245603281bb1254a3e3ad0f90356a Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 9 Apr 2024 00:55:32 +0000 Subject: [PATCH 66/97] fix conflict --- models/fixtures/access.yml | 4 +- models/fixtures/issue.yml | 44 ++++++++++++++++-- models/fixtures/org_user.yml | 20 +++++++- models/fixtures/pull_request.yml | 38 +++++++++++---- models/fixtures/repo_unit.yml | 42 +++++++++++++++++ models/fixtures/repository.yml | 64 +++++++++++++++++++++++++- models/fixtures/team.yml | 28 +++++++++-- models/fixtures/team_repo.yml | 18 ++++++-- models/fixtures/team_unit.yml | 42 +++++++++++++++-- models/fixtures/team_user.yml | 24 ++++++++-- tests/integration/api_issue_test.go | 8 ++-- tests/integration/api_nodeinfo_test.go | 2 +- tests/integration/api_repo_test.go | 6 +-- tests/integration/issue_test.go | 8 ++-- 14 files changed, 305 insertions(+), 43 deletions(-) diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index 3a59f3a74fd5c..89c902b5ec7b8 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -1,7 +1,7 @@ - id: 1 user_id: 1 - repo_id: 61 + repo_id: 63 mode: 4 - @@ -49,7 +49,7 @@ - id: 9 user_id: 12 - repo_id: 60 + repo_id: 62 mode: 4 - diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index 12de7a9b20f91..c6c5f27fdcdb5 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -341,6 +341,40 @@ - id: 21 + repo_id: 60 + index: 1 + poster_id: 39 + original_author_id: 0 + name: repo60 pull1 + content: content for the 1st issue + milestone_id: 0 + priority: 0 + is_closed: false + is_pull: true + num_comments: 0 + created_unix: 1707270422 + updated_unix: 1707270422 + is_locked: false + +- + id: 22 + repo_id: 61 + index: 1 + poster_id: 40 + original_author_id: 0 + name: repo61 pull1 + content: content for the 1st issue + milestone_id: 0 + priority: 0 + is_closed: false + is_pull: true + num_comments: 0 + created_unix: 1707270422 + updated_unix: 1707270422 + is_locked: false + +- + id: 23 repo_id: 10 index: 2 poster_id: 12 @@ -357,7 +391,7 @@ is_locked: false - - id: 22 + id: 24 repo_id: 10 index: 3 poster_id: 12 @@ -374,7 +408,7 @@ is_locked: false - - id: 23 + id: 25 repo_id: 10 index: 4 poster_id: 12 @@ -391,7 +425,7 @@ is_locked: false - - id: 24 + id: 26 repo_id: 10 index: 5 poster_id: 12 @@ -408,7 +442,7 @@ is_locked: false - - id: 25 + id: 27 repo_id: 10 index: 6 poster_id: 12 @@ -425,7 +459,7 @@ is_locked: false - - id: 26 + id: 28 repo_id: 11 index: 1 poster_id: 13 diff --git a/models/fixtures/org_user.yml b/models/fixtures/org_user.yml index 757775daeb8b1..cf21b84aa9fc5 100644 --- a/models/fixtures/org_user.yml +++ b/models/fixtures/org_user.yml @@ -102,12 +102,30 @@ - id: 18 + uid: 38 + org_id: 41 + is_public: true + +- + id: 19 + uid: 39 + org_id: 41 + is_public: true + +- + id: 20 + uid: 40 + org_id: 41 + is_public: true + +- + id: 21 uid: 12 org_id: 25 is_public: true - - id: 19 + id: 22 uid: 2 org_id: 35 is_public: true diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index 9673561eb3638..5302af04d668c 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -104,6 +104,24 @@ type: 0 # gitea pull request status: 2 # mergable issue_id: 21 + index: 1 + head_repo_id: 60 + base_repo_id: 60 + +- + id: 10 + type: 0 # gitea pull request + status: 2 # mergable + issue_id: 22 + index: 1 + head_repo_id: 61 + base_repo_id: 61 + +- + id: 11 + type: 0 # gitea pull request + status: 2 # mergable + issue_id: 23 index: 2 head_repo_id: 10 base_repo_id: 10 @@ -113,10 +131,10 @@ has_merged: false - - id: 10 + id: 12 type: 0 # gitea pull request status: 2 # mergable - issue_id: 22 + issue_id: 24 index: 3 head_repo_id: 10 base_repo_id: 10 @@ -126,10 +144,10 @@ has_merged: false - - id: 11 + id: 13 type: 0 # gitea pull request status: 3 # manually merged - issue_id: 23 + issue_id: 25 index: 4 head_repo_id: 10 base_repo_id: 10 @@ -139,10 +157,10 @@ has_merged: true - - id: 12 + id: 14 type: 0 # gitea pull request status: 2 # mergable - issue_id: 24 + issue_id: 26 index: 5 head_repo_id: 10 base_repo_id: 10 @@ -152,10 +170,10 @@ has_merged: false - - id: 13 + id: 15 type: 0 # gitea pull request status: 3 # manually merged - issue_id: 25 + issue_id: 27 index: 6 head_repo_id: 10 base_repo_id: 10 @@ -165,10 +183,10 @@ has_merged: true - - id: 14 + id: 16 type: 0 # gitea pull request status: 2 # mergable - issue_id: 26 + issue_id: 28 index: 1 head_repo_id: 11 base_repo_id: 10 diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index 01d52a97d3e54..48d313638d755 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -681,10 +681,52 @@ id: 102 repo_id: 60 type: 1 + config: "{}" created_unix: 946684810 - id: 103 + repo_id: 60 + type: 2 + config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true}" + created_unix: 946684810 + +- + id: 104 + repo_id: 60 + type: 3 + config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}" + created_unix: 946684810 + +- + id: 105 + repo_id: 61 + type: 1 + config: "{}" + created_unix: 946684810 + +- + id: 106 repo_id: 61 + type: 2 + config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true}" + created_unix: 946684810 + +- + id: 107 + repo_id: 61 + type: 3 + config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}" + created_unix: 946684810 + +- + id: 108 + repo_id: 62 + type: 1 + created_unix: 946684810 + +- + id: 109 + repo_id: 63 type: 1 created_unix: 946684810 diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index f2bf047b6d310..4414d7e8e4c49 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -1709,6 +1709,68 @@ - id: 60 + owner_id: 40 + owner_name: user40 + lower_name: repo60 + name: repo60 + default_branch: main + num_watches: 0 + num_stars: 0 + num_forks: 0 + num_issues: 0 + num_closed_issues: 0 + num_pulls: 1 + num_closed_pulls: 0 + num_milestones: 0 + num_closed_milestones: 0 + num_projects: 0 + num_closed_projects: 0 + is_private: false + is_empty: false + is_archived: false + is_mirror: false + status: 0 + is_fork: false + fork_id: 0 + is_template: false + template_id: 0 + size: 0 + is_fsck_enabled: true + close_issues_via_commit_in_any_branch: false + +- + id: 61 + owner_id: 41 + owner_name: org41 + lower_name: repo61 + name: repo61 + default_branch: main + num_watches: 0 + num_stars: 0 + num_forks: 0 + num_issues: 0 + num_closed_issues: 0 + num_pulls: 1 + num_closed_pulls: 0 + num_milestones: 0 + num_closed_milestones: 0 + num_projects: 0 + num_closed_projects: 0 + is_private: false + is_empty: false + is_archived: false + is_mirror: false + status: 0 + is_fork: false + fork_id: 0 + is_template: false + template_id: 0 + size: 0 + is_fsck_enabled: true + close_issues_via_commit_in_any_branch: false + +- + id: 62 owner_id: 25 owner_name: org25 lower_name: org_fork_repo59 @@ -1738,7 +1800,7 @@ close_issues_via_commit_in_any_branch: false - - id: 61 + id: 63 owner_id: 35 owner_name: private_org35 lower_name: private_org_fork_repo60 diff --git a/models/fixtures/team.yml b/models/fixtures/team.yml index fa00c7f97e687..8040d907405b0 100644 --- a/models/fixtures/team.yml +++ b/models/fixtures/team.yml @@ -220,6 +220,28 @@ - id: 21 + org_id: 41 + lower_name: owners + name: Owners + authorize: 4 # owner + num_repos: 1 + num_members: 1 + includes_all_repositories: true + can_create_org_repo: true + +- + id: 22 + org_id: 41 + lower_name: team1 + name: Team1 + authorize: 1 # read + num_repos: 1 + num_members: 2 + includes_all_repositories: false + can_create_org_repo: false + +- + id: 23 org_id: 25 lower_name: owners name: Owners @@ -230,10 +252,10 @@ can_create_org_repo: true - - id: 22 + id: 24 org_id: 35 - lower_name: team22noreadcode - name: team22noreadcode + lower_name: team24noreadcode + name: team24noreadcode authorize: 0 # no access num_repos: 1 num_members: 1 diff --git a/models/fixtures/team_repo.yml b/models/fixtures/team_repo.yml index 753f228bb8d20..0a54d230d3520 100644 --- a/models/fixtures/team_repo.yml +++ b/models/fixtures/team_repo.yml @@ -66,12 +66,24 @@ - id: 12 - org_id: 35 - team_id: 18 + org_id: 41 + team_id: 21 repo_id: 61 - id: 13 - org_id: 35 + org_id: 41 team_id: 22 repo_id: 61 + +- + id: 14 + org_id: 35 + team_id: 18 + repo_id: 63 + +- + id: 15 + org_id: 35 + team_id: 24 + repo_id: 63 diff --git a/models/fixtures/team_unit.yml b/models/fixtures/team_unit.yml index 911b4d3f9a364..eb8646b6863a8 100644 --- a/models/fixtures/team_unit.yml +++ b/models/fixtures/team_unit.yml @@ -289,18 +289,54 @@ - id: 49 - team_id: 18 - type: 1 # code + team_id: 21 + type: 1 access_mode: 4 - id: 50 team_id: 21 - type: 1 # code + type: 2 access_mode: 4 - id: 51 + team_id: 21 + type: 3 + access_mode: 4 + +- + id: 52 + team_id: 22 + type: 1 + access_mode: 1 + +- + id: 53 + team_id: 22 + type: 2 + access_mode: 1 + +- + id: 54 team_id: 22 + type: 3 + access_mode: 1 + +- + id: 55 + team_id: 18 + type: 1 # code + access_mode: 4 + +- + id: 56 + team_id: 23 + type: 1 # code + access_mode: 4 + +- + id: 57 + team_id: 24 type: 1 # code access_mode: 0 diff --git a/models/fixtures/team_user.yml b/models/fixtures/team_user.yml index 45f681e4c7a0e..6b2d153278ac5 100644 --- a/models/fixtures/team_user.yml +++ b/models/fixtures/team_user.yml @@ -132,12 +132,30 @@ - id: 23 - org_id: 25 + org_id: 41 team_id: 21 - uid: 12 + uid: 40 - id: 24 - org_id: 35 + org_id: 41 team_id: 22 + uid: 38 + +- + id: 25 + org_id: 41 + team_id: 22 + uid: 39 + +- + id: 26 + org_id: 25 + team_id: 23 + uid: 12 + +- + id: 27 + org_id: 35 + team_id: 24 uid: 2 diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go index 0e97aeda94c2f..ea49cfb59ef87 100644 --- a/tests/integration/api_issue_test.go +++ b/tests/integration/api_issue_test.go @@ -217,7 +217,7 @@ func TestAPISearchIssues(t *testing.T) { defer tests.PrepareTestEnv(t)() // as this API was used in the frontend, it uses UI page size - expectedIssueCount := 22 // from the fixtures + expectedIssueCount := 24 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } @@ -257,7 +257,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "26", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "28", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 20) query.Add("limit", "10") @@ -265,7 +265,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "26", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "28", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 10) query = url.Values{"assigned": {"true"}, "state": {"all"}} @@ -315,7 +315,7 @@ func TestAPISearchIssuesWithLabels(t *testing.T) { defer tests.PrepareTestEnv(t)() // as this API was used in the frontend, it uses UI page size - expectedIssueCount := 22 // from the fixtures + expectedIssueCount := 24 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } diff --git a/tests/integration/api_nodeinfo_test.go b/tests/integration/api_nodeinfo_test.go index 8f67b1071695c..44ec6fe3be450 100644 --- a/tests/integration/api_nodeinfo_test.go +++ b/tests/integration/api_nodeinfo_test.go @@ -33,7 +33,7 @@ func TestNodeinfo(t *testing.T) { assert.True(t, nodeinfo.OpenRegistrations) assert.Equal(t, "gitea", nodeinfo.Software.Name) assert.Equal(t, 26, nodeinfo.Usage.Users.Total) - assert.Equal(t, 26, nodeinfo.Usage.LocalPosts) + assert.Equal(t, 28, nodeinfo.Usage.LocalPosts) assert.Equal(t, 3, nodeinfo.Usage.LocalComments) }) } diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go index 352fb0eb3404f..36a71a5bd77b4 100644 --- a/tests/integration/api_repo_test.go +++ b/tests/integration/api_repo_test.go @@ -93,9 +93,9 @@ func TestAPISearchRepo(t *testing.T) { }{ { name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{ - nil: {count: 34}, - user: {count: 34}, - user2: {count: 34}, + nil: {count: 36}, + user: {count: 36}, + user2: {count: 36}, }, }, { diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 11b22851a0390..190378c91e980 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -407,7 +407,7 @@ func TestSearchIssues(t *testing.T) { session := loginUser(t, "user2") - expectedIssueCount := 22 // from the fixtures + expectedIssueCount := 24 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } @@ -444,7 +444,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "26", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "28", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 20) query.Add("limit", "5") @@ -452,7 +452,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "26", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "28", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 5) query = url.Values{"assigned": {"true"}, "state": {"all"}} @@ -501,7 +501,7 @@ func TestSearchIssues(t *testing.T) { func TestSearchIssuesWithLabels(t *testing.T) { defer tests.PrepareTestEnv(t)() - expectedIssueCount := 22 // from the fixtures + expectedIssueCount := 24 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } From 5af46f7ce9c69a49fb97d25c889d3646bf8b7590 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 9 Apr 2024 00:59:02 +0000 Subject: [PATCH 67/97] fix --- models/fixtures/access.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index 89c902b5ec7b8..fb2f425d637bc 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -147,3 +147,27 @@ user_id: 31 repo_id: 28 mode: 4 + +- + id: 26 + user_id: 38 + repo_id: 60 + mode: 2 + +- + id: 27 + user_id: 38 + repo_id: 61 + mode: 1 + +- + id: 28 + user_id: 39 + repo_id: 61 + mode: 1 + +- + id: 29 + user_id: 40 + repo_id: 61 + mode: 4 From 7b06c463e679db69078a5938115fcdb97f78c3ae Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 9 Apr 2024 01:44:02 +0000 Subject: [PATCH 68/97] fix --- models/git/branch.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index f756bbe21b9c1..9f8fc690bd213 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -14,6 +14,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/optional" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" @@ -401,6 +402,7 @@ type FindRecentlyPushedNewBranchesOptions struct { type RecentlyPushedNewBranch struct { BranchName string + BranchLink string BranchCompareURL string CommitTime timeutil.TimeStamp } @@ -416,9 +418,9 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed Private: true, AllPublic: false, // Include also all public repositories of users and public organisations AllLimited: false, // Include also all public repositories of limited organisations - Fork: util.OptionalBoolTrue, + Fork: optional.Some(true), ForkFrom: opts.BaseRepo.ID, - Archived: util.OptionalBoolFalse, + Archived: optional.Some(false), } repoCond := repo_model.SearchRepositoryCondition(&repoOpts).And(repo_model.AccessibleRepositoryCondition(opts.Actor, unit.TypeCode)) if opts.Repo == opts.BaseRepo { @@ -457,7 +459,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed RepoCond: builder.In("branch.repo_id", repoIDs), CommitCond: builder.Neq{"branch.commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them, PusherID: opts.Actor.ID, - IsDeletedBranch: util.OptionalBoolFalse, + IsDeletedBranch: optional.Some(false), CommitAfterUnix: opts.CommitAfterUnix, OrderBy: "branch.updated_unix DESC", // should not use branch name here, because if there are branches with same name in different repos, @@ -480,6 +482,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed } newBranches = append(newBranches, &RecentlyPushedNewBranch{ BranchName: branchName, + BranchLink: branch.Repo.Link(), BranchCompareURL: branch.Repo.ComposeBranchCompareURL(opts.BaseRepo, branch.Name), CommitTime: branch.CommitTime, }) From c4386f0532dbd2fc429d30bf350e3d43ab6f188a Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 9 Apr 2024 01:45:47 +0000 Subject: [PATCH 69/97] fix --- models/issues/issue_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go index a2e07b18aff5d..e6724e27f9ce1 100644 --- a/models/issues/issue_test.go +++ b/models/issues/issue_test.go @@ -355,7 +355,7 @@ func TestCorrectIssueStats(t *testing.T) { assert.EqualValues(t, issueStats.OpenCount, issueAmount) } -https://github.com/go-gitea/gitea/pull/25812/conflict?name=models%252Fissues%252Fissue_test.go&ancestor_oid=cc363d2fae7c607d293393017094e5e385e470e7&base_oid=b93ea6d9f04b25760feac861043b8f2e08cca6de&head_oid=1bbc0eee564fda8994f817eebc95a3f05a61fba8func TestMilestoneList_LoadTotalTrackedTimes(t *testing.T) { +func TestMilestoneList_LoadTotalTrackedTimes(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) miles := issues_model.MilestoneList{ unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1}), From eed8b07efd3cf8efbe06d0ba8d1c2cc13efec6af Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 9 Apr 2024 01:57:46 +0000 Subject: [PATCH 70/97] fix --- models/git/branch.go | 24 +++++++++---------- .../code/recently_pushed_new_branches.tmpl | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index 9f8fc690bd213..d846173d3b334 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -401,10 +401,10 @@ type FindRecentlyPushedNewBranchesOptions struct { } type RecentlyPushedNewBranch struct { - BranchName string - BranchLink string - BranchCompareURL string - CommitTime timeutil.TimeStamp + BranchDisplayName string + BranchLink string + BranchCompareURL string + CommitTime timeutil.TimeStamp } // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 2 hours which has no opened PRs created @@ -433,7 +433,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed repoIDs := builder.Select("id").From("repository").Where(repoCond) // find branches which have already created PRs - prBranchIds := builder.Select("branch.id").From("branch"). + prBranchIDs := builder.Select("branch.id").From("branch"). InnerJoin("pull_request", "branch.name = pull_request.head_branch AND branch.repo_id = pull_request.head_repo_id"). Where(builder.And( builder.Eq{"pull_request.base_repo_id": opts.BaseRepo.ID}, @@ -464,7 +464,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed OrderBy: "branch.updated_unix DESC", // should not use branch name here, because if there are branches with same name in different repos, // we can not detect them correctly - PullRequestCond: builder.NotIn("branch.id", prBranchIds), + PullRequestCond: builder.NotIn("branch.id", prBranchIDs), ListOptions: opts.ListOptions, }) if err != nil { @@ -476,15 +476,15 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed newBranches := make([]*RecentlyPushedNewBranch, 0, len(branches)) for _, branch := range branches { - branchName := branch.Name + branchDisplayName := branch.Name if branch.Repo.ID != opts.BaseRepo.ID && branch.Repo.ID != opts.Repo.ID { - branchName = fmt.Sprintf("%s:%s", branch.Repo.FullName(), branchName) + branchDisplayName = fmt.Sprintf("%s:%s", branch.Repo.FullName(), branchDisplayName) } newBranches = append(newBranches, &RecentlyPushedNewBranch{ - BranchName: branchName, - BranchLink: branch.Repo.Link(), - BranchCompareURL: branch.Repo.ComposeBranchCompareURL(opts.BaseRepo, branch.Name), - CommitTime: branch.CommitTime, + BranchDisplayName: branchDisplayName, + BranchLink: fmt.Sprintf("%s/src/branch/%s", branch.Repo.Link(), util.PathEscapeSegments(branch.Name)), + BranchCompareURL: branch.Repo.ComposeBranchCompareURL(opts.BaseRepo, branch.Name), + CommitTime: branch.CommitTime, }) } return newBranches, nil diff --git a/templates/repo/code/recently_pushed_new_branches.tmpl b/templates/repo/code/recently_pushed_new_branches.tmpl index 237c586eaeb41..6d264fcc17525 100644 --- a/templates/repo/code/recently_pushed_new_branches.tmpl +++ b/templates/repo/code/recently_pushed_new_branches.tmpl @@ -2,7 +2,7 @@
{{$timeSince := TimeSince .CommitTime.AsTime ctx.Locale}} - {{$branchLink := HTMLFormat `%s` .BranchLink (PathEscapeSegments .BranchName) .BranchName}} + {{$branchLink := HTMLFormat `%s` .BranchLink .BranchDisplayName}} {{ctx.Locale.Tr "repo.pulls.recently_pushed_new_branches" $branchLink $timeSince}}
From 263a4438e4c030b784f8b83407eb1eebf687da68 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 9 Apr 2024 02:04:38 +0000 Subject: [PATCH 71/97] fix test --- models/fixtures/branch.yml | 16 ++++++++-------- models/fixtures/repository.yml | 8 ++++---- models/git/branch_test.go | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index b9ac2c95a17ec..2e7c5838dd46b 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -192,7 +192,7 @@ - id: 17 - repo_id: 60 + repo_id: 62 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -204,7 +204,7 @@ - id: 18 - repo_id: 60 + repo_id: 62 name: 'org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -216,7 +216,7 @@ - id: 19 - repo_id: 60 + repo_id: 62 name: 'org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -228,7 +228,7 @@ - id: 20 - repo_id: 61 + repo_id: 63 name: 'master' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -240,7 +240,7 @@ - id: 21 - repo_id: 61 + repo_id: 63 name: 'private-org-fork-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -252,7 +252,7 @@ - id: 22 - repo_id: 61 + repo_id: 63 name: 'private-org-fork-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' @@ -264,7 +264,7 @@ - id: 23 - repo_id: 61 + repo_id: 63 name: 'private-org-fork-no-permission-new-commit' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' @@ -276,7 +276,7 @@ - id: 24 - repo_id: 61 + repo_id: 63 name: 'private-org-fork-no-permission-no-commit' commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' commit_message: 'Initial commit' diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 1574423c5ae56..f1045bce3f06f 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -1773,8 +1773,8 @@ id: 62 owner_id: 25 owner_name: org25 - lower_name: org_fork_repo59 - name: org_fork_repo59 + lower_name: org_fork_repo62 + name: org_fork_repo62 num_watches: 0 num_stars: 0 num_forks: 0 @@ -1803,8 +1803,8 @@ id: 63 owner_id: 35 owner_name: private_org35 - lower_name: private_org_fork_repo60 - name: private_org_fork_repo60 + lower_name: private_org_fork_repo63 + name: private_org_fork_repo63 num_watches: 0 num_stars: 0 num_forks: 0 diff --git a/models/git/branch_test.go b/models/git/branch_test.go index 1820f5a029023..b7a221234f383 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -213,7 +213,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { }, }, count: 2, - want: []string{"new-commit", "org25/org_fork_repo59:org-fork-new-commit"}, + want: []string{"new-commit", "org25/org_fork_repo62:org-fork-new-commit"}, }, // user13 pushed 2 branches with the same name in repo10 and repo11 // and repo11's branch has a pr, but repo10's branch doesn't @@ -239,7 +239,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { CommitAfterUnix: 1489927670, }, count: 1, - want: []string{"private_org35/private_org_fork_repo60:private-org-fork-new-commit"}, + want: []string{"private_org35/private_org_fork_repo63:private-org-fork-new-commit"}, }, // user2 does not have code permission in private_org35 { @@ -258,7 +258,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { CommitAfterUnix: 1489927690, }, count: 1, - want: []string{"org25/org_fork_repo59:org-fork-new-commit"}, + want: []string{"org25/org_fork_repo62:org-fork-new-commit"}, }, } @@ -272,7 +272,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { assert.Equal(t, tt.count, len(branches)) for i := 0; i < tt.count; i++ { - assert.Equal(t, tt.want[i], branches[i].BranchName) + assert.Equal(t, tt.want[i], branches[i].BranchDisplayName) } }) } From a8a5de2cdf6971a429f550fd858880a9acc5e3e7 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 9 Apr 2024 02:49:26 +0000 Subject: [PATCH 72/97] fix test --- models/fixtures/access.yml | 52 +++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index fb2f425d637bc..681d6a93841eb 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -48,126 +48,138 @@ - id: 9 + user_id: 10 + repo_id: 21 + mode: 2 + +- + id: 10 + user_id: 10 + repo_id: 32 + mode: 2 + +- + id: 11 user_id: 12 repo_id: 62 mode: 4 - - id: 10 + id: 12 user_id: 15 repo_id: 21 mode: 2 - - id: 11 + id: 13 user_id: 15 repo_id: 22 mode: 2 - - id: 12 + id: 14 user_id: 15 repo_id: 23 mode: 4 - - id: 13 + id: 15 user_id: 15 repo_id: 24 mode: 4 - - id: 14 + id: 16 user_id: 15 repo_id: 32 mode: 2 - - id: 15 + id: 17 user_id: 18 repo_id: 21 mode: 2 - - id: 16 + id: 18 user_id: 18 repo_id: 22 mode: 2 - - id: 17 + id: 19 user_id: 18 repo_id: 23 mode: 4 - - id: 18 + id: 20 user_id: 18 repo_id: 24 mode: 4 - - id: 19 + id: 21 user_id: 20 repo_id: 24 mode: 1 - - id: 20 + id: 22 user_id: 20 repo_id: 27 mode: 4 - - id: 21 + id: 23 user_id: 20 repo_id: 28 mode: 4 - - id: 22 + id: 24 user_id: 29 repo_id: 4 mode: 2 - - id: 23 + id: 25 user_id: 29 repo_id: 24 mode: 1 - - id: 24 + id: 26 user_id: 31 repo_id: 27 mode: 4 - - id: 25 + id: 27 user_id: 31 repo_id: 28 mode: 4 - - id: 26 + id: 28 user_id: 38 repo_id: 60 mode: 2 - - id: 27 + id: 29 user_id: 38 repo_id: 61 mode: 1 - - id: 28 + id: 30 user_id: 39 repo_id: 61 mode: 1 - - id: 29 + id: 31 user_id: 40 repo_id: 61 mode: 4 From ed19b8bdd7e4876a15cb5346f0b0a3e684c20036 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 12 Apr 2024 05:54:45 +0000 Subject: [PATCH 73/97] use container.FilterSlice --- models/git/branch_list.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/models/git/branch_list.go b/models/git/branch_list.go index 03e81a38b875c..653886e371221 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -61,14 +61,12 @@ func (branches BranchList) LoadPusher(ctx context.Context) error { } func (branches BranchList) LoadRepo(ctx context.Context) error { - ids := container.Set[int64]{} - for _, branch := range branches { - if branch.RepoID > 0 { - ids.Add(branch.RepoID) - } - } + ids := container.FilterSlice(branches, func(branch *Branch) (int64, bool) { + return branch.RepoID, branch.RepoID > 0 + }) + reposMap := make(map[int64]*repo_model.Repository, len(ids)) - if err := db.GetEngine(ctx).In("id", ids.Values()).Find(&reposMap); err != nil { + if err := db.GetEngine(ctx).In("id", ids).Find(&reposMap); err != nil { return err } for _, branch := range branches { From c397f0881236fced3b3d9ca39535c6b6637f37e4 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 12 Apr 2024 05:58:32 +0000 Subject: [PATCH 74/97] improve --- models/git/branch_list.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/git/branch_list.go b/models/git/branch_list.go index 653886e371221..d3620c662f3ba 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -62,7 +62,7 @@ func (branches BranchList) LoadPusher(ctx context.Context) error { func (branches BranchList) LoadRepo(ctx context.Context) error { ids := container.FilterSlice(branches, func(branch *Branch) (int64, bool) { - return branch.RepoID, branch.RepoID > 0 + return branch.RepoID, branch.RepoID > 0 && branch.Repo == nil }) reposMap := make(map[int64]*repo_model.Repository, len(ids)) @@ -70,7 +70,7 @@ func (branches BranchList) LoadRepo(ctx context.Context) error { return err } for _, branch := range branches { - if branch.RepoID <= 0 { + if branch.RepoID <= 0 || branch.Repo != nil { continue } branch.Repo = reposMap[branch.RepoID] From 7031377e1e1efdb71e36bbb15704e8fccc79cdb4 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 18 Apr 2024 11:02:35 +0000 Subject: [PATCH 75/97] fix --- models/git/branch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/git/branch.go b/models/git/branch.go index d846173d3b334..d13fd294d0c62 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -423,7 +423,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed Archived: optional.Some(false), } repoCond := repo_model.SearchRepositoryCondition(&repoOpts).And(repo_model.AccessibleRepositoryCondition(opts.Actor, unit.TypeCode)) - if opts.Repo == opts.BaseRepo { + if opts.Repo.ID == opts.BaseRepo.ID { // should also include the base repo's branches repoCond = repoCond.Or(builder.Eq{"id": opts.BaseRepo.ID}) } else { From 43495eb81a76566677dfd907526790351d2cf4f8 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 18 Apr 2024 12:07:13 +0000 Subject: [PATCH 76/97] improve --- models/git/branch.go | 67 +++++++++++++++++++++------------------ models/git/branch_list.go | 7 ---- models/git/branch_test.go | 10 ++---- 3 files changed, 38 insertions(+), 46 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index d13fd294d0c62..b92851f5ab309 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -393,11 +393,11 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str } type FindRecentlyPushedNewBranchesOptions struct { - db.ListOptions Actor *user_model.User Repo *repo_model.Repository BaseRepo *repo_model.Repository CommitAfterUnix int64 + MaxCount int } type RecentlyPushedNewBranch struct { @@ -432,15 +432,6 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed } repoIDs := builder.Select("id").From("repository").Where(repoCond) - // find branches which have already created PRs - prBranchIDs := builder.Select("branch.id").From("branch"). - InnerJoin("pull_request", "branch.name = pull_request.head_branch AND branch.repo_id = pull_request.head_repo_id"). - Where(builder.And( - builder.Eq{"pull_request.base_repo_id": opts.BaseRepo.ID}, - builder.Eq{"pull_request.base_branch": opts.BaseRepo.DefaultBranch}, - builder.In("pull_request.head_repo_id", repoIDs), - )) - if opts.CommitAfterUnix == 0 { opts.CommitAfterUnix = time.Now().Add(-time.Hour * 2).Unix() } @@ -450,11 +441,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed return nil, err } - if opts.ListOptions.PageSize == 0 { - opts.ListOptions.PageSize = 2 - opts.ListOptions.Page = 1 - } - + // find all related branches, these branches may already created PRs, we will check later branches, err := db.Find[Branch](ctx, FindBranchOptions{ RepoCond: builder.In("branch.repo_id", repoIDs), CommitCond: builder.Neq{"branch.commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them, @@ -462,30 +449,48 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed IsDeletedBranch: optional.Some(false), CommitAfterUnix: opts.CommitAfterUnix, OrderBy: "branch.updated_unix DESC", - // should not use branch name here, because if there are branches with same name in different repos, - // we can not detect them correctly - PullRequestCond: builder.NotIn("branch.id", prBranchIDs), - ListOptions: opts.ListOptions, + ListOptions: db.ListOptionsAll, }) if err != nil { return nil, err } - if err := BranchList(branches).LoadRepo(ctx); err != nil { - return nil, err - } newBranches := make([]*RecentlyPushedNewBranch, 0, len(branches)) + if opts.MaxCount == 0 { + // by default we display 2 recently pushed new branch + opts.MaxCount = 2 + } for _, branch := range branches { - branchDisplayName := branch.Name - if branch.Repo.ID != opts.BaseRepo.ID && branch.Repo.ID != opts.Repo.ID { - branchDisplayName = fmt.Sprintf("%s:%s", branch.Repo.FullName(), branchDisplayName) + // whether branch have already created PR + count, err := db.GetEngine(ctx).Table("pull_request"). + // we should not only use branch name here, because if there are branches with same name in other repos, + // we can not detect them correctly + Where(builder.Eq{"head_repo_id": branch.RepoID, "head_branch": branch.Name}).Count() + if err != nil { + return nil, err + } + + // if no PR, we add to the result + if count == 0 { + if err := branch.LoadRepo(ctx); err != nil { + return nil, err + } + + branchDisplayName := branch.Name + if branch.Repo.ID != opts.BaseRepo.ID && branch.Repo.ID != opts.Repo.ID { + branchDisplayName = fmt.Sprintf("%s:%s", branch.Repo.FullName(), branchDisplayName) + } + newBranches = append(newBranches, &RecentlyPushedNewBranch{ + BranchDisplayName: branchDisplayName, + BranchLink: fmt.Sprintf("%s/src/branch/%s", branch.Repo.Link(), util.PathEscapeSegments(branch.Name)), + BranchCompareURL: branch.Repo.ComposeBranchCompareURL(opts.BaseRepo, branch.Name), + CommitTime: branch.CommitTime, + }) + } + if len(newBranches) == opts.MaxCount { + break } - newBranches = append(newBranches, &RecentlyPushedNewBranch{ - BranchDisplayName: branchDisplayName, - BranchLink: fmt.Sprintf("%s/src/branch/%s", branch.Repo.Link(), util.PathEscapeSegments(branch.Name)), - BranchCompareURL: branch.Repo.ComposeBranchCompareURL(opts.BaseRepo, branch.Name), - CommitTime: branch.CommitTime, - }) } + return newBranches, nil } diff --git a/models/git/branch_list.go b/models/git/branch_list.go index d3620c662f3ba..681685b644462 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -90,9 +90,6 @@ type FindBranchOptions struct { CommitBeforeUnix int64 OrderBy string Keyword string - - // find branch by pull request - PullRequestCond builder.Cond } func (opts FindBranchOptions) ToConds() builder.Cond { @@ -131,10 +128,6 @@ func (opts FindBranchOptions) ToConds() builder.Cond { cond = cond.And(builder.Lte{"branch.commit_time": opts.CommitBeforeUnix}) } - if opts.PullRequestCond != nil { - cond = cond.And(opts.PullRequestCond) - } - return cond } diff --git a/models/git/branch_test.go b/models/git/branch_test.go index b7a221234f383..1092ca521cc14 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -207,10 +207,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { opts: &git_model.FindRecentlyPushedNewBranchesOptions{ Actor: user12, CommitAfterUnix: 1489927670, - ListOptions: db.ListOptions{ - PageSize: 10, - Page: 1, - }, + MaxCount: 10, }, count: 2, want: []string{"new-commit", "org25/org_fork_repo62:org-fork-new-commit"}, @@ -223,10 +220,7 @@ func TestFindRecentlyPushedNewBranches(t *testing.T) { opts: &git_model.FindRecentlyPushedNewBranchesOptions{ Actor: user13, CommitAfterUnix: 1489927670, - ListOptions: db.ListOptions{ - PageSize: 10, - Page: 1, - }, + MaxCount: 10, }, count: 2, want: []string{"user13/repo11:user-fork-new-commit", "same-name-branch-in-pr"}, From fb7abfe792ccc32e23e0e7f3fd75081d98d32d76 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 8 May 2024 08:59:00 +0000 Subject: [PATCH 77/97] fix misspelling --- models/fixtures/pull_request.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index 439a3100bf810..03cce53063912 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -121,7 +121,7 @@ - id: 11 type: 0 # gitea pull request - status: 2 # mergable + status: 2 # mergeable issue_id: 23 index: 2 head_repo_id: 10 @@ -134,7 +134,7 @@ - id: 12 type: 0 # gitea pull request - status: 2 # mergable + status: 2 # mergeable issue_id: 24 index: 3 head_repo_id: 10 @@ -160,7 +160,7 @@ - id: 14 type: 0 # gitea pull request - status: 2 # mergable + status: 2 # mergeable issue_id: 26 index: 5 head_repo_id: 10 @@ -186,7 +186,7 @@ - id: 16 type: 0 # gitea pull request - status: 2 # mergable + status: 2 # mergeable issue_id: 28 index: 1 head_repo_id: 11 From 3a96038f71111a422842a112a85f58fe68aaf253 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 14 May 2024 00:50:24 +0000 Subject: [PATCH 78/97] pre auto generate test data --- models/fixtures/access.yml | 6 +- models/fixtures/branch.yml | 230 +----------------------- models/fixtures/collaboration.yml | 6 + models/fixtures/issue.yml | 102 ----------- models/fixtures/pull_request.yml | 78 -------- models/fixtures/repository.yml | 60 ------- models/fixtures/team.yml | 12 +- models/fixtures/team_unit.yml | 2 +- models/git/branch_test.go | 88 --------- tests/integration/empty_repo_test.go | 13 ++ tests/integration/integration_test.go | 9 + tests/integration/pull_compare_test.go | 2 +- tests/integration/pull_create_test.go | 6 +- tests/integration/pull_merge_test.go | 26 +-- tests/integration/pull_review_test.go | 2 +- tests/integration/pull_status_test.go | 6 +- tests/integration/repo_activity_test.go | 2 +- tests/integration/repo_branch_test.go | 171 +++++++++++++++++- tests/integration/repo_fork_test.go | 13 +- 19 files changed, 237 insertions(+), 597 deletions(-) diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index 681d6a93841eb..f27810f9e7ff8 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -60,9 +60,9 @@ - id: 11 - user_id: 12 - repo_id: 62 - mode: 4 + user_id: 13 + repo_id: 10 + mode: 2 - id: 12 diff --git a/models/fixtures/branch.yml b/models/fixtures/branch.yml index 2e7c5838dd46b..c7bdff7733995 100644 --- a/models/fixtures/branch.yml +++ b/models/fixtures/branch.yml @@ -61,99 +61,15 @@ - id: 6 repo_id: 10 - name: 'new-commit' + name: 'outdated-new-branch' commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' commit_message: 'add' - commit_time: 1489927680 - pusher_id: 12 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 7 - repo_id: 10 - name: 'no-commit' - commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' - commit_message: 'Initial commit' commit_time: 1489927679 pusher_id: 12 is_deleted: false deleted_by_id: 0 deleted_unix: 0 -- - id: 8 - repo_id: 10 - name: 'opening-pr' - commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' - commit_message: 'add' - commit_time: 1489927680 - pusher_id: 12 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 9 - repo_id: 10 - name: 'closed-pr' - commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' - commit_message: 'add' - commit_time: 1489927680 - pusher_id: 12 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 10 - repo_id: 10 - name: 'merged-pr' - commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' - commit_message: 'add' - commit_time: 1489927680 - pusher_id: 12 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 11 - repo_id: 10 - name: 'closed-pr-with-deleted-branch' - commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' - commit_message: 'add' - commit_time: 1489927680 - pusher_id: 12 - is_deleted: true - deleted_by_id: 12 - deleted_unix: 1489927700 - -- - id: 12 - repo_id: 10 - name: 'merged-pr-with-deleted-branch' - commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' - commit_message: 'add' - commit_time: 1489927680 - pusher_id: 12 - is_deleted: true - deleted_by_id: 12 - deleted_unix: 1489927700 - -- - id: 13 - repo_id: 10 - name: 'deleted-branch' - commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' - commit_message: 'add' - commit_time: 1489927680 - pusher_id: 12 - is_deleted: true - deleted_by_id: 12 - deleted_unix: 1489927700 - - id: 14 repo_id: 11 @@ -165,147 +81,3 @@ is_deleted: false deleted_by_id: 0 deleted_unix: 0 - -- - id: 15 - repo_id: 11 - name: 'user-fork-new-commit' - commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' - commit_message: 'add' - commit_time: 1489927680 - pusher_id: 13 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 16 - repo_id: 11 - name: 'user-fork-no-commit' - commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' - commit_message: 'Initial commit' - commit_time: 1489927679 - pusher_id: 13 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 17 - repo_id: 62 - name: 'master' - commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' - commit_message: 'Initial commit' - commit_time: 1489927679 - pusher_id: 12 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 18 - repo_id: 62 - name: 'org-fork-new-commit' - commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' - commit_message: 'add' - commit_time: 1489927691 - pusher_id: 12 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 19 - repo_id: 62 - name: 'org-fork-no-commit' - commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' - commit_message: 'Initial commit' - commit_time: 1489927691 - pusher_id: 12 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 20 - repo_id: 63 - name: 'master' - commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' - commit_message: 'Initial commit' - commit_time: 1489927679 - pusher_id: 1 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 21 - repo_id: 63 - name: 'private-org-fork-new-commit' - commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' - commit_message: 'add' - commit_time: 1489927680 - pusher_id: 1 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 22 - repo_id: 63 - name: 'private-org-fork-no-commit' - commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' - commit_message: 'Initial commit' - commit_time: 1489927679 - pusher_id: 1 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 23 - repo_id: 63 - name: 'private-org-fork-no-permission-new-commit' - commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' - commit_message: 'add' - commit_time: 1489927680 - pusher_id: 2 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 24 - repo_id: 63 - name: 'private-org-fork-no-permission-no-commit' - commit_id: '65f1bf27bc3bf70f64657658635e66094edbcb4d' - commit_message: 'Initial commit' - commit_time: 1489927679 - pusher_id: 2 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 25 - repo_id: 10 - name: 'same-name-branch-in-pr' - commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' - commit_message: 'add' - commit_time: 1489927680 - pusher_id: 13 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 - -- - id: 26 - repo_id: 11 - name: 'same-name-branch-in-pr' - commit_id: 'cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d' - commit_message: 'add' - commit_time: 1489927680 - pusher_id: 13 - is_deleted: false - deleted_by_id: 0 - deleted_unix: 0 diff --git a/models/fixtures/collaboration.yml b/models/fixtures/collaboration.yml index 4c3ac367f6b59..244e41be3a505 100644 --- a/models/fixtures/collaboration.yml +++ b/models/fixtures/collaboration.yml @@ -63,3 +63,9 @@ repo_id: 32 user_id: 10 mode: 2 # write + +- + id: 12 + repo_id: 10 + user_id: 13 + mode: 2 # write \ No newline at end of file diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index c6c5f27fdcdb5..ca5b1c6cd1df5 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -372,105 +372,3 @@ created_unix: 1707270422 updated_unix: 1707270422 is_locked: false - -- - id: 23 - repo_id: 10 - index: 2 - poster_id: 12 - original_author_id: 0 - name: opening pr for recently new branch search test - content: content - milestone_id: 0 - priority: 0 - is_closed: false - is_pull: true - num_comments: 0 - created_unix: 946684830 - updated_unix: 978307200 - is_locked: false - -- - id: 24 - repo_id: 10 - index: 3 - poster_id: 12 - original_author_id: 0 - name: closed pr for recently new branch search test - content: content - milestone_id: 0 - priority: 0 - is_closed: true - is_pull: true - num_comments: 0 - created_unix: 946684830 - updated_unix: 978307200 - is_locked: false - -- - id: 25 - repo_id: 10 - index: 4 - poster_id: 12 - original_author_id: 0 - name: merged pr for recently new branch search test - content: content - milestone_id: 0 - priority: 0 - is_closed: false - is_pull: true - num_comments: 0 - created_unix: 946684830 - updated_unix: 978307200 - is_locked: false - -- - id: 26 - repo_id: 10 - index: 5 - poster_id: 12 - original_author_id: 0 - name: closed pr with deleted branch for recently new branch search test - content: content - milestone_id: 0 - priority: 0 - is_closed: true - is_pull: true - num_comments: 0 - created_unix: 946684830 - updated_unix: 978307200 - is_locked: false - -- - id: 27 - repo_id: 10 - index: 6 - poster_id: 12 - original_author_id: 0 - name: merged pr with deleted branch for recently new branch search test - content: content - milestone_id: 0 - priority: 0 - is_closed: false - is_pull: true - num_comments: 0 - created_unix: 946684830 - updated_unix: 978307200 - is_locked: false - -- - id: 28 - repo_id: 11 - index: 1 - poster_id: 13 - original_author_id: 0 - name: pr with same branch name for recently new branch search test - content: content - milestone_id: 0 - priority: 0 - is_closed: false - is_pull: true - num_comments: 0 - created_unix: 946684830 - updated_unix: 978307200 - is_locked: false diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index 03cce53063912..9a16316e5a2b4 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -117,81 +117,3 @@ index: 1 head_repo_id: 61 base_repo_id: 61 - -- - id: 11 - type: 0 # gitea pull request - status: 2 # mergeable - issue_id: 23 - index: 2 - head_repo_id: 10 - base_repo_id: 10 - head_branch: opening-pr - base_branch: master - merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d - has_merged: false - -- - id: 12 - type: 0 # gitea pull request - status: 2 # mergeable - issue_id: 24 - index: 3 - head_repo_id: 10 - base_repo_id: 10 - head_branch: closed-pr - base_branch: master - merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d - has_merged: false - -- - id: 13 - type: 0 # gitea pull request - status: 3 # manually merged - issue_id: 25 - index: 4 - head_repo_id: 10 - base_repo_id: 10 - head_branch: merged-pr - base_branch: master - merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d - has_merged: true - -- - id: 14 - type: 0 # gitea pull request - status: 2 # mergeable - issue_id: 26 - index: 5 - head_repo_id: 10 - base_repo_id: 10 - head_branch: closed-pr-with-deleted-branch - base_branch: master - merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d - has_merged: false - -- - id: 15 - type: 0 # gitea pull request - status: 3 # manually merged - issue_id: 27 - index: 6 - head_repo_id: 10 - base_repo_id: 10 - head_branch: merged-pr-with-deleted-branch - base_branch: master - merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d - has_merged: true - -- - id: 16 - type: 0 # gitea pull request - status: 2 # mergeable - issue_id: 28 - index: 1 - head_repo_id: 11 - base_repo_id: 10 - head_branch: same-name-branch-in-pr - base_branch: master - merge_base: cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d - has_merged: false diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index f1045bce3f06f..73d7179a62d57 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -1768,63 +1768,3 @@ size: 0 is_fsck_enabled: true close_issues_via_commit_in_any_branch: false - -- - id: 62 - owner_id: 25 - owner_name: org25 - lower_name: org_fork_repo62 - name: org_fork_repo62 - num_watches: 0 - num_stars: 0 - num_forks: 0 - num_issues: 0 - num_closed_issues: 0 - num_pulls: 0 - num_closed_pulls: 0 - num_milestones: 0 - num_closed_milestones: 0 - num_projects: 0 - num_closed_projects: 0 - is_private: false - is_empty: false - is_archived: false - is_mirror: false - status: 0 - is_fork: true - fork_id: 10 - is_template: false - template_id: 0 - size: 0 - is_fsck_enabled: true - close_issues_via_commit_in_any_branch: false - -- - id: 63 - owner_id: 35 - owner_name: private_org35 - lower_name: private_org_fork_repo63 - name: private_org_fork_repo63 - num_watches: 0 - num_stars: 0 - num_forks: 0 - num_issues: 0 - num_closed_issues: 0 - num_pulls: 0 - num_closed_pulls: 0 - num_milestones: 0 - num_closed_milestones: 0 - num_projects: 0 - num_closed_projects: 0 - is_private: true - is_empty: false - is_archived: false - is_mirror: false - status: 0 - is_fork: true - fork_id: 10 - is_template: false - template_id: 0 - size: 0 - is_fsck_enabled: true - close_issues_via_commit_in_any_branch: false diff --git a/models/fixtures/team.yml b/models/fixtures/team.yml index 8040d907405b0..b549d0589bc9e 100644 --- a/models/fixtures/team.yml +++ b/models/fixtures/team.yml @@ -191,7 +191,7 @@ lower_name: owners name: Owners authorize: 4 # owner - num_repos: 1 + num_repos: 0 num_members: 1 includes_all_repositories: false can_create_org_repo: true @@ -254,10 +254,10 @@ - id: 24 org_id: 35 - lower_name: team24noreadcode - name: team24noreadcode - authorize: 0 # no access - num_repos: 1 + lower_name: team24 + name: team24 + authorize: 2 # write + num_repos: 0 num_members: 1 - includes_all_repositories: false + includes_all_repositories: true can_create_org_repo: false diff --git a/models/fixtures/team_unit.yml b/models/fixtures/team_unit.yml index eb8646b6863a8..110019eee30cf 100644 --- a/models/fixtures/team_unit.yml +++ b/models/fixtures/team_unit.yml @@ -339,4 +339,4 @@ id: 57 team_id: 24 type: 1 # code - access_mode: 0 + access_mode: 2 diff --git a/models/git/branch_test.go b/models/git/branch_test.go index 1092ca521cc14..b8ea663e81cef 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -12,7 +12,6 @@ import ( issues_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" - user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/optional" @@ -184,90 +183,3 @@ func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, deletedBranch) } - -func TestFindRecentlyPushedNewBranches(t *testing.T) { - assert.NoError(t, unittest.PrepareTestDatabase()) - - repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10}) - user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) - user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) - user12 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 12}) - user13 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 13}) - - tests := []struct { - name string - opts *git_model.FindRecentlyPushedNewBranchesOptions - count int - want []string - }{ - // user12 is the owner of the repo10 and the organization org25 - // in repo10, user12 has opening/closed/merged pr and closed/merged pr with deleted branch - { - name: "new branch of the repo, org fork repo, pr branches and deleted branch", - opts: &git_model.FindRecentlyPushedNewBranchesOptions{ - Actor: user12, - CommitAfterUnix: 1489927670, - MaxCount: 10, - }, - count: 2, - want: []string{"new-commit", "org25/org_fork_repo62:org-fork-new-commit"}, - }, - // user13 pushed 2 branches with the same name in repo10 and repo11 - // and repo11's branch has a pr, but repo10's branch doesn't - // in this case, we should get repo10's branch but not repo11's branch - { - name: "new branch from user fork repo and same name branch", - opts: &git_model.FindRecentlyPushedNewBranchesOptions{ - Actor: user13, - CommitAfterUnix: 1489927670, - MaxCount: 10, - }, - count: 2, - want: []string{"user13/repo11:user-fork-new-commit", "same-name-branch-in-pr"}, - }, - // user1 is the owner of private_org35 - { - name: "new branch from private org with code permission repo", - opts: &git_model.FindRecentlyPushedNewBranchesOptions{ - Actor: user1, - CommitAfterUnix: 1489927670, - }, - count: 1, - want: []string{"private_org35/private_org_fork_repo63:private-org-fork-new-commit"}, - }, - // user2 does not have code permission in private_org35 - { - name: "new branch from private org with no code permission repo", - opts: &git_model.FindRecentlyPushedNewBranchesOptions{ - Actor: user2, - CommitAfterUnix: 1489927670, - }, - count: 0, - want: []string{}, - }, - { - name: "test commitAfterUnix option", - opts: &git_model.FindRecentlyPushedNewBranchesOptions{ - Actor: user12, - CommitAfterUnix: 1489927690, - }, - count: 1, - want: []string{"org25/org_fork_repo62:org-fork-new-commit"}, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - tt.opts.Repo = repo - tt.opts.BaseRepo = repo - branches, err := git_model.FindRecentlyPushedNewBranches(db.DefaultContext, tt.opts) - - assert.NoError(t, err) - assert.Equal(t, tt.count, len(branches)) - - for i := 0; i < tt.count; i++ { - assert.Equal(t, tt.want[i], branches[i].BranchDisplayName) - } - }) - } -} diff --git a/tests/integration/empty_repo_test.go b/tests/integration/empty_repo_test.go index ea393a606167a..002aa5600e08b 100644 --- a/tests/integration/empty_repo_test.go +++ b/tests/integration/empty_repo_test.go @@ -6,9 +6,11 @@ package integration import ( "bytes" "encoding/base64" + "fmt" "io" "mime/multipart" "net/http" + "net/http/httptest" "testing" auth_model "code.gitea.io/gitea/models/auth" @@ -24,6 +26,17 @@ import ( "github.com/stretchr/testify/assert" ) +func testAPINewFile(t *testing.T, session *TestSession, user, repo, branch, treePath, content string) *httptest.ResponseRecorder { + url := fmt.Sprintf("/%s/%s/_new/%s", user, repo, branch) + req := NewRequestWithValues(t, "POST", url, map[string]string{ + "_csrf": GetCSRF(t, session, "/user/settings"), + "commit_choice": "direct", + "tree_path": treePath, + "content": content, + }) + return session.MakeRequest(t, req, http.StatusSeeOther) +} + func TestEmptyRepo(t *testing.T) { defer tests.PrepareTestEnv(t)() subPaths := []string{ diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index f9bd352b6221c..18f415083c9e6 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -485,6 +485,7 @@ func VerifyJSONSchema(t testing.TB, resp *httptest.ResponseRecorder, schemaFile assert.True(t, result.Valid()) } +// GetCSRF returns CSRF token from body func GetCSRF(t testing.TB, session *TestSession, urlStr string) string { t.Helper() req := NewRequest(t, "GET", urlStr) @@ -492,3 +493,11 @@ func GetCSRF(t testing.TB, session *TestSession, urlStr string) string { doc := NewHTMLParser(t, resp.Body) return doc.GetCSRF() } + +// GetCSRFFrom returns CSRF token from body +func GetCSRFFromCookie(t testing.TB, session *TestSession, urlStr string) string { + t.Helper() + req := NewRequest(t, "GET", urlStr) + session.MakeRequest(t, req, http.StatusOK) + return session.GetCookie("_csrf").Value +} diff --git a/tests/integration/pull_compare_test.go b/tests/integration/pull_compare_test.go index 39d9103dfd9f7..aed699fd20018 100644 --- a/tests/integration/pull_compare_test.go +++ b/tests/integration/pull_compare_test.go @@ -45,7 +45,7 @@ func TestPullCompare(t *testing.T) { defer tests.PrepareTestEnv(t)() session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testCreateBranch(t, session, "user1", "repo1", "branch/master", "master1", http.StatusSeeOther) testEditFile(t, session, "user1", "repo1", "master1", "README.md", "Hello, World (Edited)\n") testPullCreate(t, session, "user1", "repo1", false, "master", "master1", "This is a pull title") diff --git a/tests/integration/pull_create_test.go b/tests/integration/pull_create_test.go index 7add8e1db6516..5a06a7817f661 100644 --- a/tests/integration/pull_create_test.go +++ b/tests/integration/pull_create_test.go @@ -85,7 +85,7 @@ func testPullCreateDirectly(t *testing.T, session *TestSession, baseRepoOwner, b func TestPullCreate(t *testing.T) { onGiteaRun(t, func(t *testing.T, u *url.URL) { session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") resp := testPullCreate(t, session, "user1", "repo1", false, "master", "master", "This is a pull title") @@ -113,7 +113,7 @@ func TestPullCreate(t *testing.T) { func TestPullCreate_TitleEscape(t *testing.T) { onGiteaRun(t, func(t *testing.T, u *url.URL) { session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") resp := testPullCreate(t, session, "user1", "repo1", false, "master", "master", "XSS PR") @@ -177,7 +177,7 @@ func TestPullBranchDelete(t *testing.T) { defer tests.PrepareTestEnv(t)() session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testCreateBranch(t, session, "user1", "repo1", "branch/master", "master1", http.StatusSeeOther) testEditFile(t, session, "user1", "repo1", "master1", "README.md", "Hello, World (Edited)\n") resp := testPullCreate(t, session, "user1", "repo1", false, "master", "master1", "This is a pull title") diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go index 826568caf2b4f..2ac88fed93e54 100644 --- a/tests/integration/pull_merge_test.go +++ b/tests/integration/pull_merge_test.go @@ -89,7 +89,7 @@ func TestPullMerge(t *testing.T) { hookTasksLenBefore := len(hookTasks) session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") resp := testPullCreate(t, session, "user1", "repo1", false, "master", "master", "This is a pull title") @@ -111,7 +111,7 @@ func TestPullRebase(t *testing.T) { hookTasksLenBefore := len(hookTasks) session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") resp := testPullCreate(t, session, "user1", "repo1", false, "master", "master", "This is a pull title") @@ -133,7 +133,7 @@ func TestPullRebaseMerge(t *testing.T) { hookTasksLenBefore := len(hookTasks) session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") resp := testPullCreate(t, session, "user1", "repo1", false, "master", "master", "This is a pull title") @@ -155,7 +155,7 @@ func TestPullSquash(t *testing.T) { hookTasksLenBefore := len(hookTasks) session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited!)\n") @@ -174,7 +174,7 @@ func TestPullSquash(t *testing.T) { func TestPullCleanUpAfterMerge(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFileToNewBranch(t, session, "user1", "repo1", "master", "feature/test", "README.md", "Hello, World (Edited - TestPullCleanUpAfterMerge)\n") resp := testPullCreate(t, session, "user1", "repo1", false, "master", "feature/test", "This is a pull title") @@ -209,7 +209,7 @@ func TestPullCleanUpAfterMerge(t *testing.T) { func TestCantMergeWorkInProgress(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") resp := testPullCreate(t, session, "user1", "repo1", false, "master", "master", "[wip] This is a pull title") @@ -228,7 +228,7 @@ func TestCantMergeWorkInProgress(t *testing.T) { func TestCantMergeConflict(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFileToNewBranch(t, session, "user1", "repo1", "master", "conflict", "README.md", "Hello, World (Edited Once)\n") testEditFileToNewBranch(t, session, "user1", "repo1", "master", "base", "README.md", "Hello, World (Edited Twice)\n") @@ -274,7 +274,7 @@ func TestCantMergeConflict(t *testing.T) { func TestCantMergeUnrelated(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFileToNewBranch(t, session, "user1", "repo1", "master", "base", "README.md", "Hello, World (Edited Twice)\n") // Now we want to create a commit on a branch that is totally unrelated to our current head @@ -369,7 +369,7 @@ func TestCantMergeUnrelated(t *testing.T) { func TestFastForwardOnlyMerge(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFileToNewBranch(t, session, "user1", "repo1", "master", "update", "README.md", "Hello, World 2\n") // Use API to create a pr from update to master @@ -410,7 +410,7 @@ func TestFastForwardOnlyMerge(t *testing.T) { func TestCantFastForwardOnlyMergeDiverging(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFileToNewBranch(t, session, "user1", "repo1", "master", "diverging", "README.md", "Hello, World diverged\n") testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World 2\n") @@ -533,7 +533,7 @@ func TestPullRetargetChildOnBranchDelete(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { session := loginUser(t, "user1") testEditFileToNewBranch(t, session, "user2", "repo1", "master", "base-pr", "README.md", "Hello, World\n(Edited - TestPullRetargetOnCleanup - base PR)\n") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFileToNewBranch(t, session, "user1", "repo1", "base-pr", "child-pr", "README.md", "Hello, World\n(Edited - TestPullRetargetOnCleanup - base PR)\n(Edited - TestPullRetargetOnCleanup - child PR)") respBasePR := testPullCreate(t, session, "user2", "repo1", true, "master", "base-pr", "Base Pull Request") @@ -562,7 +562,7 @@ func TestPullRetargetChildOnBranchDelete(t *testing.T) { func TestPullDontRetargetChildOnWrongRepo(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFileToNewBranch(t, session, "user1", "repo1", "master", "base-pr", "README.md", "Hello, World\n(Edited - TestPullDontRetargetChildOnWrongRepo - base PR)\n") testEditFileToNewBranch(t, session, "user1", "repo1", "base-pr", "child-pr", "README.md", "Hello, World\n(Edited - TestPullDontRetargetChildOnWrongRepo - base PR)\n(Edited - TestPullDontRetargetChildOnWrongRepo - child PR)") @@ -593,7 +593,7 @@ func TestPullMergeIndexerNotifier(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { // create a pull request session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") createPullResp := testPullCreate(t, session, "user1", "repo1", false, "master", "master", "Indexer notifier test pull") diff --git a/tests/integration/pull_review_test.go b/tests/integration/pull_review_test.go index 273332a36b416..a5fbfd1e1502b 100644 --- a/tests/integration/pull_review_test.go +++ b/tests/integration/pull_review_test.go @@ -186,7 +186,7 @@ func TestPullView_GivenApproveOrRejectReviewOnClosedPR(t *testing.T) { user2Session := loginUser(t, "user2") // Have user1 create a fork of repo1. - testRepoFork(t, user1Session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, user1Session, "user2", "repo1", "user1", "repo1", "") t.Run("Submit approve/reject review on merged PR", func(t *testing.T) { // Create a merged PR (made by user1) in the upstream repo1. diff --git a/tests/integration/pull_status_test.go b/tests/integration/pull_status_test.go index 80eea34513f32..26e1baeb11305 100644 --- a/tests/integration/pull_status_test.go +++ b/tests/integration/pull_status_test.go @@ -23,7 +23,7 @@ import ( func TestPullCreate_CommitStatus(t *testing.T) { onGiteaRun(t, func(t *testing.T, u *url.URL) { session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFileToNewBranch(t, session, "user1", "repo1", "master", "status1", "README.md", "status1") url := path.Join("user1", "repo1", "compare", "master...status1") @@ -122,7 +122,7 @@ func TestPullCreate_EmptyChangesWithDifferentCommits(t *testing.T) { // so we need to have this meta commit also in develop branch. onGiteaRun(t, func(t *testing.T, u *url.URL) { session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFileToNewBranch(t, session, "user1", "repo1", "master", "status1", "README.md", "status1") testEditFileToNewBranch(t, session, "user1", "repo1", "status1", "status1", "README.md", "# repo1\n\nDescription for repo1") @@ -147,7 +147,7 @@ func TestPullCreate_EmptyChangesWithDifferentCommits(t *testing.T) { func TestPullCreate_EmptyChangesWithSameCommits(t *testing.T) { onGiteaRun(t, func(t *testing.T, u *url.URL) { session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testCreateBranch(t, session, "user1", "repo1", "branch/master", "status1", http.StatusSeeOther) url := path.Join("user1", "repo1", "compare", "master...status1") req := NewRequestWithValues(t, "POST", url, diff --git a/tests/integration/repo_activity_test.go b/tests/integration/repo_activity_test.go index 792554db4bc93..b04560379d2cd 100644 --- a/tests/integration/repo_activity_test.go +++ b/tests/integration/repo_activity_test.go @@ -20,7 +20,7 @@ func TestRepoActivity(t *testing.T) { session := loginUser(t, "user1") // Create PRs (1 merged & 2 proposed) - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") resp := testPullCreate(t, session, "user1", "repo1", false, "master", "master", "This is a pull title") elem := strings.Split(test.RedirectURL(resp), "/") diff --git a/tests/integration/repo_branch_test.go b/tests/integration/repo_branch_test.go index baa8da4b75956..7d953a6021f4b 100644 --- a/tests/integration/repo_branch_test.go +++ b/tests/integration/repo_branch_test.go @@ -4,26 +4,37 @@ package integration import ( + "fmt" "net/http" "net/url" "path" "strings" "testing" + auth_model "code.gitea.io/gitea/models/auth" + org_model "code.gitea.io/gitea/models/organization" + "code.gitea.io/gitea/models/perm" + repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/models/unit" + "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/modules/setting" + api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/tests" + "github.com/PuerkitoBio/goquery" "github.com/stretchr/testify/assert" ) func testCreateBranch(t testing.TB, session *TestSession, user, repo, oldRefSubURL, newBranchName string, expectedStatus int) string { var csrf string if expectedStatus == http.StatusNotFound { - csrf = GetCSRF(t, session, path.Join(user, repo, "src/branch/master")) + // src/branch/branch_name may not container "_csrf" input, + // so we need to get it from cookies not from body + csrf = GetCSRFFromCookie(t, session, path.Join(user, repo, "src/branch/master")) } else { - csrf = GetCSRF(t, session, path.Join(user, repo, "src", oldRefSubURL)) + csrf = GetCSRFFromCookie(t, session, path.Join(user, repo, "src", oldRefSubURL)) } req := NewRequestWithValues(t, "POST", path.Join(user, repo, "branches/_new", oldRefSubURL), map[string]string{ "_csrf": csrf, @@ -145,3 +156,159 @@ func TestCreateBranchInvalidCSRF(t *testing.T) { strings.TrimSpace(htmlDoc.doc.Find(".ui.message").Text()), ) } + +func prepareBranch(t *testing.T, session *TestSession, repo *repo_model.Repository) { + baseRefSubURL := fmt.Sprintf("branch/%s", repo.DefaultBranch) + + // create branch with no new commit + testCreateBranch(t, session, repo.OwnerName, repo.Name, baseRefSubURL, "no-commit", http.StatusSeeOther) + + // create branch with commit + testCreateBranch(t, session, repo.OwnerName, repo.Name, baseRefSubURL, "new-commit", http.StatusSeeOther) + testAPINewFile(t, session, repo.OwnerName, repo.Name, "new-commit", "new-commit.txt", "new-commit") + + // create deleted branch + testCreateBranch(t, session, repo.OwnerName, repo.Name, "branch/new-commit", "deleted-branch", http.StatusSeeOther) + testUIDeleteBranch(t, session, repo.OwnerName, repo.Name, "deleted-branch") + +} + +func testCreatePullToDefaultBranch(t *testing.T, session *TestSession, baseRepo, headRepo *repo_model.Repository, headBranch, title string) string { + srcRef := headBranch + if baseRepo.ID != headRepo.ID { + srcRef = fmt.Sprintf("%s/%s:%s", headRepo.OwnerName, headRepo.Name, headBranch) + } + resp := testPullCreate(t, session, baseRepo.OwnerName, baseRepo.Name, false, baseRepo.DefaultBranch, srcRef, title) + elem := strings.Split(test.RedirectURL(resp), "/") + // return pull request ID + return elem[4] +} + +func prepareRepoPR(t *testing.T, baseSession, headSession *TestSession, baseRepo, headRepo *repo_model.Repository) { + // create opening PR + testCreateBranch(t, headSession, headRepo.OwnerName, headRepo.Name, "branch/new-commit", "opening-pr", http.StatusSeeOther) + testCreatePullToDefaultBranch(t, baseSession, baseRepo, headRepo, "opening-pr", "opening pr") + + // create closed PR + testCreateBranch(t, headSession, headRepo.OwnerName, headRepo.Name, "branch/new-commit", "closed-pr", http.StatusSeeOther) + prID := testCreatePullToDefaultBranch(t, baseSession, baseRepo, headRepo, "closed-pr", "closed pr") + testIssueClose(t, baseSession, baseRepo.OwnerName, baseRepo.Name, prID) + + // create closed PR with deleted branch + testCreateBranch(t, headSession, headRepo.OwnerName, headRepo.Name, "branch/new-commit", "closed-pr-deleted", http.StatusSeeOther) + prID = testCreatePullToDefaultBranch(t, baseSession, baseRepo, headRepo, "closed-pr-deleted", "closed pr with deleted branch") + testIssueClose(t, baseSession, baseRepo.OwnerName, baseRepo.Name, prID) + testUIDeleteBranch(t, headSession, headRepo.OwnerName, headRepo.Name, "closed-pr-deleted") + + // create merged PR + testCreateBranch(t, headSession, headRepo.OwnerName, headRepo.Name, "branch/new-commit", "merged-pr", http.StatusSeeOther) + prID = testCreatePullToDefaultBranch(t, baseSession, baseRepo, headRepo, "merged-pr", "merged pr") + testAPINewFile(t, headSession, headRepo.OwnerName, headRepo.Name, "merged-pr", fmt.Sprintf("new-commit-%s.txt", headRepo.Name), "new-commit") + testPullMerge(t, baseSession, baseRepo.OwnerName, baseRepo.Name, prID, repo_model.MergeStyleRebaseMerge, false) + + // create merged PR with deleted branch + testCreateBranch(t, headSession, headRepo.OwnerName, headRepo.Name, "branch/new-commit", "merged-pr-deleted", http.StatusSeeOther) + prID = testCreatePullToDefaultBranch(t, baseSession, baseRepo, headRepo, "merged-pr-deleted", "merged pr with deleted branch") + testAPINewFile(t, headSession, headRepo.OwnerName, headRepo.Name, "merged-pr-deleted", fmt.Sprintf("new-commit-%s-2.txt", headRepo.Name), "new-commit") + testPullMerge(t, baseSession, baseRepo.OwnerName, baseRepo.Name, prID, repo_model.MergeStyleRebaseMerge, true) +} + +func TestRecentlyPushedNewBranches(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + onGiteaRun(t, func(t *testing.T, u *url.URL) { + user1Session := loginUser(t, "user1") + user2Session := loginUser(t, "user2") + user12Session := loginUser(t, "user12") + user13Session := loginUser(t, "user13") + + // prepare branch and PRs in original repo + repo10 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 10}) + prepareBranch(t, user12Session, repo10) + prepareRepoPR(t, user12Session, user12Session, repo10, repo10) + + // outdated new branch should not be displayed + branches := make([]string, 0, 2) + req := NewRequest(t, "GET", "user12/repo10") + resp := user12Session.MakeRequest(t, req, http.StatusOK) + doc := NewHTMLParser(t, resp.Body) + doc.doc.Find(".ui.positive.message div a").Each(func(index int, branch *goquery.Selection) { + branches = append(branches, branch.Text()) + }) + assert.Equal(t, []string{"new-commit"}, branches) + + // create a fork repo in public org + testRepoFork(t, user12Session, repo10.OwnerName, repo10.Name, "org25", "org25_fork_repo10", "new-commit") + orgPublicForkRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: 25, Name: "org25_fork_repo10"}) + prepareRepoPR(t, user12Session, user12Session, repo10, orgPublicForkRepo) + + // user12 is the owner of the repo10 and the organization org25 + // in repo10, user12 has opening/closed/merged pr and closed/merged pr with deleted branch + branches = make([]string, 0, 2) + req = NewRequest(t, "GET", "user12/repo10") + resp = user12Session.MakeRequest(t, req, http.StatusOK) + doc = NewHTMLParser(t, resp.Body) + doc.doc.Find(".ui.positive.message div a").Each(func(index int, branch *goquery.Selection) { + branches = append(branches, branch.Text()) + }) + assert.Equal(t, []string{"org25/org25_fork_repo10:new-commit", "new-commit"}, branches) + + userForkRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 11}) + prepareBranch(t, user13Session, userForkRepo) + prepareRepoPR(t, user13Session, user13Session, repo10, userForkRepo) + + // create branch with same name in different repo by user13 + testCreateBranch(t, user13Session, repo10.OwnerName, repo10.Name, "branch/new-commit", "same-name-branch", http.StatusSeeOther) + testCreateBranch(t, user13Session, userForkRepo.OwnerName, userForkRepo.Name, "branch/new-commit", "same-name-branch", http.StatusSeeOther) + testCreatePullToDefaultBranch(t, user13Session, repo10, userForkRepo, "same-name-branch", "same name branch pr") + + // user13 pushed 2 branches with the same name in repo10 and repo11 + // and repo11's branch has a pr, but repo10's branch doesn't + // in this case, we should get repo10's branch but not repo11's branch + branches = make([]string, 0, 2) + req = NewRequest(t, "GET", "user12/repo10") + resp = user13Session.MakeRequest(t, req, http.StatusOK) + doc = NewHTMLParser(t, resp.Body) + doc.doc.Find(".ui.positive.message div a").Each(func(index int, branch *goquery.Selection) { + branches = append(branches, branch.Text()) + }) + assert.Equal(t, []string{"same-name-branch", "user13/repo11:new-commit"}, branches) + + // create a fork repo in private org + testRepoFork(t, user1Session, repo10.OwnerName, repo10.Name, "private_org35", "org35_fork_repo10", "new-commit") + orgPrivateForkRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: 35, Name: "org35_fork_repo10"}) + prepareRepoPR(t, user1Session, user1Session, repo10, orgPrivateForkRepo) + + // user1 is the owner of private_org35 and no write permission to repo10 + // so user1 can only see the branch in org35_fork_repo10 + branches = make([]string, 0, 2) + req = NewRequest(t, "GET", "user12/repo10") + resp = user1Session.MakeRequest(t, req, http.StatusOK) + doc = NewHTMLParser(t, resp.Body) + doc.doc.Find(".ui.positive.message div a").Each(func(index int, branch *goquery.Selection) { + branches = append(branches, branch.Text()) + }) + assert.Equal(t, []string{"private_org35/org35_fork_repo10:new-commit"}, branches) + + // user2 push a branch in private_org35 + testCreateBranch(t, user2Session, orgPrivateForkRepo.OwnerName, orgPrivateForkRepo.Name, "branch/new-commit", "user-no-permission", http.StatusSeeOther) + // convert write permission to read permission for code unit + token := getTokenForLoggedInUser(t, user1Session, auth_model.AccessTokenScopeWriteOrganization) + req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/teams/%d", 24), &api.EditTeamOption{ + Name: "team24", + UnitsMap: map[string]string{"repo.code": "read"}, + }).AddTokenAuth(token) + MakeRequest(t, req, http.StatusOK) + teamUnit := unittest.AssertExistsAndLoadBean(t, &org_model.TeamUnit{TeamID: 24, Type: unit.TypeCode}) + assert.Equal(t, perm.AccessModeRead, teamUnit.AccessMode) + // user2 should not see the branch + branches = make([]string, 0, 2) + req = NewRequest(t, "GET", "user12/repo10") + resp = user2Session.MakeRequest(t, req, http.StatusOK) + doc = NewHTMLParser(t, resp.Body) + doc.doc.Find(".ui.positive.message div a").Each(func(index int, branch *goquery.Selection) { + branches = append(branches, branch.Text()) + }) + assert.Empty(t, branches) + }) +} diff --git a/tests/integration/repo_fork_test.go b/tests/integration/repo_fork_test.go index ca5d61ecc2a90..feebebf062081 100644 --- a/tests/integration/repo_fork_test.go +++ b/tests/integration/repo_fork_test.go @@ -16,7 +16,7 @@ import ( "github.com/stretchr/testify/assert" ) -func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkOwnerName, forkRepoName string) *httptest.ResponseRecorder { +func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkOwnerName, forkRepoName, forkBranch string) *httptest.ResponseRecorder { forkOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{Name: forkOwnerName}) // Step0: check the existence of the to-fork repo @@ -41,9 +41,10 @@ func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkO _, exists = htmlDoc.doc.Find(fmt.Sprintf(".owner.dropdown .item[data-value=\"%d\"]", forkOwner.ID)).Attr("data-value") assert.True(t, exists, fmt.Sprintf("Fork owner '%s' is not present in select box", forkOwnerName)) req = NewRequestWithValues(t, "POST", link, map[string]string{ - "_csrf": htmlDoc.GetCSRF(), - "uid": fmt.Sprintf("%d", forkOwner.ID), - "repo_name": forkRepoName, + "_csrf": htmlDoc.GetCSRF(), + "uid": fmt.Sprintf("%d", forkOwner.ID), + "repo_name": forkRepoName, + "fork_single_branch": forkBranch, }) session.MakeRequest(t, req, http.StatusSeeOther) @@ -57,13 +58,13 @@ func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkO func TestRepoFork(t *testing.T) { defer tests.PrepareTestEnv(t)() session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1", "") } func TestRepoForkToOrg(t *testing.T) { defer tests.PrepareTestEnv(t)() session := loginUser(t, "user2") - testRepoFork(t, session, "user2", "repo1", "org3", "repo1") + testRepoFork(t, session, "user2", "repo1", "org3", "repo1", "") // Check that no more forking is allowed as user2 owns repository // and org3 organization that owner user2 is also now has forked this repository From b65bad01d1d0af1f63a83e348c568275ee6c4896 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 14 May 2024 02:04:21 +0000 Subject: [PATCH 79/97] remove unused fixture --- models/fixtures/issue_index.yml | 2 +- models/fixtures/repo_unit.yml | 12 ------------ models/fixtures/repository.yml | 8 ++++---- models/fixtures/team_repo.yml | 12 ------------ models/fixtures/user.yml | 4 ++-- 5 files changed, 7 insertions(+), 31 deletions(-) diff --git a/models/fixtures/issue_index.yml b/models/fixtures/issue_index.yml index 27d2be824235f..5aabc08e388c5 100644 --- a/models/fixtures/issue_index.yml +++ b/models/fixtures/issue_index.yml @@ -12,7 +12,7 @@ - group_id: 10 - max_index: 6 + max_index: 1 - group_id: 32 diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index 244dea32cd768..8a22db0445c64 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -712,15 +712,3 @@ type: 3 config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}" created_unix: 946684810 - -- - id: 108 - repo_id: 62 - type: 1 - created_unix: 946684810 - -- - id: 109 - repo_id: 63 - type: 1 - created_unix: 946684810 diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 73d7179a62d57..e1f1dd73679b5 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -282,11 +282,11 @@ default_branch: master num_watches: 0 num_stars: 0 - num_forks: 3 + num_forks: 1 num_issues: 0 num_closed_issues: 0 - num_pulls: 6 - num_closed_pulls: 2 + num_pulls: 1 + num_closed_pulls: 0 num_milestones: 1 num_closed_milestones: 0 num_projects: 0 @@ -316,7 +316,7 @@ num_forks: 0 num_issues: 0 num_closed_issues: 0 - num_pulls: 1 + num_pulls: 0 num_closed_pulls: 0 num_milestones: 0 num_closed_milestones: 0 diff --git a/models/fixtures/team_repo.yml b/models/fixtures/team_repo.yml index 0a54d230d3520..a29078107eeb4 100644 --- a/models/fixtures/team_repo.yml +++ b/models/fixtures/team_repo.yml @@ -75,15 +75,3 @@ org_id: 41 team_id: 22 repo_id: 61 - -- - id: 14 - org_id: 35 - team_id: 18 - repo_id: 63 - -- - id: 15 - org_id: 35 - team_id: 24 - repo_id: 63 diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 72ac59f5faf45..8504d88ce5995 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -917,7 +917,7 @@ num_followers: 0 num_following: 0 num_stars: 0 - num_repos: 1 + num_repos: 0 num_teams: 2 num_members: 2 visibility: 0 @@ -1288,7 +1288,7 @@ num_followers: 0 num_following: 0 num_stars: 0 - num_repos: 1 + num_repos: 0 num_teams: 2 num_members: 2 visibility: 2 From b1a5d9e97d34e145cc4c13fa2080d9c599d0423b Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 14 May 2024 02:11:42 +0000 Subject: [PATCH 80/97] fix tests --- tests/integration/api_issue_test.go | 12 ++++++------ tests/integration/api_nodeinfo_test.go | 2 +- tests/integration/api_repo_test.go | 10 +++++----- tests/integration/issue_test.go | 12 ++++++------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/integration/api_issue_test.go b/tests/integration/api_issue_test.go index f0d435cec9514..8bfb6fabe2a49 100644 --- a/tests/integration/api_issue_test.go +++ b/tests/integration/api_issue_test.go @@ -227,7 +227,7 @@ func TestAPISearchIssues(t *testing.T) { defer tests.PrepareTestEnv(t)() // as this API was used in the frontend, it uses UI page size - expectedIssueCount := 24 // from the fixtures + expectedIssueCount := 20 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } @@ -251,7 +251,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 15) + assert.Len(t, apiIssues, 11) query.Del("since") query.Del("before") @@ -260,14 +260,14 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 4) + assert.Len(t, apiIssues, 2) query.Set("state", "all") link.RawQuery = query.Encode() req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "28", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "22", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 20) query.Add("limit", "10") @@ -275,7 +275,7 @@ func TestAPISearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()).AddTokenAuth(token) resp = MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "28", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "22", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 10) query = url.Values{"assigned": {"true"}, "state": {"all"}} @@ -325,7 +325,7 @@ func TestAPISearchIssuesWithLabels(t *testing.T) { defer tests.PrepareTestEnv(t)() // as this API was used in the frontend, it uses UI page size - expectedIssueCount := 24 // from the fixtures + expectedIssueCount := 20 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } diff --git a/tests/integration/api_nodeinfo_test.go b/tests/integration/api_nodeinfo_test.go index 24342180209fc..75f8dbb4ba3aa 100644 --- a/tests/integration/api_nodeinfo_test.go +++ b/tests/integration/api_nodeinfo_test.go @@ -33,7 +33,7 @@ func TestNodeinfo(t *testing.T) { assert.True(t, nodeinfo.OpenRegistrations) assert.Equal(t, "gitea", nodeinfo.Software.Name) assert.Equal(t, 29, nodeinfo.Usage.Users.Total) - assert.Equal(t, 28, nodeinfo.Usage.LocalPosts) + assert.Equal(t, 22, nodeinfo.Usage.LocalPosts) assert.Equal(t, 3, nodeinfo.Usage.LocalComments) }) } diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go index aab469853978d..716da762e542d 100644 --- a/tests/integration/api_repo_test.go +++ b/tests/integration/api_repo_test.go @@ -94,9 +94,9 @@ func TestAPISearchRepo(t *testing.T) { }{ { name: "RepositoriesMax50", requestURL: "/api/v1/repos/search?limit=50&private=false", expectedResults: expectedResults{ - nil: {count: 36}, - user: {count: 36}, - user2: {count: 36}, + nil: {count: 35}, + user: {count: 35}, + user2: {count: 35}, }, }, { @@ -276,8 +276,8 @@ func TestAPIViewRepo(t *testing.T) { DecodeJSON(t, resp, &repo) assert.EqualValues(t, 10, repo.ID) assert.EqualValues(t, "repo10", repo.Name) - assert.EqualValues(t, 4, repo.OpenPulls) - assert.EqualValues(t, 3, repo.Forks) + assert.EqualValues(t, 1, repo.OpenPulls) + assert.EqualValues(t, 1, repo.Forks) req = NewRequest(t, "GET", "/api/v1/repos/user5/repo4") resp = MakeRequest(t, req, http.StatusOK) diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 8d01ecb94d42d..d74516d110a61 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -408,7 +408,7 @@ func TestSearchIssues(t *testing.T) { session := loginUser(t, "user2") - expectedIssueCount := 24 // from the fixtures + expectedIssueCount := 20 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } @@ -429,7 +429,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 15) + assert.Len(t, apiIssues, 11) query.Del("since") query.Del("before") @@ -438,14 +438,14 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.Len(t, apiIssues, 4) + assert.Len(t, apiIssues, 2) query.Set("state", "all") link.RawQuery = query.Encode() req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "28", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "22", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 20) query.Add("limit", "5") @@ -453,7 +453,7 @@ func TestSearchIssues(t *testing.T) { req = NewRequest(t, "GET", link.String()) resp = session.MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &apiIssues) - assert.EqualValues(t, "28", resp.Header().Get("X-Total-Count")) + assert.EqualValues(t, "22", resp.Header().Get("X-Total-Count")) assert.Len(t, apiIssues, 5) query = url.Values{"assigned": {"true"}, "state": {"all"}} @@ -502,7 +502,7 @@ func TestSearchIssues(t *testing.T) { func TestSearchIssuesWithLabels(t *testing.T) { defer tests.PrepareTestEnv(t)() - expectedIssueCount := 24 // from the fixtures + expectedIssueCount := 20 // from the fixtures if expectedIssueCount > setting.UI.IssuePagingNum { expectedIssueCount = setting.UI.IssuePagingNum } From 1263116ed262a8274401c82e658e314593b65573 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 14 May 2024 02:59:20 +0000 Subject: [PATCH 81/97] improve test --- tests/integration/repo_branch_test.go | 59 ++++++++------------------- 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/tests/integration/repo_branch_test.go b/tests/integration/repo_branch_test.go index 7d953a6021f4b..bc9ba7a1e1bbc 100644 --- a/tests/integration/repo_branch_test.go +++ b/tests/integration/repo_branch_test.go @@ -170,7 +170,6 @@ func prepareBranch(t *testing.T, session *TestSession, repo *repo_model.Reposito // create deleted branch testCreateBranch(t, session, repo.OwnerName, repo.Name, "branch/new-commit", "deleted-branch", http.StatusSeeOther) testUIDeleteBranch(t, session, repo.OwnerName, repo.Name, "deleted-branch") - } func testCreatePullToDefaultBranch(t *testing.T, session *TestSession, baseRepo, headRepo *repo_model.Repository, headBranch, title string) string { @@ -213,6 +212,17 @@ func prepareRepoPR(t *testing.T, baseSession, headSession *TestSession, baseRepo testPullMerge(t, baseSession, baseRepo.OwnerName, baseRepo.Name, prID, repo_model.MergeStyleRebaseMerge, true) } +func checkRecentlyPushedNewBranches(t *testing.T, session *TestSession, repoPath string, expected []string) { + branches := make([]string, 0, 2) + req := NewRequest(t, "GET", repoPath) + resp := session.MakeRequest(t, req, http.StatusOK) + doc := NewHTMLParser(t, resp.Body) + doc.doc.Find(".ui.positive.message div a").Each(func(index int, branch *goquery.Selection) { + branches = append(branches, branch.Text()) + }) + assert.Equal(t, expected, branches) +} + func TestRecentlyPushedNewBranches(t *testing.T) { defer tests.PrepareTestEnv(t)() @@ -228,14 +238,7 @@ func TestRecentlyPushedNewBranches(t *testing.T) { prepareRepoPR(t, user12Session, user12Session, repo10, repo10) // outdated new branch should not be displayed - branches := make([]string, 0, 2) - req := NewRequest(t, "GET", "user12/repo10") - resp := user12Session.MakeRequest(t, req, http.StatusOK) - doc := NewHTMLParser(t, resp.Body) - doc.doc.Find(".ui.positive.message div a").Each(func(index int, branch *goquery.Selection) { - branches = append(branches, branch.Text()) - }) - assert.Equal(t, []string{"new-commit"}, branches) + checkRecentlyPushedNewBranches(t, user12Session, "user12/repo10", []string{"new-commit"}) // create a fork repo in public org testRepoFork(t, user12Session, repo10.OwnerName, repo10.Name, "org25", "org25_fork_repo10", "new-commit") @@ -244,14 +247,7 @@ func TestRecentlyPushedNewBranches(t *testing.T) { // user12 is the owner of the repo10 and the organization org25 // in repo10, user12 has opening/closed/merged pr and closed/merged pr with deleted branch - branches = make([]string, 0, 2) - req = NewRequest(t, "GET", "user12/repo10") - resp = user12Session.MakeRequest(t, req, http.StatusOK) - doc = NewHTMLParser(t, resp.Body) - doc.doc.Find(".ui.positive.message div a").Each(func(index int, branch *goquery.Selection) { - branches = append(branches, branch.Text()) - }) - assert.Equal(t, []string{"org25/org25_fork_repo10:new-commit", "new-commit"}, branches) + checkRecentlyPushedNewBranches(t, user12Session, "user12/repo10", []string{"org25/org25_fork_repo10:new-commit", "new-commit"}) userForkRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 11}) prepareBranch(t, user13Session, userForkRepo) @@ -265,14 +261,7 @@ func TestRecentlyPushedNewBranches(t *testing.T) { // user13 pushed 2 branches with the same name in repo10 and repo11 // and repo11's branch has a pr, but repo10's branch doesn't // in this case, we should get repo10's branch but not repo11's branch - branches = make([]string, 0, 2) - req = NewRequest(t, "GET", "user12/repo10") - resp = user13Session.MakeRequest(t, req, http.StatusOK) - doc = NewHTMLParser(t, resp.Body) - doc.doc.Find(".ui.positive.message div a").Each(func(index int, branch *goquery.Selection) { - branches = append(branches, branch.Text()) - }) - assert.Equal(t, []string{"same-name-branch", "user13/repo11:new-commit"}, branches) + checkRecentlyPushedNewBranches(t, user13Session, "user12/repo10", []string{"same-name-branch", "user13/repo11:new-commit"}) // create a fork repo in private org testRepoFork(t, user1Session, repo10.OwnerName, repo10.Name, "private_org35", "org35_fork_repo10", "new-commit") @@ -281,20 +270,13 @@ func TestRecentlyPushedNewBranches(t *testing.T) { // user1 is the owner of private_org35 and no write permission to repo10 // so user1 can only see the branch in org35_fork_repo10 - branches = make([]string, 0, 2) - req = NewRequest(t, "GET", "user12/repo10") - resp = user1Session.MakeRequest(t, req, http.StatusOK) - doc = NewHTMLParser(t, resp.Body) - doc.doc.Find(".ui.positive.message div a").Each(func(index int, branch *goquery.Selection) { - branches = append(branches, branch.Text()) - }) - assert.Equal(t, []string{"private_org35/org35_fork_repo10:new-commit"}, branches) + checkRecentlyPushedNewBranches(t, user1Session, "user12/repo10", []string{"private_org35/org35_fork_repo10:new-commit"}) // user2 push a branch in private_org35 testCreateBranch(t, user2Session, orgPrivateForkRepo.OwnerName, orgPrivateForkRepo.Name, "branch/new-commit", "user-no-permission", http.StatusSeeOther) // convert write permission to read permission for code unit token := getTokenForLoggedInUser(t, user1Session, auth_model.AccessTokenScopeWriteOrganization) - req = NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/teams/%d", 24), &api.EditTeamOption{ + req := NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/teams/%d", 24), &api.EditTeamOption{ Name: "team24", UnitsMap: map[string]string{"repo.code": "read"}, }).AddTokenAuth(token) @@ -302,13 +284,6 @@ func TestRecentlyPushedNewBranches(t *testing.T) { teamUnit := unittest.AssertExistsAndLoadBean(t, &org_model.TeamUnit{TeamID: 24, Type: unit.TypeCode}) assert.Equal(t, perm.AccessModeRead, teamUnit.AccessMode) // user2 should not see the branch - branches = make([]string, 0, 2) - req = NewRequest(t, "GET", "user12/repo10") - resp = user2Session.MakeRequest(t, req, http.StatusOK) - doc = NewHTMLParser(t, resp.Body) - doc.doc.Find(".ui.positive.message div a").Each(func(index int, branch *goquery.Selection) { - branches = append(branches, branch.Text()) - }) - assert.Empty(t, branches) + checkRecentlyPushedNewBranches(t, user2Session, "user12/repo10", []string{}) }) } From 73233221ff8dfe7bf79c2be865dce1bd5b269cbe Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 14 May 2024 04:05:42 +0000 Subject: [PATCH 82/97] create pr should have write permission --- routers/web/repo/view.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index da7f66a90aed0..a7dc2c8d9c5cc 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -1045,7 +1045,7 @@ func renderHomeCode(ctx *context.Context) { if !opts.Repo.IsMirror && !opts.BaseRepo.IsMirror && opts.BaseRepo.UnitEnabled(ctx, unit_model.TypePullRequests) && - baseRepoPerm.CanRead(unit_model.TypePullRequests) { + baseRepoPerm.CanWrite(unit_model.TypePullRequests) { ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, opts) if err != nil { ctx.ServerError("FindRecentlyPushedNewBranches", err) From 1f7b93cc79c20734a044ce8ba597a460cf1af79a Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 14 May 2024 04:13:18 +0000 Subject: [PATCH 83/97] fix lint --- models/fixtures/collaboration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/fixtures/collaboration.yml b/models/fixtures/collaboration.yml index 244e41be3a505..16447c9607ac5 100644 --- a/models/fixtures/collaboration.yml +++ b/models/fixtures/collaboration.yml @@ -68,4 +68,4 @@ id: 12 repo_id: 10 user_id: 13 - mode: 2 # write \ No newline at end of file + mode: 2 # write From 41a2bb25305541eaadf947e3f432e1819e5e66f7 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 14 May 2024 04:38:56 +0000 Subject: [PATCH 84/97] fix tests --- models/repo/repo_list_test.go | 6 +++--- modules/indexer/issues/indexer_test.go | 14 +++++++------- services/issue/issue_test.go | 5 ++--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/models/repo/repo_list_test.go b/models/repo/repo_list_test.go index ca6007f6c7882..88cfcde620832 100644 --- a/models/repo/repo_list_test.go +++ b/models/repo/repo_list_test.go @@ -138,12 +138,12 @@ func getTestCases() []struct { { name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: optional.Some(false)}, - count: 34, + count: 33, }, { name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: optional.Some(false)}, - count: 39, + count: 38, }, { name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName", @@ -158,7 +158,7 @@ func getTestCases() []struct { { name: "AllPublic/PublicRepositoriesOfOrganization", opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: optional.Some(false), Template: optional.Some(false)}, - count: 34, + count: 33, }, { name: "AllTemplates", diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index 4d6ad6903d6c7..0d0cfc851697d 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -215,7 +215,7 @@ func searchIssueIsPull(t *testing.T) { SearchOptions{ IsPull: optional.Some(true), }, - []int64{22, 21, 12, 11, 20, 28, 27, 26, 25, 24, 23, 19, 9, 8, 3, 2}, + []int64{22, 21, 12, 11, 20, 19, 9, 8, 3, 2}, }, } for _, test := range tests { @@ -236,13 +236,13 @@ func searchIssueIsClosed(t *testing.T) { SearchOptions{ IsClosed: optional.Some(false), }, - []int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 28, 27, 25, 23, 19, 18, 10, 7, 9, 8, 3, 2, 1}, + []int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 19, 18, 10, 7, 9, 8, 3, 2, 1}, }, { SearchOptions{ IsClosed: optional.Some(true), }, - []int64{5, 26, 24, 4}, + []int64{5, 4}, }, } for _, test := range tests { @@ -302,7 +302,7 @@ func searchIssueByLabelID(t *testing.T) { SearchOptions{ ExcludedLabelIDs: []int64{1}, }, - []int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 28, 27, 26, 25, 24, 23, 19, 18, 10, 7, 4, 9, 8, 3}, + []int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3}, }, } for _, test := range tests { @@ -323,7 +323,7 @@ func searchIssueByTime(t *testing.T) { SearchOptions{ UpdatedAfterUnix: optional.Some(int64(0)), }, - []int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 28, 27, 26, 25, 24, 23, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1}, + []int64{22, 21, 17, 16, 15, 14, 13, 12, 11, 20, 6, 5, 19, 18, 10, 7, 4, 9, 8, 3, 2, 1}, }, } for _, test := range tests { @@ -344,7 +344,7 @@ func searchIssueWithOrder(t *testing.T) { SearchOptions{ SortBy: internal.SortByCreatedAsc, }, - []int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 23, 24, 25, 26, 27, 28, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17, 21, 22}, + []int64{1, 2, 3, 8, 9, 4, 7, 10, 18, 19, 5, 6, 20, 11, 12, 13, 14, 15, 16, 17, 21, 22}, }, } for _, test := range tests { @@ -402,7 +402,7 @@ func searchIssueWithPaginator(t *testing.T) { }, }, []int64{22, 21, 17, 16, 15}, - 28, + 22, }, } for _, test := range tests { diff --git a/services/issue/issue_test.go b/services/issue/issue_test.go index 38735e1a8e8db..8806cec0e7c5d 100644 --- a/services/issue/issue_test.go +++ b/services/issue/issue_test.go @@ -35,10 +35,9 @@ func TestGetRefEndNamesAndURLs(t *testing.T) { func TestIssue_DeleteIssue(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - issueCount := 5 issueIDs, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1) assert.NoError(t, err) - assert.Len(t, issueIDs, issueCount) + assert.Len(t, issueIDs, 5) issue := &issues_model.Issue{ RepoID: 1, @@ -49,7 +48,7 @@ func TestIssue_DeleteIssue(t *testing.T) { assert.NoError(t, err) issueIDs, err = issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1) assert.NoError(t, err) - assert.Len(t, issueIDs, issueCount-1) + assert.Len(t, issueIDs, 4) // check attachment removal attachments, err := repo_model.GetAttachmentsByIssueID(db.DefaultContext, 4) From d99cf1abdee904665b7b89b562a7e993f8f5b745 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 14 May 2024 06:27:55 +0000 Subject: [PATCH 85/97] revert permission change --- routers/web/repo/view.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index a7dc2c8d9c5cc..da7f66a90aed0 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -1045,7 +1045,7 @@ func renderHomeCode(ctx *context.Context) { if !opts.Repo.IsMirror && !opts.BaseRepo.IsMirror && opts.BaseRepo.UnitEnabled(ctx, unit_model.TypePullRequests) && - baseRepoPerm.CanWrite(unit_model.TypePullRequests) { + baseRepoPerm.CanRead(unit_model.TypePullRequests) { ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, opts) if err != nil { ctx.ServerError("FindRecentlyPushedNewBranches", err) From 71556edade126f20b68941cdf8e0f2f57ef7c894 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 14 May 2024 06:30:05 +0000 Subject: [PATCH 86/97] fix test --- models/issues/issue_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go index e6724e27f9ce1..1bbc0eee564fd 100644 --- a/models/issues/issue_test.go +++ b/models/issues/issue_test.go @@ -379,7 +379,7 @@ func TestCountIssues(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) count, err := issues_model.CountIssues(db.DefaultContext, &issues_model.IssuesOptions{}) assert.NoError(t, err) - assert.EqualValues(t, 28, count) + assert.EqualValues(t, 22, count) } func TestIssueLoadAttributes(t *testing.T) { From 9fb523c6892bfb0f5a67a1470070452b4d8e76e1 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 14 May 2024 07:07:24 +0000 Subject: [PATCH 87/97] fix access --- models/fixtures/access.yml | 64 +++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index f27810f9e7ff8..0a90b97288a6a 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -1,185 +1,179 @@ - id: 1 - user_id: 1 - repo_id: 63 - mode: 4 - -- - id: 2 user_id: 2 repo_id: 3 mode: 4 - - id: 3 + id: 2 user_id: 2 repo_id: 5 mode: 4 - - id: 4 + id: 3 user_id: 2 repo_id: 24 mode: 2 - - id: 5 + id: 4 user_id: 2 repo_id: 32 mode: 4 - - id: 6 + id: 5 user_id: 4 repo_id: 3 mode: 2 - - id: 7 + id: 6 user_id: 4 repo_id: 4 mode: 2 - - id: 8 + id: 7 user_id: 4 repo_id: 40 mode: 2 - - id: 9 + id: 8 user_id: 10 repo_id: 21 mode: 2 - - id: 10 + id: 9 user_id: 10 repo_id: 32 mode: 2 - - id: 11 + id: 10 user_id: 13 repo_id: 10 mode: 2 - - id: 12 + id: 11 user_id: 15 repo_id: 21 mode: 2 - - id: 13 + id: 12 user_id: 15 repo_id: 22 mode: 2 - - id: 14 + id: 13 user_id: 15 repo_id: 23 mode: 4 - - id: 15 + id: 14 user_id: 15 repo_id: 24 mode: 4 - - id: 16 + id: 15 user_id: 15 repo_id: 32 mode: 2 - - id: 17 + id: 16 user_id: 18 repo_id: 21 mode: 2 - - id: 18 + id: 17 user_id: 18 repo_id: 22 mode: 2 - - id: 19 + id: 18 user_id: 18 repo_id: 23 mode: 4 - - id: 20 + id: 19 user_id: 18 repo_id: 24 mode: 4 - - id: 21 + id: 20 user_id: 20 repo_id: 24 mode: 1 - - id: 22 + id: 21 user_id: 20 repo_id: 27 mode: 4 - - id: 23 + id: 22 user_id: 20 repo_id: 28 mode: 4 - - id: 24 + id: 23 user_id: 29 repo_id: 4 mode: 2 - - id: 25 + id: 24 user_id: 29 repo_id: 24 mode: 1 - - id: 26 + id: 25 user_id: 31 repo_id: 27 mode: 4 - - id: 27 + id: 26 user_id: 31 repo_id: 28 mode: 4 - - id: 28 + id: 27 user_id: 38 repo_id: 60 mode: 2 - - id: 29 + id: 28 user_id: 38 repo_id: 61 mode: 1 - - id: 30 + id: 29 user_id: 39 repo_id: 61 mode: 1 - - id: 31 + id: 30 user_id: 40 repo_id: 61 mode: 4 From c6edde19ff2c595e245f187569fd9dd3e27ed61e Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 15 May 2024 00:37:31 +0000 Subject: [PATCH 88/97] when doer is nil, return empty branch --- models/git/branch.go | 14 ++++++++------ routers/web/repo/view.go | 3 +-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index 1da307df1a02c..8d08fa9b544b0 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -412,7 +412,6 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, from, to str } type FindRecentlyPushedNewBranchesOptions struct { - Actor *user_model.User Repo *repo_model.Repository BaseRepo *repo_model.Repository CommitAfterUnix int64 @@ -427,13 +426,16 @@ type RecentlyPushedNewBranch struct { } // FindRecentlyPushedNewBranches return at most 2 new branches pushed by the user in 2 hours which has no opened PRs created -// opts.Actor should not be nil // if opts.CommitAfterUnix is 0, we will find the branches that were committed to in the last 2 hours // if opts.ListOptions is not set, we will only display top 2 latest branch -func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushedNewBranchesOptions) ([]*RecentlyPushedNewBranch, error) { +func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, opts *FindRecentlyPushedNewBranchesOptions) ([]*RecentlyPushedNewBranch, error) { + if doer == nil { + return []*RecentlyPushedNewBranch{}, nil + } + // find all related repo ids repoOpts := repo_model.SearchRepoOptions{ - Actor: opts.Actor, + Actor: doer, Private: true, AllPublic: false, // Include also all public repositories of users and public organisations AllLimited: false, // Include also all public repositories of limited organisations @@ -441,7 +443,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed ForkFrom: opts.BaseRepo.ID, Archived: optional.Some(false), } - repoCond := repo_model.SearchRepositoryCondition(&repoOpts).And(repo_model.AccessibleRepositoryCondition(opts.Actor, unit.TypeCode)) + repoCond := repo_model.SearchRepositoryCondition(&repoOpts).And(repo_model.AccessibleRepositoryCondition(doer, unit.TypeCode)) if opts.Repo.ID == opts.BaseRepo.ID { // should also include the base repo's branches repoCond = repoCond.Or(builder.Eq{"id": opts.BaseRepo.ID}) @@ -464,7 +466,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, opts *FindRecentlyPushed branches, err := db.Find[Branch](ctx, FindBranchOptions{ RepoCond: builder.In("branch.repo_id", repoIDs), CommitCond: builder.Neq{"branch.commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them, - PusherID: opts.Actor.ID, + PusherID: doer.ID, IsDeletedBranch: optional.Some(false), CommitAfterUnix: opts.CommitAfterUnix, OrderBy: "branch.updated_unix DESC", diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index da7f66a90aed0..e1498c0d581e0 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -1029,7 +1029,6 @@ func renderHomeCode(ctx *context.Context) { } opts := &git_model.FindRecentlyPushedNewBranchesOptions{ - Actor: ctx.Doer, Repo: ctx.Repo.Repository, BaseRepo: ctx.Repo.Repository, } @@ -1046,7 +1045,7 @@ func renderHomeCode(ctx *context.Context) { if !opts.Repo.IsMirror && !opts.BaseRepo.IsMirror && opts.BaseRepo.UnitEnabled(ctx, unit_model.TypePullRequests) && baseRepoPerm.CanRead(unit_model.TypePullRequests) { - ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, opts) + ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, ctx.Doer, opts) if err != nil { ctx.ServerError("FindRecentlyPushedNewBranches", err) return From 4ed9e41766e1d00e4c992caa6854c193735a7152 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Wed, 15 May 2024 23:52:16 +0000 Subject: [PATCH 89/97] fix test --- tests/integration/repo_branch_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/repo_branch_test.go b/tests/integration/repo_branch_test.go index bc9ba7a1e1bbc..a4a56ca90d93a 100644 --- a/tests/integration/repo_branch_test.go +++ b/tests/integration/repo_branch_test.go @@ -273,7 +273,7 @@ func TestRecentlyPushedNewBranches(t *testing.T) { checkRecentlyPushedNewBranches(t, user1Session, "user12/repo10", []string{"private_org35/org35_fork_repo10:new-commit"}) // user2 push a branch in private_org35 - testCreateBranch(t, user2Session, orgPrivateForkRepo.OwnerName, orgPrivateForkRepo.Name, "branch/new-commit", "user-no-permission", http.StatusSeeOther) + testCreateBranch(t, user2Session, orgPrivateForkRepo.OwnerName, orgPrivateForkRepo.Name, "branch/new-commit", "user-read-permission", http.StatusSeeOther) // convert write permission to read permission for code unit token := getTokenForLoggedInUser(t, user1Session, auth_model.AccessTokenScopeWriteOrganization) req := NewRequestWithJSON(t, "PATCH", fmt.Sprintf("/api/v1/teams/%d", 24), &api.EditTeamOption{ @@ -283,7 +283,7 @@ func TestRecentlyPushedNewBranches(t *testing.T) { MakeRequest(t, req, http.StatusOK) teamUnit := unittest.AssertExistsAndLoadBean(t, &org_model.TeamUnit{TeamID: 24, Type: unit.TypeCode}) assert.Equal(t, perm.AccessModeRead, teamUnit.AccessMode) - // user2 should not see the branch - checkRecentlyPushedNewBranches(t, user2Session, "user12/repo10", []string{}) + // user2 can see the branch as it is created by user2 + checkRecentlyPushedNewBranches(t, user2Session, "user12/repo10", []string{"private_org35/org35_fork_repo10:user-read-permission"}) }) } From b1346d561c12890e89b985d4146d61a7d3164ce9 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 21 May 2024 00:48:11 +0000 Subject: [PATCH 90/97] use api to create collaborator --- models/fixtures/access.yml | 46 ++++++++++++--------------- models/fixtures/collaboration.yml | 6 ---- tests/integration/repo_branch_test.go | 2 ++ 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index 0a90b97288a6a..1dd4c4ead6b29 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -53,127 +53,121 @@ mode: 2 - - id: 10 - user_id: 13 - repo_id: 10 - mode: 2 - -- - id: 11 + id: 12 user_id: 15 repo_id: 21 mode: 2 - - id: 12 + id: 13 user_id: 15 repo_id: 22 mode: 2 - - id: 13 + id: 14 user_id: 15 repo_id: 23 mode: 4 - - id: 14 + id: 15 user_id: 15 repo_id: 24 mode: 4 - - id: 15 + id: 16 user_id: 15 repo_id: 32 mode: 2 - - id: 16 + id: 17 user_id: 18 repo_id: 21 mode: 2 - - id: 17 + id: 18 user_id: 18 repo_id: 22 mode: 2 - - id: 18 + id: 19 user_id: 18 repo_id: 23 mode: 4 - - id: 19 + id: 20 user_id: 18 repo_id: 24 mode: 4 - - id: 20 + id: 21 user_id: 20 repo_id: 24 mode: 1 - - id: 21 + id: 22 user_id: 20 repo_id: 27 mode: 4 - - id: 22 + id: 23 user_id: 20 repo_id: 28 mode: 4 - - id: 23 + id: 24 user_id: 29 repo_id: 4 mode: 2 - - id: 24 + id: 25 user_id: 29 repo_id: 24 mode: 1 - - id: 25 + id: 26 user_id: 31 repo_id: 27 mode: 4 - - id: 26 + id: 27 user_id: 31 repo_id: 28 mode: 4 - - id: 27 + id: 28 user_id: 38 repo_id: 60 mode: 2 - - id: 28 + id: 29 user_id: 38 repo_id: 61 mode: 1 - - id: 29 + id: 30 user_id: 39 repo_id: 61 mode: 1 - - id: 30 + id: 31 user_id: 40 repo_id: 61 mode: 4 diff --git a/models/fixtures/collaboration.yml b/models/fixtures/collaboration.yml index 16447c9607ac5..4c3ac367f6b59 100644 --- a/models/fixtures/collaboration.yml +++ b/models/fixtures/collaboration.yml @@ -63,9 +63,3 @@ repo_id: 32 user_id: 10 mode: 2 # write - -- - id: 12 - repo_id: 10 - user_id: 13 - mode: 2 # write diff --git a/tests/integration/repo_branch_test.go b/tests/integration/repo_branch_test.go index a4a56ca90d93a..d1bc9198c32f4 100644 --- a/tests/integration/repo_branch_test.go +++ b/tests/integration/repo_branch_test.go @@ -250,6 +250,8 @@ func TestRecentlyPushedNewBranches(t *testing.T) { checkRecentlyPushedNewBranches(t, user12Session, "user12/repo10", []string{"org25/org25_fork_repo10:new-commit", "new-commit"}) userForkRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 11}) + testCtx := NewAPITestContext(t, repo10.OwnerName, repo10.Name, auth_model.AccessTokenScopeWriteRepository) + t.Run("AddUser13AsCollaborator", doAPIAddCollaborator(testCtx, "user13", perm.AccessModeWrite)) prepareBranch(t, user13Session, userForkRepo) prepareRepoPR(t, user13Session, user13Session, repo10, userForkRepo) From 0d589f4fe2fba82034c73411ef8f166c0f429b93 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 21 May 2024 00:50:20 +0000 Subject: [PATCH 91/97] fix id in access.yml --- models/fixtures/access.yml | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/models/fixtures/access.yml b/models/fixtures/access.yml index 1dd4c4ead6b29..4171e31fef777 100644 --- a/models/fixtures/access.yml +++ b/models/fixtures/access.yml @@ -53,121 +53,121 @@ mode: 2 - - id: 12 + id: 10 user_id: 15 repo_id: 21 mode: 2 - - id: 13 + id: 11 user_id: 15 repo_id: 22 mode: 2 - - id: 14 + id: 12 user_id: 15 repo_id: 23 mode: 4 - - id: 15 + id: 13 user_id: 15 repo_id: 24 mode: 4 - - id: 16 + id: 14 user_id: 15 repo_id: 32 mode: 2 - - id: 17 + id: 15 user_id: 18 repo_id: 21 mode: 2 - - id: 18 + id: 16 user_id: 18 repo_id: 22 mode: 2 - - id: 19 + id: 17 user_id: 18 repo_id: 23 mode: 4 - - id: 20 + id: 18 user_id: 18 repo_id: 24 mode: 4 - - id: 21 + id: 19 user_id: 20 repo_id: 24 mode: 1 - - id: 22 + id: 20 user_id: 20 repo_id: 27 mode: 4 - - id: 23 + id: 21 user_id: 20 repo_id: 28 mode: 4 - - id: 24 + id: 22 user_id: 29 repo_id: 4 mode: 2 - - id: 25 + id: 23 user_id: 29 repo_id: 24 mode: 1 - - id: 26 + id: 24 user_id: 31 repo_id: 27 mode: 4 - - id: 27 + id: 25 user_id: 31 repo_id: 28 mode: 4 - - id: 28 + id: 26 user_id: 38 repo_id: 60 mode: 2 - - id: 29 + id: 27 user_id: 38 repo_id: 61 mode: 1 - - id: 30 + id: 28 user_id: 39 repo_id: 61 mode: 1 - - id: 31 + id: 29 user_id: 40 repo_id: 61 mode: 4 From 4175d64b60424b48c290e3b3623d161f07513de9 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 21 May 2024 01:28:43 +0000 Subject: [PATCH 92/97] fix lint --- tests/integration/compare_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/compare_test.go b/tests/integration/compare_test.go index 7fb8dbc3327ab..9f73ac80e2f9a 100644 --- a/tests/integration/compare_test.go +++ b/tests/integration/compare_test.go @@ -140,7 +140,7 @@ func TestCompareCodeExpand(t *testing.T) { user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) session = loginUser(t, user2.Name) - testRepoFork(t, session, user1.Name, repo.Name, user2.Name, "test_blob_excerpt-fork") + testRepoFork(t, session, user1.Name, repo.Name, user2.Name, "test_blob_excerpt-fork", "") testCreateBranch(t, session, user2.Name, "test_blob_excerpt-fork", "branch/main", "forked-branch", http.StatusSeeOther) testEditFile(t, session, user2.Name, "test_blob_excerpt-fork", "forked-branch", "README.md", strings.Repeat("a\n", 15)+"CHANGED\n"+strings.Repeat("a\n", 15)) From 484b3344f84f380777bcce5c007d602595434926 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 21 May 2024 04:06:39 +0000 Subject: [PATCH 93/97] improve --- models/git/branch.go | 18 ++++++++++++------ models/git/branch_list.go | 19 +++++-------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index 8d08fa9b544b0..fdf02ccd5f495 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -463,16 +463,22 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o } // find all related branches, these branches may already created PRs, we will check later - branches, err := db.Find[Branch](ctx, FindBranchOptions{ - RepoCond: builder.In("branch.repo_id", repoIDs), - CommitCond: builder.Neq{"branch.commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them, + var branches []*Branch + cond := FindBranchOptions{ PusherID: doer.ID, IsDeletedBranch: optional.Some(false), CommitAfterUnix: opts.CommitAfterUnix, - OrderBy: "branch.updated_unix DESC", ListOptions: db.ListOptionsAll, - }) - if err != nil { + }.ToConds() + cond = cond.And( + builder.In("repo_id", repoIDs), + // newly created branch have no changes, so skip them + builder.Neq{"commit_id": baseBranch.CommitID}, + ) + if err := db.GetEngine(ctx). + Where(cond). + OrderBy(db.SearchOrderByRecentUpdated.String()). + Find(&branches); err != nil { return nil, err } diff --git a/models/git/branch_list.go b/models/git/branch_list.go index 681685b644462..b87d172355ea7 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -81,9 +81,7 @@ func (branches BranchList) LoadRepo(ctx context.Context) error { type FindBranchOptions struct { db.ListOptions RepoID int64 - RepoCond builder.Cond ExcludeBranchNames []string - CommitCond builder.Cond PusherID int64 IsDeletedBranch optional.Option[bool] CommitAfterUnix int64 @@ -98,34 +96,27 @@ func (opts FindBranchOptions) ToConds() builder.Cond { if opts.RepoID > 0 { cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) } - if opts.RepoCond != nil { - cond = cond.And(opts.RepoCond) - } if len(opts.ExcludeBranchNames) > 0 { - cond = cond.And(builder.NotIn("branch.name", opts.ExcludeBranchNames)) - } - - if opts.CommitCond != nil { - cond = cond.And(opts.CommitCond) + cond = cond.And(builder.NotIn("name", opts.ExcludeBranchNames)) } if opts.PusherID > 0 { - cond = cond.And(builder.Eq{"branch.pusher_id": opts.PusherID}) + cond = cond.And(builder.Eq{"pusher_id": opts.PusherID}) } if opts.IsDeletedBranch.Has() { - cond = cond.And(builder.Eq{"branch.is_deleted": opts.IsDeletedBranch.Value()}) + cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.Value()}) } if opts.Keyword != "" { cond = cond.And(builder.Like{"name", opts.Keyword}) } if opts.CommitAfterUnix != 0 { - cond = cond.And(builder.Gte{"branch.commit_time": opts.CommitAfterUnix}) + cond = cond.And(builder.Gte{"commit_time": opts.CommitAfterUnix}) } if opts.CommitBeforeUnix != 0 { - cond = cond.And(builder.Lte{"branch.commit_time": opts.CommitBeforeUnix}) + cond = cond.And(builder.Lte{"commit_time": opts.CommitBeforeUnix}) } return cond From 9fcb6b73caaa71d6b91a46a0952a0db86fa5faff Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 21 May 2024 04:08:49 +0000 Subject: [PATCH 94/97] fix --- models/git/branch.go | 1 - 1 file changed, 1 deletion(-) diff --git a/models/git/branch.go b/models/git/branch.go index fdf02ccd5f495..adb9dac867e16 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -468,7 +468,6 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o PusherID: doer.ID, IsDeletedBranch: optional.Some(false), CommitAfterUnix: opts.CommitAfterUnix, - ListOptions: db.ListOptionsAll, }.ToConds() cond = cond.And( builder.In("repo_id", repoIDs), From 8cea058beac46f032db530f206135b1cda796696 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Tue, 21 May 2024 04:14:18 +0000 Subject: [PATCH 95/97] improve --- models/git/branch.go | 21 ++++++++++----------- models/git/branch_list.go | 16 ---------------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index adb9dac867e16..c315d921ffb88 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -464,18 +464,17 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o // find all related branches, these branches may already created PRs, we will check later var branches []*Branch - cond := FindBranchOptions{ - PusherID: doer.ID, - IsDeletedBranch: optional.Some(false), - CommitAfterUnix: opts.CommitAfterUnix, - }.ToConds() - cond = cond.And( - builder.In("repo_id", repoIDs), - // newly created branch have no changes, so skip them - builder.Neq{"commit_id": baseBranch.CommitID}, - ) if err := db.GetEngine(ctx). - Where(cond). + Where(builder.And( + builder.Eq{ + "pusher_id": doer.ID, + "is_deleted": false, + }, + builder.Gte{"commit_time": opts.CommitAfterUnix}, + builder.In("repo_id", repoIDs), + // newly created branch have no changes, so skip them + builder.Neq{"commit_id": baseBranch.CommitID}, + )). OrderBy(db.SearchOrderByRecentUpdated.String()). Find(&branches); err != nil { return nil, err diff --git a/models/git/branch_list.go b/models/git/branch_list.go index b87d172355ea7..1d0c34aeb5a03 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -84,15 +84,12 @@ type FindBranchOptions struct { ExcludeBranchNames []string PusherID int64 IsDeletedBranch optional.Option[bool] - CommitAfterUnix int64 - CommitBeforeUnix int64 OrderBy string Keyword string } func (opts FindBranchOptions) ToConds() builder.Cond { cond := builder.NewCond() - if opts.RepoID > 0 { cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) } @@ -100,25 +97,12 @@ func (opts FindBranchOptions) ToConds() builder.Cond { if len(opts.ExcludeBranchNames) > 0 { cond = cond.And(builder.NotIn("name", opts.ExcludeBranchNames)) } - - if opts.PusherID > 0 { - cond = cond.And(builder.Eq{"pusher_id": opts.PusherID}) - } - if opts.IsDeletedBranch.Has() { cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.Value()}) } if opts.Keyword != "" { cond = cond.And(builder.Like{"name", opts.Keyword}) } - - if opts.CommitAfterUnix != 0 { - cond = cond.And(builder.Gte{"commit_time": opts.CommitAfterUnix}) - } - if opts.CommitBeforeUnix != 0 { - cond = cond.And(builder.Lte{"commit_time": opts.CommitBeforeUnix}) - } - return cond } From 8929a16e2cd3da26a1ab79d888a850943fb2bf46 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 21 May 2024 20:05:37 +0800 Subject: [PATCH 96/97] Update models/git/branch_list.go --- models/git/branch_list.go | 1 - 1 file changed, 1 deletion(-) diff --git a/models/git/branch_list.go b/models/git/branch_list.go index 1d0c34aeb5a03..5c887461d5a07 100644 --- a/models/git/branch_list.go +++ b/models/git/branch_list.go @@ -82,7 +82,6 @@ type FindBranchOptions struct { db.ListOptions RepoID int64 ExcludeBranchNames []string - PusherID int64 IsDeletedBranch optional.Option[bool] OrderBy string Keyword string From f1b17d0a48b1cd287a4642fe9c245951b7787772 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 22 May 2024 00:05:22 +0800 Subject: [PATCH 97/97] Fix test --- tests/integration/pull_merge_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go index d639f2a1c76ad..3e7054c7e83d2 100644 --- a/tests/integration/pull_merge_test.go +++ b/tests/integration/pull_merge_test.go @@ -676,7 +676,7 @@ func TestPullAutoMergeAfterCommitStatusSucceed(t *testing.T) { session := loginUser(t, "user1") user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) forkedName := "repo1-1" - testRepoFork(t, session, "user2", "repo1", "user1", forkedName) + testRepoFork(t, session, "user2", "repo1", "user1", forkedName, "") defer func() { testDeleteRepository(t, session, "user1", forkedName) }() @@ -759,7 +759,7 @@ func TestPullAutoMergeAfterCommitStatusSucceedAndApproval(t *testing.T) { session := loginUser(t, "user1") user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}) forkedName := "repo1-2" - testRepoFork(t, session, "user2", "repo1", "user1", forkedName) + testRepoFork(t, session, "user2", "repo1", "user1", forkedName, "") defer func() { testDeleteRepository(t, session, "user1", forkedName) }()