summaryrefslogtreecommitdiffstats
path: root/routers/repo/view.go
diff options
context:
space:
mode:
authorMorlinest <Morlinest@users.noreply.github.com>2017-10-01 15:50:56 +0200
committerLauris BH <lauris@nix.lv>2017-10-01 16:50:56 +0300
commit1ad902d5298202d5be14fd5a9c8ed6ce781a23c8 (patch)
treea4554edf9987b2d7088da89c909b7b4502f432bd /routers/repo/view.go
parentbae9cbce9c8fa02e62260e5bf4744d211c85f690 (diff)
downloadgitea-1ad902d5298202d5be14fd5a9c8ed6ce781a23c8.tar.gz
gitea-1ad902d5298202d5be14fd5a9c8ed6ce781a23c8.zip
Fix implementation of repo Home func (#2601)
* Fix implementation of repo Home func * Make fixture changes for testing
Diffstat (limited to 'routers/repo/view.go')
-rw-r--r--routers/repo/view.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/routers/repo/view.go b/routers/repo/view.go
index 64a2e2ea76..fa1087fe09 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -264,16 +264,21 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
// Home render repository home page
func Home(ctx *context.Context) {
if len(ctx.Repo.Repository.Units) > 0 {
- tp := ctx.Repo.Repository.Units[0].Type
- if tp == models.UnitTypeCode {
- renderCode(ctx)
- return
+ var firstUnit *models.Unit
+ for _, repoUnit := range ctx.Repo.Repository.Units {
+ if repoUnit.Type == models.UnitTypeCode {
+ renderCode(ctx)
+ return
+ }
+
+ unit, ok := models.Units[repoUnit.Type]
+ if ok && (firstUnit == nil || !firstUnit.IsLessThan(unit)) {
+ firstUnit = &unit
+ }
}
- unit, ok := models.Units[tp]
- if ok {
- ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/%s%s",
- ctx.Repo.Repository.FullName(), unit.URI))
+ if firstUnit != nil {
+ ctx.Redirect(fmt.Sprintf("%s/%s%s", setting.AppSubURL, ctx.Repo.Repository.FullName(), firstUnit.URI))
return
}
}