mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-30 19:08:37 +00:00 
			
		
		
		
	Fix implementation of repo Home func (#2601)
* Fix implementation of repo Home func * Make fixture changes for testing
This commit is contained in:
		| @@ -1,43 +1,43 @@ | |||||||
| - | - | ||||||
|   id: 1 |   id: 1 | ||||||
|   repo_id: 1 |   repo_id: 1 | ||||||
|   type: 1 |  | ||||||
|   index: 0 |  | ||||||
|   config: "{}" |  | ||||||
|   created_unix: 946684810 |  | ||||||
|  |  | ||||||
| - |  | ||||||
|   id: 2 |  | ||||||
|   repo_id: 1 |  | ||||||
|   type: 2 |  | ||||||
|   index: 1 |  | ||||||
|   config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true}" |  | ||||||
|   created_unix: 946684810 |  | ||||||
|  |  | ||||||
| - |  | ||||||
|   id: 3 |  | ||||||
|   repo_id: 1 |  | ||||||
|   type: 3 |  | ||||||
|   index: 2 |  | ||||||
|   config: "{}" |  | ||||||
|   created_unix: 946684810 |  | ||||||
|  |  | ||||||
| - |  | ||||||
|   id: 4 |  | ||||||
|   repo_id: 1 |  | ||||||
|   type: 4 |   type: 4 | ||||||
|   index: 3 |   index: 3 | ||||||
|   config: "{}" |   config: "{}" | ||||||
|   created_unix: 946684810 |   created_unix: 946684810 | ||||||
|  |  | ||||||
| - | - | ||||||
|   id: 5 |   id: 2 | ||||||
|   repo_id: 1 |   repo_id: 1 | ||||||
|   type: 5 |   type: 5 | ||||||
|   index: 4 |   index: 4 | ||||||
|   config: "{}" |   config: "{}" | ||||||
|   created_unix: 946684810 |   created_unix: 946684810 | ||||||
|  |  | ||||||
|  | - | ||||||
|  |   id: 3 | ||||||
|  |   repo_id: 1 | ||||||
|  |   type: 1 | ||||||
|  |   index: 0 | ||||||
|  |   config: "{}" | ||||||
|  |   created_unix: 946684810 | ||||||
|  |  | ||||||
|  | - | ||||||
|  |   id: 4 | ||||||
|  |   repo_id: 1 | ||||||
|  |   type: 2 | ||||||
|  |   index: 1 | ||||||
|  |   config: "{\"EnableTimetracker\":true,\"AllowOnlyContributorsToTrackTime\":true}" | ||||||
|  |   created_unix: 946684810 | ||||||
|  |  | ||||||
|  | - | ||||||
|  |   id: 5 | ||||||
|  |   repo_id: 1 | ||||||
|  |   type: 3 | ||||||
|  |   index: 2 | ||||||
|  |   config: "{}" | ||||||
|  |   created_unix: 946684810 | ||||||
|  |  | ||||||
| - | - | ||||||
|   id: 6 |   id: 6 | ||||||
|   repo_id: 3 |   repo_id: 3 | ||||||
|   | |||||||
| @@ -60,6 +60,14 @@ func (u *Unit) CanDisable() bool { | |||||||
| 	return true | 	return true | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // IsLessThan compares order of two units | ||||||
|  | func (u Unit) IsLessThan(unit Unit) bool { | ||||||
|  | 	if (u.Type == UnitTypeExternalTracker || u.Type == UnitTypeExternalWiki) && unit.Type != UnitTypeExternalTracker && unit.Type != UnitTypeExternalWiki { | ||||||
|  | 		return false | ||||||
|  | 	} | ||||||
|  | 	return u.Idx < unit.Idx | ||||||
|  | } | ||||||
|  |  | ||||||
| // Enumerate all the units | // Enumerate all the units | ||||||
| var ( | var ( | ||||||
| 	UnitCode = Unit{ | 	UnitCode = Unit{ | ||||||
|   | |||||||
| @@ -264,16 +264,21 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st | |||||||
| // Home render repository home page | // Home render repository home page | ||||||
| func Home(ctx *context.Context) { | func Home(ctx *context.Context) { | ||||||
| 	if len(ctx.Repo.Repository.Units) > 0 { | 	if len(ctx.Repo.Repository.Units) > 0 { | ||||||
| 		tp := ctx.Repo.Repository.Units[0].Type | 		var firstUnit *models.Unit | ||||||
| 		if tp == models.UnitTypeCode { | 		for _, repoUnit := range ctx.Repo.Repository.Units { | ||||||
|  | 			if repoUnit.Type == models.UnitTypeCode { | ||||||
| 				renderCode(ctx) | 				renderCode(ctx) | ||||||
| 				return | 				return | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 		unit, ok := models.Units[tp] | 			unit, ok := models.Units[repoUnit.Type] | ||||||
| 		if ok { | 			if ok && (firstUnit == nil || !firstUnit.IsLessThan(unit)) { | ||||||
| 			ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/%s%s", | 				firstUnit = &unit | ||||||
| 				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 | 			return | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user