diff options
Diffstat (limited to 'models/git/branch.go')
-rw-r--r-- | models/git/branch.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/models/git/branch.go b/models/git/branch.go index 5e99544958..97891f01eb 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -15,6 +15,8 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" + + "xorm.io/builder" ) // ErrBranchNotExist represents an error that branch with such name does not exist. @@ -378,3 +380,22 @@ 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 +func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64) (BranchList, error) { + branches := make(BranchList, 0, 2) + subQuery := builder.Select("head_branch").From("pull_request"). + InnerJoin("issue", "issue.id = pull_request.issue_id"). + Where(builder.Eq{ + "pull_request.head_repo_id": repoID, + "issue.is_closed": false, + }) + err := db.GetEngine(ctx). + Where("pusher_id=? AND is_deleted=?", userID, false). + And("updated_unix >= ?", time.Now().Add(-time.Hour*6).Unix()). + NotIn("name", subQuery). + OrderBy("branch.updated_unix DESC"). + Limit(2). + Find(&branches) + return branches, err +} |