|
|
|
@ -835,8 +835,8 @@ func wikiRemoteURL(remote string) string { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// MigrateRepository migrates a existing repository from other project hosting.
|
|
|
|
|
func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) { |
|
|
|
|
repo, err := CreateRepository(u, CreateRepoOptions{ |
|
|
|
|
func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, error) { |
|
|
|
|
repo, err := CreateRepository(doer, u, CreateRepoOptions{ |
|
|
|
|
Name: opts.Name, |
|
|
|
|
Description: opts.Description, |
|
|
|
|
IsPrivate: opts.IsPrivate, |
|
|
|
@ -1202,7 +1202,7 @@ func IsUsableRepoName(name string) error { |
|
|
|
|
return isUsableName(reservedRepoNames, reservedRepoPatterns, name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) { |
|
|
|
|
func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err error) { |
|
|
|
|
if err = IsUsableRepoName(repo.Name); err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
@ -1249,7 +1249,15 @@ func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) { |
|
|
|
|
return fmt.Errorf("getOwnerTeam: %v", err) |
|
|
|
|
} else if err = t.addRepository(e, repo); err != nil { |
|
|
|
|
return fmt.Errorf("addRepository: %v", err) |
|
|
|
|
} else if err = prepareWebhooks(e, repo, HookEventRepository, &api.RepositoryPayload{ |
|
|
|
|
Action: api.HookRepoCreated, |
|
|
|
|
Repository: repo.APIFormat(AccessModeOwner), |
|
|
|
|
Organization: u.APIFormat(), |
|
|
|
|
Sender: doer.APIFormat(), |
|
|
|
|
}); err != nil { |
|
|
|
|
return fmt.Errorf("prepareWebhooks: %v", err) |
|
|
|
|
} |
|
|
|
|
go HookQueue.Add(repo.ID) |
|
|
|
|
} else { |
|
|
|
|
// Organization automatically called this in addRepository method.
|
|
|
|
|
if err = repo.recalculateAccesses(e); err != nil { |
|
|
|
@ -1266,8 +1274,8 @@ func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// CreateRepository creates a repository for given user or organization.
|
|
|
|
|
func CreateRepository(u *User, opts CreateRepoOptions) (_ *Repository, err error) { |
|
|
|
|
// CreateRepository creates a repository for the user/organization u.
|
|
|
|
|
func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err error) { |
|
|
|
|
if !u.CanCreateRepo() { |
|
|
|
|
return nil, ErrReachLimitOfRepo{u.MaxRepoCreation} |
|
|
|
|
} |
|
|
|
@ -1287,7 +1295,7 @@ func CreateRepository(u *User, opts CreateRepoOptions) (_ *Repository, err error |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err = createRepository(sess, u, repo); err != nil { |
|
|
|
|
if err = createRepository(sess, doer, u, repo); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1623,7 +1631,7 @@ func UpdateRepositoryUnits(repo *Repository, units []RepoUnit) (err error) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// DeleteRepository deletes a repository for a user or organization.
|
|
|
|
|
func DeleteRepository(uid, repoID int64) error { |
|
|
|
|
func DeleteRepository(doer *User, uid, repoID int64) error { |
|
|
|
|
// In case is a organization.
|
|
|
|
|
org, err := GetUserByID(uid) |
|
|
|
|
if err != nil { |
|
|
|
@ -1781,6 +1789,18 @@ func DeleteRepository(uid, repoID int64) error { |
|
|
|
|
return fmt.Errorf("Commit: %v", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if org.IsOrganization() { |
|
|
|
|
if err = PrepareWebhooks(repo, HookEventRepository, &api.RepositoryPayload{ |
|
|
|
|
Action: api.HookRepoDeleted, |
|
|
|
|
Repository: repo.APIFormat(AccessModeOwner), |
|
|
|
|
Organization: org.APIFormat(), |
|
|
|
|
Sender: doer.APIFormat(), |
|
|
|
|
}); err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
go HookQueue.Add(repo.ID) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1974,7 +1994,7 @@ func gatherMissingRepoRecords() ([]*Repository, error) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// DeleteMissingRepositories deletes all repository records that lost Git files.
|
|
|
|
|
func DeleteMissingRepositories() error { |
|
|
|
|
func DeleteMissingRepositories(doer *User) error { |
|
|
|
|
repos, err := gatherMissingRepoRecords() |
|
|
|
|
if err != nil { |
|
|
|
|
return fmt.Errorf("gatherMissingRepoRecords: %v", err) |
|
|
|
@ -1986,7 +2006,7 @@ func DeleteMissingRepositories() error { |
|
|
|
|
|
|
|
|
|
for _, repo := range repos { |
|
|
|
|
log.Trace("Deleting %d/%d...", repo.OwnerID, repo.ID) |
|
|
|
|
if err := DeleteRepository(repo.OwnerID, repo.ID); err != nil { |
|
|
|
|
if err := DeleteRepository(doer, repo.OwnerID, repo.ID); err != nil { |
|
|
|
|
if err2 := CreateRepositoryNotice(fmt.Sprintf("DeleteRepository [%d]: %v", repo.ID, err)); err2 != nil { |
|
|
|
|
return fmt.Errorf("CreateRepositoryNotice: %v", err) |
|
|
|
|
} |
|
|
|
@ -2226,7 +2246,7 @@ func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ForkRepository forks a repository
|
|
|
|
|
func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) { |
|
|
|
|
func ForkRepository(doer, u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) { |
|
|
|
|
forkedRepo, err := oldRepo.GetUserFork(u.ID) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
@ -2256,7 +2276,7 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Reposit |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err = createRepository(sess, u, repo); err != nil { |
|
|
|
|
if err = createRepository(sess, doer, u, repo); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|