diff options
author | Mario Lubenka <mario.lubenka@googlemail.com> | 2019-06-27 16:15:30 +0200 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-06-27 22:15:30 +0800 |
commit | 7c0f2b9843f67ec49ea0038692648a531138a055 (patch) | |
tree | 9041ca592b8fef9937e6cd3abb5dc57683f12473 /models | |
parent | c37ec66ee25b95525b9c8dfddd5a6f9a798150fe (diff) | |
download | gitea-7c0f2b9843f67ec49ea0038692648a531138a055.tar.gz gitea-7c0f2b9843f67ec49ea0038692648a531138a055.zip |
Show Pull Request button or status of latest PR in branch list (#6990)
* Show Pull Request button or status of latest PR in branch list
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Do not show pull request button on deleted branches
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Do not show commit divergence on deleted branches
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Use XORMs Get instead of limit
* Links pull request ID and use smaller labels for displaying the pull request status
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Handle error when getting latest pull request
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Indent template
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
* Check error when loading issue
Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
Diffstat (limited to 'models')
-rw-r--r-- | models/pull.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/models/pull.go b/models/pull.go index 2f5412651b..eac36235bb 100644 --- a/models/pull.go +++ b/models/pull.go @@ -776,6 +776,20 @@ func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string) ([]*PullRequ Find(&prs) } +// GetLatestPullRequestByHeadInfo returns the latest pull request (regardless of its status) +// by given head information (repo and branch). +func GetLatestPullRequestByHeadInfo(repoID int64, branch string) (*PullRequest, error) { + pr := new(PullRequest) + has, err := x. + Where("head_repo_id = ? AND head_branch = ?", repoID, branch). + OrderBy("id DESC"). + Get(pr) + if !has { + return nil, err + } + return pr, err +} + // GetUnmergedPullRequestsByBaseInfo returns all pull requests that are open and has not been merged // by given base information (repo and branch). func GetUnmergedPullRequestsByBaseInfo(repoID int64, branch string) ([]*PullRequest, error) { |