summaryrefslogtreecommitdiffstats
path: root/routers/repo/branch.go
diff options
context:
space:
mode:
authorMario Lubenka <mario.lubenka@googlemail.com>2019-06-27 16:15:30 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2019-06-27 22:15:30 +0800
commit7c0f2b9843f67ec49ea0038692648a531138a055 (patch)
tree9041ca592b8fef9937e6cd3abb5dc57683f12473 /routers/repo/branch.go
parentc37ec66ee25b95525b9c8dfddd5a6f9a798150fe (diff)
downloadgitea-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 'routers/repo/branch.go')
-rw-r--r--routers/repo/branch.go38
1 files changed, 26 insertions, 12 deletions
diff --git a/routers/repo/branch.go b/routers/repo/branch.go
index 05d64fb4c8..708b33be09 100644
--- a/routers/repo/branch.go
+++ b/routers/repo/branch.go
@@ -24,13 +24,14 @@ const (
// Branch contains the branch information
type Branch struct {
- Name string
- Commit *git.Commit
- IsProtected bool
- IsDeleted bool
- DeletedBranch *models.DeletedBranch
- CommitsAhead int
- CommitsBehind int
+ Name string
+ Commit *git.Commit
+ IsProtected bool
+ IsDeleted bool
+ DeletedBranch *models.DeletedBranch
+ CommitsAhead int
+ CommitsBehind int
+ LatestPullRequest *models.PullRequest
}
// Branches render repository branch page
@@ -181,12 +182,25 @@ func loadBranches(ctx *context.Context) []*Branch {
return nil
}
+ pr, err := models.GetLatestPullRequestByHeadInfo(ctx.Repo.Repository.ID, branchName)
+ if err != nil {
+ ctx.ServerError("GetLatestPullRequestByHeadInfo", err)
+ return nil
+ }
+ if pr != nil {
+ if err := pr.LoadIssue(); err != nil {
+ ctx.ServerError("pr.LoadIssue", err)
+ return nil
+ }
+ }
+
branches[i] = &Branch{
- Name: branchName,
- Commit: commit,
- IsProtected: isProtected,
- CommitsAhead: divergence.Ahead,
- CommitsBehind: divergence.Behind,
+ Name: branchName,
+ Commit: commit,
+ IsProtected: isProtected,
+ CommitsAhead: divergence.Ahead,
+ CommitsBehind: divergence.Behind,
+ LatestPullRequest: pr,
}
}