mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	#1597 support pull requests in same repository
This commit is contained in:
		@@ -487,7 +487,7 @@ func (pr *PullRequest) UpdatePatch() (err error) {
 | 
			
		||||
// FIXME: could fail after user force push head repo, should we always force push here?
 | 
			
		||||
// FIXME: Only push branches that are actually updates?
 | 
			
		||||
func (pr *PullRequest) PushToBaseRepo() (err error) {
 | 
			
		||||
	log.Trace("PushToBaseRepo[%[1]d]: pushing commits to base repo 'refs/pull/%[1]d/head'", pr.ID)
 | 
			
		||||
	log.Trace("PushToBaseRepo[%d]: pushing commits to base repo 'refs/pull/%d/head'", pr.BaseRepoID, pr.Index)
 | 
			
		||||
 | 
			
		||||
	headRepoPath := pr.HeadRepo.RepoPath()
 | 
			
		||||
	headGitRepo, err := git.OpenRepository(headRepoPath)
 | 
			
		||||
 
 | 
			
		||||
@@ -184,6 +184,11 @@ type Repository struct {
 | 
			
		||||
 | 
			
		||||
func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
 | 
			
		||||
	switch colName {
 | 
			
		||||
	case "default_branch":
 | 
			
		||||
		// FIXME: use models migration to solve all at once.
 | 
			
		||||
		if len(repo.DefaultBranch) == 0 {
 | 
			
		||||
			repo.DefaultBranch = "master"
 | 
			
		||||
		}
 | 
			
		||||
	case "num_closed_issues":
 | 
			
		||||
		repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
 | 
			
		||||
	case "num_closed_pulls":
 | 
			
		||||
 
 | 
			
		||||
@@ -348,16 +348,10 @@ func (u *User) UploadAvatar(data []byte) error {
 | 
			
		||||
 | 
			
		||||
// IsAdminOfRepo returns true if user has admin or higher access of repository.
 | 
			
		||||
func (u *User) IsAdminOfRepo(repo *Repository) bool {
 | 
			
		||||
	if err := repo.GetOwner(); err != nil {
 | 
			
		||||
		log.Error(3, "GetOwner: %v", err)
 | 
			
		||||
		return false
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if repo.Owner.IsOrganization() {
 | 
			
		||||
	if repo.MustOwner().IsOrganization() {
 | 
			
		||||
		has, err := HasAccess(u, repo, ACCESS_MODE_ADMIN)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Error(3, "HasAccess: %v", err)
 | 
			
		||||
			return false
 | 
			
		||||
		}
 | 
			
		||||
		return has
 | 
			
		||||
	}
 | 
			
		||||
@@ -365,6 +359,15 @@ func (u *User) IsAdminOfRepo(repo *Repository) bool {
 | 
			
		||||
	return repo.IsOwnedBy(u.Id)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CanWriteTo returns true if user has write access to given repository.
 | 
			
		||||
func (u *User) CanWriteTo(repo *Repository) bool {
 | 
			
		||||
	has, err := HasAccess(u, repo, ACCESS_MODE_WRITE)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Error(3, "HasAccess: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
	return has
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsOrganization returns true if user is actually a organization.
 | 
			
		||||
func (u *User) IsOrganization() bool {
 | 
			
		||||
	return u.Type == ORGANIZATION
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user