From 7c0f2b9843f67ec49ea0038692648a531138a055 Mon Sep 17 00:00:00 2001 From: Mario Lubenka Date: Thu, 27 Jun 2019 16:15:30 +0200 Subject: 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 * Do not show pull request button on deleted branches Signed-off-by: Mario Lubenka * Do not show commit divergence on deleted branches Signed-off-by: Mario Lubenka * 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 * Handle error when getting latest pull request Signed-off-by: Mario Lubenka * Indent template Signed-off-by: Mario Lubenka * Check error when loading issue Signed-off-by: Mario Lubenka --- models/pull.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'models') 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) { -- cgit v1.2.3