|
|
@ -21,15 +21,15 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
"github.com/Unknwon/cae/zip" |
|
|
|
"github.com/Unknwon/cae/zip" |
|
|
|
"github.com/Unknwon/com" |
|
|
|
"github.com/Unknwon/com" |
|
|
|
|
|
|
|
"github.com/go-gitea/git" |
|
|
|
"github.com/go-gitea/gitea/modules/bindata" |
|
|
|
"github.com/go-gitea/gitea/modules/bindata" |
|
|
|
"github.com/go-gitea/gitea/modules/log" |
|
|
|
"github.com/go-gitea/gitea/modules/log" |
|
|
|
"github.com/go-gitea/gitea/modules/markdown" |
|
|
|
"github.com/go-gitea/gitea/modules/markdown" |
|
|
|
"github.com/go-gitea/gitea/modules/process" |
|
|
|
"github.com/go-gitea/gitea/modules/process" |
|
|
|
"github.com/go-gitea/gitea/modules/setting" |
|
|
|
"github.com/go-gitea/gitea/modules/setting" |
|
|
|
"github.com/go-gitea/gitea/modules/sync" |
|
|
|
"github.com/go-gitea/gitea/modules/sync" |
|
|
|
"github.com/go-xorm/xorm" |
|
|
|
|
|
|
|
"github.com/go-gitea/git" |
|
|
|
|
|
|
|
api "github.com/go-gitea/go-sdk/gitea" |
|
|
|
api "github.com/go-gitea/go-sdk/gitea" |
|
|
|
|
|
|
|
"github.com/go-xorm/xorm" |
|
|
|
version "github.com/mcuadros/go-version" |
|
|
|
version "github.com/mcuadros/go-version" |
|
|
|
ini "gopkg.in/ini.v1" |
|
|
|
ini "gopkg.in/ini.v1" |
|
|
|
) |
|
|
|
) |
|
|
@ -334,7 +334,9 @@ func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
accesses := make([]*Access, 0, 10) |
|
|
|
accesses := make([]*Access, 0, 10) |
|
|
|
if err = e.Where("repo_id = ? AND mode >= ?", repo.ID, AccessModeWrite).Find(&accesses); err != nil { |
|
|
|
if err = e. |
|
|
|
|
|
|
|
Where("repo_id = ? AND mode >= ?", repo.ID, AccessModeWrite). |
|
|
|
|
|
|
|
Find(&accesses); err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1209,7 +1211,9 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error) |
|
|
|
|
|
|
|
|
|
|
|
func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) { |
|
|
|
func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) { |
|
|
|
repos := make([]*Repository, 0, 10) |
|
|
|
repos := make([]*Repository, 0, 10) |
|
|
|
return repos, e.Where("fork_id=?", forkID).Find(&repos) |
|
|
|
return repos, e. |
|
|
|
|
|
|
|
Where("fork_id=?", forkID). |
|
|
|
|
|
|
|
Find(&repos) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetRepositoriesByForkID returns all repositories with given fork ID.
|
|
|
|
// GetRepositoriesByForkID returns all repositories with given fork ID.
|
|
|
@ -1341,7 +1345,9 @@ func DeleteRepository(uid, repoID int64) error { |
|
|
|
// Delete comments and attachments.
|
|
|
|
// Delete comments and attachments.
|
|
|
|
issues := make([]*Issue, 0, 25) |
|
|
|
issues := make([]*Issue, 0, 25) |
|
|
|
attachmentPaths := make([]string, 0, len(issues)) |
|
|
|
attachmentPaths := make([]string, 0, len(issues)) |
|
|
|
if err = sess.Where("repo_id=?", repoID).Find(&issues); err != nil { |
|
|
|
if err = sess. |
|
|
|
|
|
|
|
Where("repo_id=?", repoID). |
|
|
|
|
|
|
|
Find(&issues); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
for i := range issues { |
|
|
|
for i := range issues { |
|
|
@ -1350,7 +1356,9 @@ func DeleteRepository(uid, repoID int64) error { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
attachments := make([]*Attachment, 0, 5) |
|
|
|
attachments := make([]*Attachment, 0, 5) |
|
|
|
if err = sess.Where("issue_id=?", issues[i].ID).Find(&attachments); err != nil { |
|
|
|
if err = sess. |
|
|
|
|
|
|
|
Where("issue_id=?", issues[i].ID). |
|
|
|
|
|
|
|
Find(&attachments); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
for j := range attachments { |
|
|
|
for j := range attachments { |
|
|
@ -1450,7 +1458,9 @@ func GetRepositoryByID(id int64) (*Repository, error) { |
|
|
|
|
|
|
|
|
|
|
|
// GetUserRepositories returns a list of repositories of given user.
|
|
|
|
// GetUserRepositories returns a list of repositories of given user.
|
|
|
|
func GetUserRepositories(userID int64, private bool, page, pageSize int) ([]*Repository, error) { |
|
|
|
func GetUserRepositories(userID int64, private bool, page, pageSize int) ([]*Repository, error) { |
|
|
|
sess := x.Where("owner_id = ?", userID).Desc("updated_unix") |
|
|
|
sess := x. |
|
|
|
|
|
|
|
Where("owner_id = ?", userID). |
|
|
|
|
|
|
|
Desc("updated_unix") |
|
|
|
if !private { |
|
|
|
if !private { |
|
|
|
sess.And("is_private=?", false) |
|
|
|
sess.And("is_private=?", false) |
|
|
|
} |
|
|
|
} |
|
|
@ -1467,13 +1477,20 @@ func GetUserRepositories(userID int64, private bool, page, pageSize int) ([]*Rep |
|
|
|
// GetUserRepositories returns a list of mirror repositories of given user.
|
|
|
|
// GetUserRepositories returns a list of mirror repositories of given user.
|
|
|
|
func GetUserMirrorRepositories(userID int64) ([]*Repository, error) { |
|
|
|
func GetUserMirrorRepositories(userID int64) ([]*Repository, error) { |
|
|
|
repos := make([]*Repository, 0, 10) |
|
|
|
repos := make([]*Repository, 0, 10) |
|
|
|
return repos, x.Where("owner_id = ?", userID).And("is_mirror = ?", true).Find(&repos) |
|
|
|
return repos, x. |
|
|
|
|
|
|
|
Where("owner_id = ?", userID). |
|
|
|
|
|
|
|
And("is_mirror = ?", true). |
|
|
|
|
|
|
|
Find(&repos) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetRecentUpdatedRepositories returns the list of repositories that are recently updated.
|
|
|
|
// GetRecentUpdatedRepositories returns the list of repositories that are recently updated.
|
|
|
|
func GetRecentUpdatedRepositories(page, pageSize int) (repos []*Repository, err error) { |
|
|
|
func GetRecentUpdatedRepositories(page, pageSize int) (repos []*Repository, err error) { |
|
|
|
return repos, x.Limit(pageSize, (page-1)*pageSize). |
|
|
|
return repos, x. |
|
|
|
Where("is_private=?", false).Limit(pageSize).Desc("updated_unix").Find(&repos) |
|
|
|
Limit(pageSize, (page-1)*pageSize). |
|
|
|
|
|
|
|
Where("is_private=?", false). |
|
|
|
|
|
|
|
Limit(pageSize). |
|
|
|
|
|
|
|
Desc("updated_unix"). |
|
|
|
|
|
|
|
Find(&repos) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getRepositoryCount(e Engine, u *User) (int64, error) { |
|
|
|
func getRepositoryCount(e Engine, u *User) (int64, error) { |
|
|
@ -1532,7 +1549,9 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, _ int |
|
|
|
|
|
|
|
|
|
|
|
// DeleteRepositoryArchives deletes all repositories' archives.
|
|
|
|
// DeleteRepositoryArchives deletes all repositories' archives.
|
|
|
|
func DeleteRepositoryArchives() error { |
|
|
|
func DeleteRepositoryArchives() error { |
|
|
|
return x.Where("id > 0").Iterate(new(Repository), |
|
|
|
return x. |
|
|
|
|
|
|
|
Where("id > 0"). |
|
|
|
|
|
|
|
Iterate(new(Repository), |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
repo := bean.(*Repository) |
|
|
|
repo := bean.(*Repository) |
|
|
|
return os.RemoveAll(filepath.Join(repo.RepoPath(), "archives")) |
|
|
|
return os.RemoveAll(filepath.Join(repo.RepoPath(), "archives")) |
|
|
@ -1541,7 +1560,9 @@ func DeleteRepositoryArchives() error { |
|
|
|
|
|
|
|
|
|
|
|
func gatherMissingRepoRecords() ([]*Repository, error) { |
|
|
|
func gatherMissingRepoRecords() ([]*Repository, error) { |
|
|
|
repos := make([]*Repository, 0, 10) |
|
|
|
repos := make([]*Repository, 0, 10) |
|
|
|
if err := x.Where("id > 0").Iterate(new(Repository), |
|
|
|
if err := x. |
|
|
|
|
|
|
|
Where("id > 0"). |
|
|
|
|
|
|
|
Iterate(new(Repository), |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
repo := bean.(*Repository) |
|
|
|
repo := bean.(*Repository) |
|
|
|
if !com.IsDir(repo.RepoPath()) { |
|
|
|
if !com.IsDir(repo.RepoPath()) { |
|
|
@ -1602,7 +1623,9 @@ func ReinitMissingRepositories() error { |
|
|
|
|
|
|
|
|
|
|
|
// RewriteRepositoryUpdateHook rewrites all repositories' update hook.
|
|
|
|
// RewriteRepositoryUpdateHook rewrites all repositories' update hook.
|
|
|
|
func RewriteRepositoryUpdateHook() error { |
|
|
|
func RewriteRepositoryUpdateHook() error { |
|
|
|
return x.Where("id > 0").Iterate(new(Repository), |
|
|
|
return x. |
|
|
|
|
|
|
|
Where("id > 0"). |
|
|
|
|
|
|
|
Iterate(new(Repository), |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
repo := bean.(*Repository) |
|
|
|
repo := bean.(*Repository) |
|
|
|
return createUpdateHook(repo.RepoPath()) |
|
|
|
return createUpdateHook(repo.RepoPath()) |
|
|
@ -1628,7 +1651,9 @@ func GitFsck() { |
|
|
|
|
|
|
|
|
|
|
|
log.Trace("Doing: GitFsck") |
|
|
|
log.Trace("Doing: GitFsck") |
|
|
|
|
|
|
|
|
|
|
|
if err := x.Where("id>0").Iterate(new(Repository), |
|
|
|
if err := x. |
|
|
|
|
|
|
|
Where("id>0"). |
|
|
|
|
|
|
|
Iterate(new(Repository), |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
repo := bean.(*Repository) |
|
|
|
repo := bean.(*Repository) |
|
|
|
repoPath := repo.RepoPath() |
|
|
|
repoPath := repo.RepoPath() |
|
|
@ -1647,7 +1672,9 @@ func GitFsck() { |
|
|
|
|
|
|
|
|
|
|
|
func GitGcRepos() error { |
|
|
|
func GitGcRepos() error { |
|
|
|
args := append([]string{"gc"}, setting.Git.GCArgs...) |
|
|
|
args := append([]string{"gc"}, setting.Git.GCArgs...) |
|
|
|
return x.Where("id > 0").Iterate(new(Repository), |
|
|
|
return x. |
|
|
|
|
|
|
|
Where("id > 0"). |
|
|
|
|
|
|
|
Iterate(new(Repository), |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
repo := bean.(*Repository) |
|
|
|
repo := bean.(*Repository) |
|
|
|
if err := repo.GetOwner(); err != nil { |
|
|
|
if err := repo.GetOwner(); err != nil { |
|
|
@ -1796,7 +1823,10 @@ func (repos RepositoryList) loadAttributes(e Engine) error { |
|
|
|
userIDs = append(userIDs, userID) |
|
|
|
userIDs = append(userIDs, userID) |
|
|
|
} |
|
|
|
} |
|
|
|
users := make([]*User, 0, len(userIDs)) |
|
|
|
users := make([]*User, 0, len(userIDs)) |
|
|
|
if err := e.Where("id > 0").In("id", userIDs).Find(&users); err != nil { |
|
|
|
if err := e. |
|
|
|
|
|
|
|
Where("id > 0"). |
|
|
|
|
|
|
|
In("id", userIDs). |
|
|
|
|
|
|
|
Find(&users); err != nil { |
|
|
|
return fmt.Errorf("find users: %v", err) |
|
|
|
return fmt.Errorf("find users: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
for i := range users { |
|
|
|
for i := range users { |
|
|
@ -1829,7 +1859,10 @@ func (repos MirrorRepositoryList) loadAttributes(e Engine) error { |
|
|
|
repoIDs = append(repoIDs, repos[i].ID) |
|
|
|
repoIDs = append(repoIDs, repos[i].ID) |
|
|
|
} |
|
|
|
} |
|
|
|
mirrors := make([]*Mirror, 0, len(repoIDs)) |
|
|
|
mirrors := make([]*Mirror, 0, len(repoIDs)) |
|
|
|
if err := e.Where("id > 0").In("repo_id", repoIDs).Find(&mirrors); err != nil { |
|
|
|
if err := e. |
|
|
|
|
|
|
|
Where("id > 0"). |
|
|
|
|
|
|
|
In("repo_id", repoIDs). |
|
|
|
|
|
|
|
Find(&mirrors); err != nil { |
|
|
|
return fmt.Errorf("find mirrors: %v", err) |
|
|
|
return fmt.Errorf("find mirrors: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1910,7 +1943,9 @@ func GetWatchers(repoID int64) ([]*Watch, error) { |
|
|
|
// Repository.GetWatchers returns range of users watching given repository.
|
|
|
|
// Repository.GetWatchers returns range of users watching given repository.
|
|
|
|
func (repo *Repository) GetWatchers(page int) ([]*User, error) { |
|
|
|
func (repo *Repository) GetWatchers(page int) ([]*User, error) { |
|
|
|
users := make([]*User, 0, ItemsPerPage) |
|
|
|
users := make([]*User, 0, ItemsPerPage) |
|
|
|
sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("watch.repo_id=?", repo.ID) |
|
|
|
sess := x. |
|
|
|
|
|
|
|
Limit(ItemsPerPage, (page-1)*ItemsPerPage). |
|
|
|
|
|
|
|
Where("watch.repo_id=?", repo.ID) |
|
|
|
if setting.UsePostgreSQL { |
|
|
|
if setting.UsePostgreSQL { |
|
|
|
sess = sess.Join("LEFT", "watch", `"user".id=watch.user_id`) |
|
|
|
sess = sess.Join("LEFT", "watch", `"user".id=watch.user_id`) |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -1998,7 +2033,9 @@ func IsStaring(userID, repoID int64) bool { |
|
|
|
|
|
|
|
|
|
|
|
func (repo *Repository) GetStargazers(page int) ([]*User, error) { |
|
|
|
func (repo *Repository) GetStargazers(page int) ([]*User, error) { |
|
|
|
users := make([]*User, 0, ItemsPerPage) |
|
|
|
users := make([]*User, 0, ItemsPerPage) |
|
|
|
sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("star.repo_id=?", repo.ID) |
|
|
|
sess := x. |
|
|
|
|
|
|
|
Limit(ItemsPerPage, (page-1)*ItemsPerPage). |
|
|
|
|
|
|
|
Where("star.repo_id=?", repo.ID) |
|
|
|
if setting.UsePostgreSQL { |
|
|
|
if setting.UsePostgreSQL { |
|
|
|
sess = sess.Join("LEFT", "star", `"user".id=star.uid`) |
|
|
|
sess = sess.Join("LEFT", "star", `"user".id=star.uid`) |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -2017,7 +2054,9 @@ func (repo *Repository) GetStargazers(page int) ([]*User, error) { |
|
|
|
// HasForkedRepo checks if given user has already forked a repository with given ID.
|
|
|
|
// HasForkedRepo checks if given user has already forked a repository with given ID.
|
|
|
|
func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) { |
|
|
|
func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) { |
|
|
|
repo := new(Repository) |
|
|
|
repo := new(Repository) |
|
|
|
has, _ := x.Where("owner_id=? AND fork_id=?", ownerID, repoID).Get(repo) |
|
|
|
has, _ := x. |
|
|
|
|
|
|
|
Where("owner_id=? AND fork_id=?", ownerID, repoID). |
|
|
|
|
|
|
|
Get(repo) |
|
|
|
return repo, has |
|
|
|
return repo, has |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|