Skip to content

Commit b33f9b6

Browse files
committed
code unit get its sub path as every other unit
1 parent 91ae32c commit b33f9b6

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

models/unit/unit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ var (
206206
UnitCode = Unit{
207207
TypeCode,
208208
"repo.code",
209-
"/",
209+
"/code",
210210
"repo.code.desc",
211211
0,
212212
perm.AccessModeOwner,

routers/web/repo/view.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,8 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) {
773773
}
774774
}
775775

776-
// Home render repository home page
777-
func Home(ctx *context.Context) {
776+
// HomeWithFeedCheck render repository home page or return feed
777+
func HomeWithFeedCheck(ctx *context.Context) {
778778
if setting.Other.EnableFeed {
779779
isFeed, _, showFeedType := feed.GetFeedType(ctx.PathParam(":reponame"), ctx.Req)
780780
if isFeed {
@@ -790,6 +790,15 @@ func Home(ctx *context.Context) {
790790
}
791791
}
792792

793+
defaultURI := ctx.Repo.Repository.MustGetUnit(ctx, ctx.Repo.Repository.DefaultUnit).Unit().URI
794+
if defaultURI == "/" { // support legacy code units
795+
defaultURI = "/code"
796+
}
797+
ctx.Redirect(ctx.Repo.RepoLink + defaultURI)
798+
}
799+
800+
// Home render repository home page
801+
func Home(ctx *context.Context) {
793802
checkHomeCodeViewable(ctx)
794803
if ctx.Written() {
795804
return

routers/web/web.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,8 @@ func registerRoutes(m *web.Router) {
11401140
// end "/{username}/{reponame}/settings"
11411141

11421142
// user/org home, including rss feeds
1143-
m.Get("/{username}/{reponame}", ignSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.Home)
1143+
m.Get("/{username}/{reponame}", ignSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.HomeWithFeedCheck)
1144+
m.Get("/{username}/{reponame}/code", ignSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.Home)
11441145

11451146
// TODO: maybe it should relax the permission to allow "any access"
11461147
m.Post("/{username}/{reponame}/markup", ignSignIn, context.RepoAssignment, context.RequireRepoReaderOr(unit.TypeCode, unit.TypeIssues, unit.TypePullRequests, unit.TypeReleases, unit.TypeWiki), web.Bind(structs.MarkupOption{}), misc.Markup)

0 commit comments

Comments
 (0)