44package user
55
66import (
7+ "code.gitea.io/gitea/modules/util"
78 "net/url"
89
910 "code.gitea.io/gitea/models/db"
@@ -102,27 +103,24 @@ func PrepareContextForProfileBigAvatar(ctx *context.Context) {
102103 }
103104}
104105
105- func FindUserProfileReadme (ctx * context.Context , doer * user_model.User , profileType string ) (profileDbRepo * repo_model.Repository , profileGitRepo * git.Repository , profileReadmeBlob * git.Blob , profileClose func ()) {
106- profileName := ".profile"
107- if profileType != "Public" {
108- profileName = ".profile-private"
109- }
110- profileDbRepo , err := repo_model .GetRepositoryByName (ctx , ctx .ContextUser .ID , profileName )
106+ func FindOwnerProfileReadme (ctx * context.Context , doer * user_model.User , optProfileRepoName ... string ) (profileDbRepo * repo_model.Repository , profileGitRepo * git.Repository , profileReadmeBlob * git.Blob , profileClose func ()) {
107+ profileRepoName := util .OptionalArg (optProfileRepoName , ".profile" )
108+ profileDbRepo , err := repo_model .GetRepositoryByName (ctx , ctx .ContextUser .ID , profileRepoName )
111109 if err == nil {
112110 perm , err := access_model .GetUserRepoPermission (ctx , profileDbRepo , doer )
113111 if err == nil && ! profileDbRepo .IsEmpty && perm .CanRead (unit .TypeCode ) {
114112 if profileGitRepo , err = gitrepo .OpenRepository (ctx , profileDbRepo ); err != nil {
115- log .Error ("FindUserProfileReadme failed to OpenRepository: %v" , err )
113+ log .Error ("FindOwnerProfileReadme failed to OpenRepository: %v" , err )
116114 } else {
117115 if commit , err := profileGitRepo .GetBranchCommit (profileDbRepo .DefaultBranch ); err != nil {
118- log .Error ("FindUserProfileReadme failed to GetBranchCommit: %v" , err )
116+ log .Error ("FindOwnerProfileReadme failed to GetBranchCommit: %v" , err )
119117 } else {
120118 profileReadmeBlob , _ = commit .GetBlobByPath ("README.md" )
121119 }
122120 }
123121 }
124122 } else if ! repo_model .IsErrRepoNotExist (err ) {
125- log .Error ("FindUserProfileReadme failed to GetRepositoryByName: %v" , err )
123+ log .Error ("FindOwnerProfileReadme failed to GetRepositoryByName: %v" , err )
126124 }
127125 return profileDbRepo , profileGitRepo , profileReadmeBlob , func () {
128126 if profileGitRepo != nil {
@@ -134,7 +132,7 @@ func FindUserProfileReadme(ctx *context.Context, doer *user_model.User, profileT
134132func RenderUserHeader (ctx * context.Context ) {
135133 prepareContextForCommonProfile (ctx )
136134
137- _ , _ , profileReadmeBlob , profileClose := FindUserProfileReadme (ctx , ctx .Doer , "Public" )
135+ _ , _ , profileReadmeBlob , profileClose := FindOwnerProfileReadme (ctx , ctx .Doer )
138136 defer profileClose ()
139137 ctx .Data ["HasPublicProfileReadme" ] = profileReadmeBlob != nil
140138}
@@ -178,11 +176,14 @@ func RenderOrgHeader(ctx *context.Context) error {
178176 return err
179177 }
180178
181- _ , _ , profileReadmeBlob , profileClose := FindUserProfileReadme (ctx , ctx .Doer , "Public" )
179+ // FIXME: only do database query, do not open it
180+ _ , _ , profileReadmeBlob , profileClose := FindOwnerProfileReadme (ctx , ctx .Doer )
182181 defer profileClose ()
183182 ctx .Data ["HasPublicProfileReadme" ] = profileReadmeBlob != nil
184183
185- _ , _ , profileReadmeBlob , profileClose = FindUserProfileReadme (ctx , ctx .Doer , "Private" )
184+ // FIXME: only do database query, do not open it
185+ // FIXME: use a const for ".profile-private"
186+ _ , _ , profileReadmeBlob , profileClose = FindOwnerProfileReadme (ctx , ctx .Doer , ".profile-private" )
186187 defer profileClose ()
187188 ctx .Data ["HasPrivateProfileReadme" ] = profileReadmeBlob != nil
188189
0 commit comments