This commit is contained in:
parent
2996573976
commit
40c6eb0d85
2 changed files with 48 additions and 4 deletions
|
@ -163,6 +163,7 @@ func NewRepoContext() {
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
OwnerID int64 `xorm:"UNIQUE(s)"`
|
OwnerID int64 `xorm:"UNIQUE(s)"`
|
||||||
|
OwnerName string `xorm:"-"`
|
||||||
Owner *User `xorm:"-"`
|
Owner *User `xorm:"-"`
|
||||||
LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
|
LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
|
||||||
Name string `xorm:"INDEX NOT NULL"`
|
Name string `xorm:"INDEX NOT NULL"`
|
||||||
|
@ -223,9 +224,17 @@ func (repo *Repository) MustOwner() *User {
|
||||||
return repo.mustOwner(x)
|
return repo.mustOwner(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MustOwnerName always returns valid owner name to avoid
|
||||||
|
// conceptually impossible error handling.
|
||||||
|
// It returns "error" and logs error details when error
|
||||||
|
// occurs.
|
||||||
|
func (repo *Repository) MustOwnerName() string {
|
||||||
|
return repo.mustOwnerName(x)
|
||||||
|
}
|
||||||
|
|
||||||
// FullName returns the repository full name
|
// FullName returns the repository full name
|
||||||
func (repo *Repository) FullName() string {
|
func (repo *Repository) FullName() string {
|
||||||
return repo.MustOwner().Name + "/" + repo.Name
|
return repo.MustOwnerName() + "/" + repo.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTMLURL returns the repository HTML URL
|
// HTMLURL returns the repository HTML URL
|
||||||
|
@ -477,6 +486,41 @@ func (repo *Repository) mustOwner(e Engine) *User {
|
||||||
return repo.Owner
|
return repo.Owner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repo *Repository) getOwnerName(e Engine) error {
|
||||||
|
if len(repo.OwnerName) > 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if repo.Owner != nil {
|
||||||
|
repo.OwnerName = repo.Owner.Name
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
u := new(User)
|
||||||
|
has, err := e.ID(repo.OwnerID).Cols("name").Get(u)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if !has {
|
||||||
|
return ErrUserNotExist{repo.OwnerID, "", 0}
|
||||||
|
}
|
||||||
|
repo.OwnerName = u.Name
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOwnerName returns the repository owner name
|
||||||
|
func (repo *Repository) GetOwnerName() error {
|
||||||
|
return repo.getOwnerName(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *Repository) mustOwnerName(e Engine) string {
|
||||||
|
if err := repo.getOwnerName(e); err != nil {
|
||||||
|
log.Error(4, "Error loading repository owner name: %v", err)
|
||||||
|
return "error"
|
||||||
|
}
|
||||||
|
|
||||||
|
return repo.OwnerName
|
||||||
|
}
|
||||||
|
|
||||||
// ComposeMetas composes a map of metas for rendering external issue tracker URL.
|
// ComposeMetas composes a map of metas for rendering external issue tracker URL.
|
||||||
func (repo *Repository) ComposeMetas() map[string]string {
|
func (repo *Repository) ComposeMetas() map[string]string {
|
||||||
unit, err := repo.GetUnit(UnitTypeExternalTracker)
|
unit, err := repo.GetUnit(UnitTypeExternalTracker)
|
||||||
|
@ -588,7 +632,7 @@ func (repo *Repository) GetBaseRepo() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) repoPath(e Engine) string {
|
func (repo *Repository) repoPath(e Engine) string {
|
||||||
return RepoPath(repo.mustOwner(e).Name, repo.Name)
|
return RepoPath(repo.mustOwnerName(e), repo.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepoPath returns the repository path
|
// RepoPath returns the repository path
|
||||||
|
@ -2133,7 +2177,7 @@ func ReinitMissingRepositories() error {
|
||||||
// SyncRepositoryHooks rewrites all repositories' pre-receive, update and post-receive hooks
|
// SyncRepositoryHooks rewrites all repositories' pre-receive, update and post-receive hooks
|
||||||
// to make sure the binary and custom conf path are up-to-date.
|
// to make sure the binary and custom conf path are up-to-date.
|
||||||
func SyncRepositoryHooks() error {
|
func SyncRepositoryHooks() error {
|
||||||
return x.Where("id > 0").Iterate(new(Repository),
|
return x.Cols("owner_id", "name").Where("id > 0").Iterate(new(Repository),
|
||||||
func(idx int, bean interface{}) error {
|
func(idx int, bean interface{}) error {
|
||||||
if err := createDelegateHooks(bean.(*Repository).RepoPath()); err != nil {
|
if err := createDelegateHooks(bean.(*Repository).RepoPath()); err != nil {
|
||||||
return fmt.Errorf("SyncRepositoryHook: %v", err)
|
return fmt.Errorf("SyncRepositoryHook: %v", err)
|
||||||
|
|
|
@ -67,7 +67,7 @@ func WikiPath(userName, repoName string) string {
|
||||||
|
|
||||||
// WikiPath returns wiki data path for given repository.
|
// WikiPath returns wiki data path for given repository.
|
||||||
func (repo *Repository) WikiPath() string {
|
func (repo *Repository) WikiPath() string {
|
||||||
return WikiPath(repo.MustOwner().Name, repo.Name)
|
return WikiPath(repo.MustOwnerName(), repo.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasWiki returns true if repository has wiki.
|
// HasWiki returns true if repository has wiki.
|
||||||
|
|
Reference in a new issue