mirror of
https://github.com/go-gitea/gitea
synced 2024-06-03 03:46:51 +02:00
add test 1
This commit is contained in:
parent
d93b2bcc80
commit
5c3f7aa231
|
@ -45,3 +45,27 @@
|
||||||
is_deleted: false
|
is_deleted: false
|
||||||
deleted_by_id: 0
|
deleted_by_id: 0
|
||||||
deleted_unix: 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
|
||||||
|
|
|
@ -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
|
// 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
|
// 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
|
// 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)
|
baseBranch, err := GetBranch(ctx, baseRepo.ID, baseRepo.DefaultBranch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -417,12 +418,16 @@ func FindRecentlyPushedNewBranches(ctx context.Context, baseRepo *repo_model.Rep
|
||||||
builder.Eq{"branch.id": baseBranch.ID},
|
builder.Eq{"branch.id": baseBranch.ID},
|
||||||
))
|
))
|
||||||
|
|
||||||
|
if commitAfterUnix == 0 {
|
||||||
|
commitAfterUnix = time.Now().Add(-time.Hour * 6).Unix()
|
||||||
|
}
|
||||||
opts := FindBranchOptions{
|
opts := FindBranchOptions{
|
||||||
IDCond: builder.NotIn("id", invalidBranchCond),
|
IDCond: builder.NotIn("id", invalidBranchCond),
|
||||||
RepoCond: builder.In("repo_id", repoCond),
|
RepoCond: builder.In("repo_id", repoCond),
|
||||||
CommitCond: builder.Neq{"commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them,
|
CommitCond: builder.Neq{"commit_id": baseBranch.CommitID}, // newly created branch have no changes, so skip them,
|
||||||
PusherID: doer.ID,
|
PusherID: doer.ID,
|
||||||
IsDeletedBranch: util.OptionalBoolFalse,
|
IsDeletedBranch: util.OptionalBoolFalse,
|
||||||
|
CommitAfterUnix: commitAfterUnix,
|
||||||
OrderBy: "branch.updated_unix DESC",
|
OrderBy: "branch.updated_unix DESC",
|
||||||
}
|
}
|
||||||
opts.PageSize = 2
|
opts.PageSize = 2
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/container"
|
"code.gitea.io/gitea/modules/container"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
|
@ -95,8 +94,8 @@ type FindBranchOptions struct {
|
||||||
CommitCond builder.Cond
|
CommitCond builder.Cond
|
||||||
PusherID int64
|
PusherID int64
|
||||||
IsDeletedBranch util.OptionalBool
|
IsDeletedBranch util.OptionalBool
|
||||||
UpdatedAfterUnix timeutil.TimeStamp
|
CommitAfterUnix int64
|
||||||
UpdatedBeforeUnix timeutil.TimeStamp
|
CommitBeforeUnix int64
|
||||||
OrderBy string
|
OrderBy string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,11 +130,11 @@ func (opts *FindBranchOptions) Cond() builder.Cond {
|
||||||
cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.IsTrue()})
|
cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.IsTrue()})
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.UpdatedAfterUnix != 0 {
|
if opts.CommitAfterUnix != 0 {
|
||||||
cond = cond.And(builder.Gte{"updated_unix": opts.UpdatedAfterUnix})
|
cond = cond.And(builder.Gte{"commit_time": opts.CommitAfterUnix})
|
||||||
}
|
}
|
||||||
if opts.UpdatedBeforeUnix != 0 {
|
if opts.CommitBeforeUnix != 0 {
|
||||||
cond = cond.And(builder.Lte{"updated_unix": opts.UpdatedBeforeUnix})
|
cond = cond.And(builder.Lte{"commit_time": opts.CommitBeforeUnix})
|
||||||
}
|
}
|
||||||
return cond
|
return cond
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"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/git"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ func TestGetDeletedBranches(t *testing.T) {
|
||||||
ListOptions: db.ListOptions{
|
ListOptions: db.ListOptions{
|
||||||
ListAll: true,
|
ListAll: true,
|
||||||
},
|
},
|
||||||
RepoID: repo.ID,
|
RepoIDs: []int64{repo.ID},
|
||||||
IsDeletedBranch: util.OptionalBoolTrue,
|
IsDeletedBranch: util.OptionalBoolTrue,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -183,3 +184,26 @@ func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, deletedBranch)
|
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
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
||||||
|
65f1bf27bc3bf70f64657658635e66094edbcb4d
|
|
@ -0,0 +1 @@
|
||||||
|
cb24c347e328d83c1e0c3c908a6b2c0a2fcb8a3d
|
Loading…
Reference in New Issue
Block a user