diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-07-08 11:19:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-08 05:19:00 +0200 |
commit | 6375419468edc95fdfac94aac3b0e10b23743557 (patch) | |
tree | e104617051a314fa33e62ebcf7c149d0d0434b82 /models/git | |
parent | e0a780d75b79233ceb97116b9ae8563a9942aff9 (diff) | |
download | gitea-6375419468edc95fdfac94aac3b0e10b23743557.tar.gz gitea-6375419468edc95fdfac94aac3b0e10b23743557.zip |
Newly pushed branches hints on repository home page (#25715)
This PR will display a pull request creation hint on the repository home
page when there are newly created branches with no pull request. Only
the recent 6 hours and 2 updated branches will be displayed.
Inspired by #14003
Replace #14003
Resolves #311
Resolves #13196
Resolves #23743
co-authored by @kolaente
Diffstat (limited to 'models/git')
-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 +} |