mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 00:20:25 +08:00 
			
		
		
		
	migrate from com.* to alternatives (#14103)
* remove github.com/unknwon/com from models * dont use "com.ToStr()" * replace "com.ToStr" with "fmt.Sprint" where its easy to do * more refactor * fix test * just "proxy" Copy func for now * as per @lunny
This commit is contained in:
		@@ -10,8 +10,6 @@ import (
 | 
			
		||||
	"code.gitea.io/gitea/models"
 | 
			
		||||
	"code.gitea.io/gitea/modules/notification"
 | 
			
		||||
	"code.gitea.io/gitea/modules/sync"
 | 
			
		||||
 | 
			
		||||
	"github.com/unknwon/com"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// repoWorkingPool represents a working pool to order the parallel changes to the same repository
 | 
			
		||||
@@ -30,12 +28,12 @@ func TransferOwnership(doer, newOwner *models.User, repo *models.Repository, tea
 | 
			
		||||
 | 
			
		||||
	oldOwner := repo.Owner
 | 
			
		||||
 | 
			
		||||
	repoWorkingPool.CheckIn(com.ToStr(repo.ID))
 | 
			
		||||
	repoWorkingPool.CheckIn(fmt.Sprint(repo.ID))
 | 
			
		||||
	if err := models.TransferOwnership(doer, newOwner.Name, repo); err != nil {
 | 
			
		||||
		repoWorkingPool.CheckOut(com.ToStr(repo.ID))
 | 
			
		||||
		repoWorkingPool.CheckOut(fmt.Sprint(repo.ID))
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	repoWorkingPool.CheckOut(com.ToStr(repo.ID))
 | 
			
		||||
	repoWorkingPool.CheckOut(fmt.Sprint(repo.ID))
 | 
			
		||||
 | 
			
		||||
	newRepo, err := models.GetRepositoryByID(repo.ID)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -61,12 +59,12 @@ func ChangeRepositoryName(doer *models.User, repo *models.Repository, newRepoNam
 | 
			
		||||
	// repo so that we can atomically rename the repo path and updates the
 | 
			
		||||
	// local copy's origin accordingly.
 | 
			
		||||
 | 
			
		||||
	repoWorkingPool.CheckIn(com.ToStr(repo.ID))
 | 
			
		||||
	repoWorkingPool.CheckIn(fmt.Sprint(repo.ID))
 | 
			
		||||
	if err := models.ChangeRepositoryName(doer, repo, newRepoName); err != nil {
 | 
			
		||||
		repoWorkingPool.CheckOut(com.ToStr(repo.ID))
 | 
			
		||||
		repoWorkingPool.CheckOut(fmt.Sprint(repo.ID))
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	repoWorkingPool.CheckOut(com.ToStr(repo.ID))
 | 
			
		||||
	repoWorkingPool.CheckOut(fmt.Sprint(repo.ID))
 | 
			
		||||
 | 
			
		||||
	notification.NotifyRenameRepository(doer, repo, oldRepoName)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,9 +11,9 @@ import (
 | 
			
		||||
	"code.gitea.io/gitea/models"
 | 
			
		||||
	"code.gitea.io/gitea/modules/notification"
 | 
			
		||||
	"code.gitea.io/gitea/modules/notification/action"
 | 
			
		||||
	"code.gitea.io/gitea/modules/util"
 | 
			
		||||
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
	"github.com/unknwon/com"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var notifySync sync.Once
 | 
			
		||||
@@ -37,8 +37,12 @@ func TestTransferOwnership(t *testing.T) {
 | 
			
		||||
	transferredRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
 | 
			
		||||
	assert.EqualValues(t, 2, transferredRepo.OwnerID)
 | 
			
		||||
 | 
			
		||||
	assert.False(t, com.IsExist(models.RepoPath("user3", "repo3")))
 | 
			
		||||
	assert.True(t, com.IsExist(models.RepoPath("user2", "repo3")))
 | 
			
		||||
	exist, err := util.IsExist(models.RepoPath("user3", "repo3"))
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	assert.False(t, exist)
 | 
			
		||||
	exist, err = util.IsExist(models.RepoPath("user2", "repo3"))
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
	assert.True(t, exist)
 | 
			
		||||
	models.AssertExistsAndLoadBean(t, &models.Action{
 | 
			
		||||
		OpType:    models.ActionTransferRepo,
 | 
			
		||||
		ActUserID: 2,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user