mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Move issues related files into models/issues (#19931)
* Move access and repo permission to models/perm/access * fix test * fix git test * Move functions sequence * Some improvements per @KN4CK3R and @delvh * Move issues related code to models/issues * Move some issues related sub package * Merge * Fix test * Fix test * Fix test * Fix test * Rename some files
This commit is contained in:
		@@ -9,6 +9,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/models"
 | 
			
		||||
	"code.gitea.io/gitea/models/db"
 | 
			
		||||
	issues_model "code.gitea.io/gitea/models/issues"
 | 
			
		||||
	"code.gitea.io/gitea/models/migrations"
 | 
			
		||||
	repo_model "code.gitea.io/gitea/models/repo"
 | 
			
		||||
	"code.gitea.io/gitea/modules/log"
 | 
			
		||||
@@ -64,10 +65,10 @@ func genericOrphanCheck(name, subject, refobject, joincond string) consistencyCh
 | 
			
		||||
	return consistencyCheck{
 | 
			
		||||
		Name: name,
 | 
			
		||||
		Counter: func() (int64, error) {
 | 
			
		||||
			return models.CountOrphanedObjects(subject, refobject, joincond)
 | 
			
		||||
			return db.CountOrphanedObjects(subject, refobject, joincond)
 | 
			
		||||
		},
 | 
			
		||||
		Fixer: func() (int64, error) {
 | 
			
		||||
			err := models.DeleteOrphanedObjects(subject, refobject, joincond)
 | 
			
		||||
			err := db.DeleteOrphanedObjects(subject, refobject, joincond)
 | 
			
		||||
			return -1, err
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
@@ -84,20 +85,20 @@ func checkDBConsistency(ctx context.Context, logger log.Logger, autofix bool) er
 | 
			
		||||
		{
 | 
			
		||||
			// find labels without existing repo or org
 | 
			
		||||
			Name:    "Orphaned Labels without existing repository or organisation",
 | 
			
		||||
			Counter: models.CountOrphanedLabels,
 | 
			
		||||
			Fixer:   asFixer(models.DeleteOrphanedLabels),
 | 
			
		||||
			Counter: issues_model.CountOrphanedLabels,
 | 
			
		||||
			Fixer:   asFixer(issues_model.DeleteOrphanedLabels),
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			// find IssueLabels without existing label
 | 
			
		||||
			Name:    "Orphaned Issue Labels without existing label",
 | 
			
		||||
			Counter: models.CountOrphanedIssueLabels,
 | 
			
		||||
			Fixer:   asFixer(models.DeleteOrphanedIssueLabels),
 | 
			
		||||
			Counter: issues_model.CountOrphanedIssueLabels,
 | 
			
		||||
			Fixer:   asFixer(issues_model.DeleteOrphanedIssueLabels),
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			// find issues without existing repository
 | 
			
		||||
			Name:    "Orphaned Issues without existing repository",
 | 
			
		||||
			Counter: models.CountOrphanedIssues,
 | 
			
		||||
			Fixer:   asFixer(models.DeleteOrphanedIssues),
 | 
			
		||||
			Counter: issues_model.CountOrphanedIssues,
 | 
			
		||||
			Fixer:   asFixer(issues_model.DeleteOrphanedIssues),
 | 
			
		||||
		},
 | 
			
		||||
		// find releases without existing repository
 | 
			
		||||
		genericOrphanCheck("Orphaned Releases without existing repository",
 | 
			
		||||
@@ -127,22 +128,22 @@ func checkDBConsistency(ctx context.Context, logger log.Logger, autofix bool) er
 | 
			
		||||
		// find label comments with empty labels
 | 
			
		||||
		{
 | 
			
		||||
			Name:         "Label comments with empty labels",
 | 
			
		||||
			Counter:      models.CountCommentTypeLabelWithEmptyLabel,
 | 
			
		||||
			Fixer:        models.FixCommentTypeLabelWithEmptyLabel,
 | 
			
		||||
			Counter:      issues_model.CountCommentTypeLabelWithEmptyLabel,
 | 
			
		||||
			Fixer:        issues_model.FixCommentTypeLabelWithEmptyLabel,
 | 
			
		||||
			FixedMessage: "Fixed",
 | 
			
		||||
		},
 | 
			
		||||
		// find label comments with labels from outside the repository
 | 
			
		||||
		{
 | 
			
		||||
			Name:         "Label comments with labels from outside the repository",
 | 
			
		||||
			Counter:      models.CountCommentTypeLabelWithOutsideLabels,
 | 
			
		||||
			Fixer:        models.FixCommentTypeLabelWithOutsideLabels,
 | 
			
		||||
			Counter:      issues_model.CountCommentTypeLabelWithOutsideLabels,
 | 
			
		||||
			Fixer:        issues_model.FixCommentTypeLabelWithOutsideLabels,
 | 
			
		||||
			FixedMessage: "Removed",
 | 
			
		||||
		},
 | 
			
		||||
		// find issue_label with labels from outside the repository
 | 
			
		||||
		{
 | 
			
		||||
			Name:         "IssueLabels with Labels from outside the repository",
 | 
			
		||||
			Counter:      models.CountIssueLabelWithOutsideLabels,
 | 
			
		||||
			Fixer:        models.FixIssueLabelWithOutsideLabels,
 | 
			
		||||
			Counter:      issues_model.CountIssueLabelWithOutsideLabels,
 | 
			
		||||
			Fixer:        issues_model.FixIssueLabelWithOutsideLabels,
 | 
			
		||||
			FixedMessage: "Removed",
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
 
 | 
			
		||||
@@ -9,8 +9,8 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/models"
 | 
			
		||||
	"code.gitea.io/gitea/models/db"
 | 
			
		||||
	issues_model "code.gitea.io/gitea/models/issues"
 | 
			
		||||
	repo_model "code.gitea.io/gitea/models/repo"
 | 
			
		||||
	"code.gitea.io/gitea/modules/git"
 | 
			
		||||
	"code.gitea.io/gitea/modules/log"
 | 
			
		||||
@@ -18,13 +18,13 @@ import (
 | 
			
		||||
	"xorm.io/builder"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func iteratePRs(ctx context.Context, repo *repo_model.Repository, each func(*repo_model.Repository, *models.PullRequest) error) error {
 | 
			
		||||
func iteratePRs(ctx context.Context, repo *repo_model.Repository, each func(*repo_model.Repository, *issues_model.PullRequest) error) error {
 | 
			
		||||
	return db.Iterate(
 | 
			
		||||
		ctx,
 | 
			
		||||
		new(models.PullRequest),
 | 
			
		||||
		new(issues_model.PullRequest),
 | 
			
		||||
		builder.Eq{"base_repo_id": repo.ID},
 | 
			
		||||
		func(idx int, bean interface{}) error {
 | 
			
		||||
			return each(repo, bean.(*models.PullRequest))
 | 
			
		||||
			return each(repo, bean.(*issues_model.PullRequest))
 | 
			
		||||
		},
 | 
			
		||||
	)
 | 
			
		||||
}
 | 
			
		||||
@@ -35,7 +35,7 @@ func checkPRMergeBase(ctx context.Context, logger log.Logger, autofix bool) erro
 | 
			
		||||
	numPRsUpdated := 0
 | 
			
		||||
	err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
 | 
			
		||||
		numRepos++
 | 
			
		||||
		return iteratePRs(ctx, repo, func(repo *repo_model.Repository, pr *models.PullRequest) error {
 | 
			
		||||
		return iteratePRs(ctx, repo, func(repo *repo_model.Repository, pr *issues_model.PullRequest) error {
 | 
			
		||||
			numPRs++
 | 
			
		||||
			pr.BaseRepo = repo
 | 
			
		||||
			repoPath := repo.RepoPath()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user