|
|
@@ -46,9 +46,19 @@ const RepoAvatarURLPrefix = "repo-avatars"
|
|
|
var repoWorkingPool = sync.NewExclusivePool()
|
|
|
|
|
|
var (
|
|
|
- Gitignores, Licenses, Readmes, LabelTemplates []string
|
|
|
+ // Gitignores contains the gitiginore files
|
|
|
+ Gitignores []string
|
|
|
|
|
|
- // Maximum items per page in forks, watchers and stars of a repo
|
|
|
+ // Licenses contains the license files
|
|
|
+ Licenses []string
|
|
|
+
|
|
|
+ // Readmes contains the readme files
|
|
|
+ Readmes []string
|
|
|
+
|
|
|
+ // LabelTemplates contains the label template files
|
|
|
+ LabelTemplates []string
|
|
|
+
|
|
|
+ // ItemsPerPage maximum items per page in forks, watchers and stars of a repo
|
|
|
ItemsPerPage = 39
|
|
|
)
|
|
|
|
|
|
@@ -220,15 +230,18 @@ type Repository struct {
|
|
|
UpdatedUnix int64
|
|
|
}
|
|
|
|
|
|
+// BeforeInsert will be invoked by XORM before inserting a record
|
|
|
func (repo *Repository) BeforeInsert() {
|
|
|
repo.CreatedUnix = time.Now().Unix()
|
|
|
repo.UpdatedUnix = repo.CreatedUnix
|
|
|
}
|
|
|
|
|
|
+// BeforeUpdate is invoked from XORM before updating this object.
|
|
|
func (repo *Repository) BeforeUpdate() {
|
|
|
repo.UpdatedUnix = time.Now().Unix()
|
|
|
}
|
|
|
|
|
|
+// AfterSet is invoked from XORM after setting the values of all fields of this object.
|
|
|
func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
|
|
|
switch colName {
|
|
|
case "default_branch":
|
|
|
@@ -276,6 +289,7 @@ func (repo *Repository) loadAttributes(e Engine) (err error) {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// LoadAttributes loads attributes from database
|
|
|
func (repo *Repository) LoadAttributes() error {
|
|
|
return repo.loadAttributes(x)
|
|
|
}
|
|
|
@@ -285,10 +299,12 @@ func (repo *Repository) IsPartialPublic() bool {
|
|
|
return !repo.IsPrivate || repo.AllowPublicWiki || repo.AllowPublicIssues
|
|
|
}
|
|
|
|
|
|
+// CanGuestViewWiki returns true if wiki is public or allow public access to wiki or issues.
|
|
|
func (repo *Repository) CanGuestViewWiki() bool {
|
|
|
return repo.EnableWiki && !repo.EnableExternalWiki && repo.AllowPublicWiki
|
|
|
}
|
|
|
|
|
|
+// CanGuestViewIssues returns true if issues is public or allow public access to wiki or issues.
|
|
|
func (repo *Repository) CanGuestViewIssues() bool {
|
|
|
return repo.EnableIssues && !repo.EnableExternalTracker && repo.AllowPublicIssues
|
|
|
}
|
|
|
@@ -299,10 +315,12 @@ func (repo *Repository) MustOwner() *User {
|
|
|
return repo.mustOwner(x)
|
|
|
}
|
|
|
|
|
|
+// FullName returns the repository full name
|
|
|
func (repo *Repository) FullName() string {
|
|
|
return repo.MustOwner().Name + "/" + repo.Name
|
|
|
}
|
|
|
|
|
|
+// HTMLURL returns the repository HTML URL
|
|
|
func (repo *Repository) HTMLURL() string {
|
|
|
return setting.AppURL + repo.FullName()
|
|
|
}
|
|
|
@@ -316,9 +334,9 @@ func (repo *Repository) CustomAvatarPath() string {
|
|
|
// which includes app sub-url as prefix.
|
|
|
// Since Gravatar support not needed here - just check for image path.
|
|
|
func (repo *Repository) RelAvatarLink() string {
|
|
|
- defaultImgUrl := ""
|
|
|
+ defaultImgURL := ""
|
|
|
if !com.IsExist(repo.CustomAvatarPath()) {
|
|
|
- return defaultImgUrl
|
|
|
+ return defaultImgURL
|
|
|
}
|
|
|
return fmt.Sprintf("%s/%s/%d", setting.AppSubURL, RepoAvatarURLPrefix, repo.ID)
|
|
|
}
|
|
|
@@ -366,7 +384,7 @@ func (repo *Repository) DeleteAvatar() error {
|
|
|
return UpdateRepository(repo, false)
|
|
|
}
|
|
|
|
|
|
-// This method assumes following fields have been assigned with valid values:
|
|
|
+// APIFormat This method assumes following fields have been assigned with valid values:
|
|
|
// Required - BaseRepo (if fork)
|
|
|
// Arguments that are allowed to be nil: permission
|
|
|
func (repo *Repository) APIFormat(permission *api.Permission, user ...*User) *api.Repository {
|
|
|
@@ -417,6 +435,7 @@ func (repo *Repository) getOwner(e Engine) (err error) {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
+// GetOwner returns the repository owner
|
|
|
func (repo *Repository) GetOwner() error {
|
|
|
return repo.getOwner(x)
|
|
|
}
|
|
|
@@ -432,6 +451,7 @@ func (repo *Repository) mustOwner(e Engine) *User {
|
|
|
return repo.Owner
|
|
|
}
|
|
|
|
|
|
+// UpdateSize updates the repository size, calculating it using git.GetRepoSize
|
|
|
func (repo *Repository) UpdateSize() error {
|
|
|
countObject, err := git.GetRepoSize(repo.RepoPath())
|
|
|
if err != nil {
|
|
|
@@ -536,6 +556,7 @@ func (repo *Repository) IssueStats(userID int64, filterMode FilterMode, isPull b
|
|
|
return GetRepoIssueStats(repo.ID, userID, filterMode, isPull)
|
|
|
}
|
|
|
|
|
|
+// GetMirror sets the repository mirror, returns an error upon failure
|
|
|
func (repo *Repository) GetMirror() (err error) {
|
|
|
repo.Mirror, err = GetMirrorByRepoID(repo.ID)
|
|
|
return err
|
|
|
@@ -545,22 +566,27 @@ func (repo *Repository) repoPath(e Engine) string {
|
|
|
return RepoPath(repo.mustOwner(e).Name, repo.Name)
|
|
|
}
|
|
|
|
|
|
+// RepoPath returns the repository path
|
|
|
func (repo *Repository) RepoPath() string {
|
|
|
return repo.repoPath(x)
|
|
|
}
|
|
|
|
|
|
+// GitConfigPath returns the path to a repository's git config/ directory
|
|
|
func (repo *Repository) GitConfigPath() string {
|
|
|
return filepath.Join(repo.RepoPath(), "config")
|
|
|
}
|
|
|
|
|
|
+// RelLink returns the repository relative link
|
|
|
func (repo *Repository) RelLink() string {
|
|
|
return "/" + repo.FullName()
|
|
|
}
|
|
|
|
|
|
+// Link returns the repository link
|
|
|
func (repo *Repository) Link() string {
|
|
|
return setting.AppSubURL + "/" + repo.FullName()
|
|
|
}
|
|
|
|
|
|
+// ComposeCompareURL returns the repository comparison URL
|
|
|
func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) string {
|
|
|
return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID)
|
|
|
}
|