|
@@ -17,6 +17,8 @@ import (
|
|
|
"gitote/gitote/pkg/setting"
|
|
"gitote/gitote/pkg/setting"
|
|
|
"gitote/gitote/pkg/sync"
|
|
"gitote/gitote/pkg/sync"
|
|
|
"image"
|
|
"image"
|
|
|
|
|
+
|
|
|
|
|
+ // Package jpeg implements a JPEG image decoder and encoder.
|
|
|
_ "image/jpeg"
|
|
_ "image/jpeg"
|
|
|
"image/png"
|
|
"image/png"
|
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
@@ -592,11 +594,13 @@ func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) strin
|
|
|
return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID)
|
|
return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// HasAccess returns if the user has access to the repository
|
|
|
func (repo *Repository) HasAccess(userID int64) bool {
|
|
func (repo *Repository) HasAccess(userID int64) bool {
|
|
|
has, _ := HasAccess(userID, repo, AccessModeRead)
|
|
has, _ := HasAccess(userID, repo, AccessModeRead)
|
|
|
return has
|
|
return has
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// IsOwnedBy returns true when user owns this repository
|
|
|
func (repo *Repository) IsOwnedBy(userID int64) bool {
|
|
func (repo *Repository) IsOwnedBy(userID int64) bool {
|
|
|
return repo.OwnerID == userID
|
|
return repo.OwnerID == userID
|
|
|
}
|
|
}
|
|
@@ -611,11 +615,12 @@ func (repo *Repository) CanEnablePulls() bool {
|
|
|
return !repo.IsMirror && !repo.IsBare
|
|
return !repo.IsMirror && !repo.IsBare
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// AllowPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
|
|
|
|
|
|
|
+// AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
|
|
|
func (repo *Repository) AllowsPulls() bool {
|
|
func (repo *Repository) AllowsPulls() bool {
|
|
|
return repo.CanEnablePulls() && repo.EnablePulls
|
|
return repo.CanEnablePulls() && repo.EnablePulls
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// IsBranchRequirePullRequest returns true if brach require pull requests.
|
|
|
func (repo *Repository) IsBranchRequirePullRequest(name string) bool {
|
|
func (repo *Repository) IsBranchRequirePullRequest(name string) bool {
|
|
|
return IsBranchOfRepoRequirePullRequest(repo.ID, name)
|
|
return IsBranchOfRepoRequirePullRequest(repo.ID, name)
|
|
|
}
|
|
}
|
|
@@ -625,12 +630,14 @@ func (repo *Repository) CanEnableEditor() bool {
|
|
|
return !repo.IsMirror
|
|
return !repo.IsMirror
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// NextIssueIndex returns the next issue index
|
|
|
// FIXME: should have a mutex to prevent producing same index for two issues that are created
|
|
// FIXME: should have a mutex to prevent producing same index for two issues that are created
|
|
|
// closely enough.
|
|
// closely enough.
|
|
|
func (repo *Repository) NextIssueIndex() int64 {
|
|
func (repo *Repository) NextIssueIndex() int64 {
|
|
|
return int64(repo.NumIssues+repo.NumPulls) + 1
|
|
return int64(repo.NumIssues+repo.NumPulls) + 1
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// LocalCopyPath returns the local repository copy path.
|
|
|
func (repo *Repository) LocalCopyPath() string {
|
|
func (repo *Repository) LocalCopyPath() string {
|
|
|
return path.Join(setting.AppDataPath, "tmp/local-repo", com.ToStr(repo.ID))
|
|
return path.Join(setting.AppDataPath, "tmp/local-repo", com.ToStr(repo.ID))
|
|
|
}
|
|
}
|
|
@@ -749,6 +756,7 @@ func (repo *Repository) CloneLink() (cl *CloneLink) {
|
|
|
return repo.cloneLink(false)
|
|
return repo.cloneLink(false)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// MigrateRepoOptions represents migrate repo options
|
|
|
type MigrateRepoOptions struct {
|
|
type MigrateRepoOptions struct {
|
|
|
Name string
|
|
Name string
|
|
|
Description string
|
|
Description string
|
|
@@ -955,6 +963,7 @@ func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// CreateRepoOptions contains the create repository options
|
|
|
type CreateRepoOptions struct {
|
|
type CreateRepoOptions struct {
|
|
|
Name string
|
|
Name string
|
|
|
Description string
|
|
Description string
|
|
@@ -1692,6 +1701,7 @@ func GetRepositoryByID(id int64) (*Repository, error) {
|
|
|
return getRepositoryByID(x, id)
|
|
return getRepositoryByID(x, id)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// UserRepoOptions represents user repo options.
|
|
|
type UserRepoOptions struct {
|
|
type UserRepoOptions struct {
|
|
|
UserID int64
|
|
UserID int64
|
|
|
Private bool
|
|
Private bool
|
|
@@ -1754,6 +1764,7 @@ func GetRepositoryCount(u *User) (int64, error) {
|
|
|
return getRepositoryCount(x, u)
|
|
return getRepositoryCount(x, u)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// SearchRepoOptions represents search repo options.
|
|
|
type SearchRepoOptions struct {
|
|
type SearchRepoOptions struct {
|
|
|
Keyword string
|
|
Keyword string
|
|
|
OwnerID int64
|
|
OwnerID int64
|
|
@@ -2140,6 +2151,7 @@ func CheckRepoStats() {
|
|
|
// ***** END: Repository.NumForks *****
|
|
// ***** END: Repository.NumForks *****
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// RepositoryList holds repository list
|
|
|
type RepositoryList []*Repository
|
|
type RepositoryList []*Repository
|
|
|
|
|
|
|
|
func (repos RepositoryList) loadAttributes(e Engine) error {
|
|
func (repos RepositoryList) loadAttributes(e Engine) error {
|
|
@@ -2194,10 +2206,12 @@ func (repos RepositoryList) loadAttributes(e Engine) error {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// LoadAttributes loads all attributes
|
|
|
func (repos RepositoryList) LoadAttributes() error {
|
|
func (repos RepositoryList) LoadAttributes() error {
|
|
|
return repos.loadAttributes(x)
|
|
return repos.loadAttributes(x)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// MirrorRepositoryList holds mirror repository list
|
|
|
type MirrorRepositoryList []*Repository
|
|
type MirrorRepositoryList []*Repository
|
|
|
|
|
|
|
|
func (repos MirrorRepositoryList) loadAttributes(e Engine) error {
|
|
func (repos MirrorRepositoryList) loadAttributes(e Engine) error {
|
|
@@ -2229,6 +2243,7 @@ func (repos MirrorRepositoryList) loadAttributes(e Engine) error {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// LoadAttributes loads all attributes
|
|
|
func (repos MirrorRepositoryList) LoadAttributes() error {
|
|
func (repos MirrorRepositoryList) LoadAttributes() error {
|
|
|
return repos.loadAttributes(x)
|
|
return repos.loadAttributes(x)
|
|
|
}
|
|
}
|
|
@@ -2286,7 +2301,7 @@ func GetWatchers(repoID int64) ([]*Watch, error) {
|
|
|
return getWatchers(x, repoID)
|
|
return getWatchers(x, repoID)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Repository.GetWatchers returns range of users watching given 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)
|
|
@@ -2333,6 +2348,7 @@ func NotifyWatchers(act *Action) error {
|
|
|
return notifyWatchers(x, act)
|
|
return notifyWatchers(x, act)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// Star represents star onformation of repository.
|
|
|
type Star struct {
|
|
type Star struct {
|
|
|
ID int64
|
|
ID int64
|
|
|
UID int64 `xorm:"UNIQUE(s)"`
|
|
UID int64 `xorm:"UNIQUE(s)"`
|
|
@@ -2371,6 +2387,7 @@ func IsStaring(userID, repoID int64) bool {
|
|
|
return has
|
|
return has
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// GetStargazers returns the repository stars
|
|
|
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)
|
|
@@ -2382,13 +2399,6 @@ func (repo *Repository) GetStargazers(page int) ([]*User, error) {
|
|
|
return users, sess.Find(&users)
|
|
return users, sess.Find(&users)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// ___________ __
|
|
|
|
|
-// \_ _____/__________| | __
|
|
|
|
|
-// | __)/ _ \_ __ \ |/ /
|
|
|
|
|
-// | \( <_> ) | \/ <
|
|
|
|
|
-// \___ / \____/|__| |__|_ \
|
|
|
|
|
-// \/ \/
|
|
|
|
|
-
|
|
|
|
|
// HasForkedRepo checks if given user has already forked a repository.
|
|
// HasForkedRepo checks if given user has already forked a repository.
|
|
|
// When user has already forked, it returns true along with the repository.
|
|
// When user has already forked, it returns true along with the repository.
|
|
|
func HasForkedRepo(ownerID, repoID int64) (*Repository, bool, error) {
|
|
func HasForkedRepo(ownerID, repoID int64) (*Repository, bool, error) {
|
|
@@ -2472,6 +2482,7 @@ func ForkRepository(doer, owner *User, baseRepo *Repository, name, desc string)
|
|
|
return repo, nil
|
|
return repo, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// GetForks returns all the forks of the repository
|
|
|
func (repo *Repository) GetForks() ([]*Repository, error) {
|
|
func (repo *Repository) GetForks() ([]*Repository, error) {
|
|
|
forks := make([]*Repository, 0, repo.NumForks)
|
|
forks := make([]*Repository, 0, repo.NumForks)
|
|
|
if err := x.Find(&forks, &Repository{ForkID: repo.ID}); err != nil {
|
|
if err := x.Find(&forks, &Repository{ForkID: repo.ID}); err != nil {
|
|
@@ -2484,6 +2495,7 @@ func (repo *Repository) GetForks() ([]*Repository, error) {
|
|
|
return forks, nil
|
|
return forks, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// CreateNewBranch creates new branch
|
|
|
func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName string) (err error) {
|
|
func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName string) (err error) {
|
|
|
repoWorkingPool.CheckIn(com.ToStr(repo.ID))
|
|
repoWorkingPool.CheckIn(com.ToStr(repo.ID))
|
|
|
defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
|
|
defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
|