Fix forked repo has no icon and language stat. (#10791)

* Update header.tmpl

* Update _repository.less

* Update pull.go

* Update indexer.go

* Update pull.go

* Update pull.go

* Update indexer.go

* fix forked repo doesn't have language stat

* fix forked repo doesn't have language stat

* fix forked repo doesn't have language stat

* fix forked repo doesn't have language stat

* fix forked repo doesn't have language stat

* fix forked repo doesn't have language stat

* fix forked repo doesn't have language stat

* fix forked repo doesn't have language stat

* fix forked repo doesn't have language stat

* fix forked repo doesn't have language stat

* fix forked repo doesn't have language stat

Thanks the advice from lunny and 6543.

* fix forked repo doesn't have language stat

Modified as suggested by 6543.

* fix forked repo doesn't have language stat

simplify the function.

* fix forked repo doesn't have language stat

update the indexer after the loop

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
L0veSunshine 2020-04-08 20:13:04 +08:00 committed by GitHub
parent b40107c416
commit 08208cdfb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 5 deletions

View File

@ -144,3 +144,32 @@ func (repo *Repository) UpdateLanguageStats(commitID string, stats map[string]fl
return sess.Commit()
}
// CopyLanguageStat Copy originalRepo language stat information to destRepo (use for forked repo)
func CopyLanguageStat(originalRepo, destRepo *Repository) error {
sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
RepoLang := make(LanguageStatList, 0, 6)
if err := sess.Where("`repo_id` = ?", originalRepo.ID).Desc("`percentage`").Find(&RepoLang); err != nil {
return err
}
if len(RepoLang) > 0 {
for i := range RepoLang {
RepoLang[i].ID = 0
RepoLang[i].RepoID = destRepo.ID
RepoLang[i].CreatedUnix = timeutil.TimeStampNow()
}
//update destRepo's indexer status
tmpCommitID := RepoLang[0].CommitID
if err := destRepo.updateIndexerStatus(sess, RepoIndexerTypeStats, tmpCommitID); err != nil {
return err
}
if _, err := sess.Insert(&RepoLang); err != nil {
return err
}
}
return sess.Commit()
}

View File

@ -82,6 +82,8 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
if err = repo.UpdateSize(ctx); err != nil {
log.Error("Failed to update size for repository: %v", err)
}
if err := models.CopyLanguageStat(oldRepo, repo); err != nil {
log.Error("Copy language stat from oldRepo failed")
}
return repo, models.CopyLFS(ctx, repo, oldRepo)
}

View File

@ -17,7 +17,7 @@
{{else if .IsMirror}}
{{svg "octicon-repo-clone" 32}}
{{else if .IsFork}}
{{svg "octicon-repo-fork" 32}}
{{svg "octicon-repo-forked" 32}}
{{else}}
{{svg "octicon-repo" 32}}
{{end}}
@ -38,7 +38,7 @@
{{else if .IsMirror}}
{{svg "octicon-repo-clone" 32}}
{{else if .IsFork}}
{{svg "octicon-repo-fork" 32}}
{{svg "octicon-repo-forked" 32}}
{{else}}
{{svg "octicon-repo" 32}}
{{end}}
@ -76,7 +76,7 @@
{{if and (not .IsEmpty) ($.Permission.CanRead $.UnitTypeCode)}}
<div class="ui labeled button {{if and ($.IsSigned) (not $.CanSignedUserFork)}}disabled-repo-button{{end}}" tabindex="0">
<a class="ui compact basic button {{if or (not $.IsSigned) (not $.CanSignedUserFork)}}poping up{{end}}" {{if $.CanSignedUserFork}}href="{{AppSubUrl}}/repo/fork/{{.ID}}"{{else if $.IsSigned}} data-content="{{$.i18n.Tr "repo.fork_from_self"}}" {{ else }} data-content="{{$.i18n.Tr "repo.fork_guest_user" }}" rel="nofollow" href="{{AppSubUrl}}/user/login?redirect_to={{AppSubUrl}}/repo/fork/{{.ID}}" {{end}} data-position="top center" data-variation="tiny">
{{svg "octicon-repo-forked" 16}}{{$.i18n.Tr "repo.fork"}}
{{svg "octicon-repo-forked" 15}}{{$.i18n.Tr "repo.fork"}}
</a>
<a class="ui basic label" href="{{.Link}}/forks">
{{.NumForks}}

View File

@ -35,7 +35,6 @@
.svg.octicon-repo-forked {
margin-top: -1px;
height: 15px;
}
.button {