|
|
|
@@ -7,6 +7,7 @@ package repo |
|
|
|
|
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"code.gitea.io/gitea/modules/options" |
|
|
|
"encoding/base64" |
|
|
|
"fmt" |
|
|
|
gotemplate "html/template" |
|
|
|
@@ -569,8 +570,9 @@ func safeURL(address string) string { |
|
|
|
|
|
|
|
type ContributorInfo struct { |
|
|
|
UserInfo *models.User |
|
|
|
Email string // for contributor who is not a registered user |
|
|
|
Email string // for contributor who is not a registered user |
|
|
|
} |
|
|
|
|
|
|
|
// Home render repository home page |
|
|
|
func Home(ctx *context.Context) { |
|
|
|
if len(ctx.Repo.Units) > 0 { |
|
|
|
@@ -579,12 +581,12 @@ func Home(ctx *context.Context) { |
|
|
|
if err == nil && contributors != nil { |
|
|
|
var contributorInfos []*ContributorInfo |
|
|
|
for _, c := range contributors { |
|
|
|
user,err := models.GetUserByEmail(c.Email) |
|
|
|
user, err := models.GetUserByEmail(c.Email) |
|
|
|
if err == nil { |
|
|
|
contributorInfos = append(contributorInfos, &ContributorInfo{ |
|
|
|
user, c.Email, |
|
|
|
}) |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
contributorInfos = append(contributorInfos, &ContributorInfo{ |
|
|
|
nil, c.Email, |
|
|
|
}) |
|
|
|
@@ -633,6 +635,39 @@ func Home(ctx *context.Context) { |
|
|
|
ctx.NotFound("Home", fmt.Errorf(ctx.Tr("units.error.no_unit_allowed_repo"))) |
|
|
|
} |
|
|
|
|
|
|
|
func renderLicense(ctx *context.Context) { |
|
|
|
entry, err := ctx.Repo.Commit.GetTreeEntryByPath("LICENSE") |
|
|
|
if err != nil { |
|
|
|
log.Error(err.Error()) |
|
|
|
return |
|
|
|
} |
|
|
|
blob := entry.Blob() |
|
|
|
dataRc, err := blob.DataAsync() |
|
|
|
if err != nil { |
|
|
|
log.Error("DataAsync", err) |
|
|
|
return |
|
|
|
} |
|
|
|
defer dataRc.Close() |
|
|
|
buf, err := ioutil.ReadAll(dataRc) |
|
|
|
if err != nil { |
|
|
|
log.Error("DataAsync", err) |
|
|
|
return |
|
|
|
} |
|
|
|
for _, f := range models.Licenses { |
|
|
|
license, err := options.License(f) |
|
|
|
if err != nil { |
|
|
|
log.Error("failed to get license content: %v, err:%v", f, err) |
|
|
|
continue |
|
|
|
} |
|
|
|
if bytes.Compare(buf,license) == 0 { |
|
|
|
log.Info("got matched license:%v",f) |
|
|
|
ctx.Data["LICENSE"] = f |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
log.Info("not found matched license,repo:%v",ctx.Repo.Repository.Name) |
|
|
|
} |
|
|
|
|
|
|
|
func renderLanguageStats(ctx *context.Context) { |
|
|
|
langs, err := ctx.Repo.Repository.GetTopLanguageStats(5) |
|
|
|
if err != nil { |
|
|
|
@@ -679,6 +714,8 @@ func renderCode(ctx *context.Context) { |
|
|
|
|
|
|
|
// Get Topics of this repo |
|
|
|
renderRepoTopics(ctx) |
|
|
|
// Get license of this repo |
|
|
|
renderLicense(ctx) |
|
|
|
if ctx.Written() { |
|
|
|
return |
|
|
|
} |
|
|
|
|