mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +00: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:
		| @@ -15,6 +15,7 @@ import ( | ||||
|  | ||||
| 	"code.gitea.io/gitea/models" | ||||
| 	"code.gitea.io/gitea/models/db" | ||||
| 	issues_model "code.gitea.io/gitea/models/issues" | ||||
| 	access_model "code.gitea.io/gitea/models/perm/access" | ||||
| 	repo_model "code.gitea.io/gitea/models/repo" | ||||
| 	"code.gitea.io/gitea/models/unit" | ||||
| @@ -44,9 +45,9 @@ var ( | ||||
| ) | ||||
|  | ||||
| // AddToTaskQueue adds itself to pull request test task queue. | ||||
| func AddToTaskQueue(pr *models.PullRequest) { | ||||
| func AddToTaskQueue(pr *issues_model.PullRequest) { | ||||
| 	err := prPatchCheckerQueue.PushFunc(strconv.FormatInt(pr.ID, 10), func() error { | ||||
| 		pr.Status = models.PullRequestStatusChecking | ||||
| 		pr.Status = issues_model.PullRequestStatusChecking | ||||
| 		err := pr.UpdateColsIfNotMerged("status") | ||||
| 		if err != nil { | ||||
| 			log.Error("AddToTaskQueue.UpdateCols[%d].(add to queue): %v", pr.ID, err) | ||||
| @@ -61,7 +62,7 @@ func AddToTaskQueue(pr *models.PullRequest) { | ||||
| } | ||||
|  | ||||
| // CheckPullMergable check if the pull mergable based on all conditions (branch protection, merge options, ...) | ||||
| func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *access_model.Permission, pr *models.PullRequest, manuallMerge, force bool) error { | ||||
| func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *access_model.Permission, pr *issues_model.PullRequest, manuallMerge, force bool) error { | ||||
| 	return db.WithTx(func(ctx context.Context) error { | ||||
| 		if pr.HasMerged { | ||||
| 			return ErrHasMerged | ||||
| @@ -114,7 +115,7 @@ func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *acce | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
| 		if noDeps, err := models.IssueNoDependenciesLeft(ctx, pr.Issue); err != nil { | ||||
| 		if noDeps, err := issues_model.IssueNoDependenciesLeft(ctx, pr.Issue); err != nil { | ||||
| 			return err | ||||
| 		} else if !noDeps { | ||||
| 			return ErrDependenciesLeft | ||||
| @@ -125,7 +126,7 @@ func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *acce | ||||
| } | ||||
|  | ||||
| // isSignedIfRequired check if merge will be signed if required | ||||
| func isSignedIfRequired(ctx context.Context, pr *models.PullRequest, doer *user_model.User) (bool, error) { | ||||
| func isSignedIfRequired(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User) (bool, error) { | ||||
| 	if err := pr.LoadProtectedBranchCtx(ctx); err != nil { | ||||
| 		return false, err | ||||
| 	} | ||||
| @@ -141,10 +142,10 @@ func isSignedIfRequired(ctx context.Context, pr *models.PullRequest, doer *user_ | ||||
|  | ||||
| // checkAndUpdateStatus checks if pull request is possible to leaving checking status, | ||||
| // and set to be either conflict or mergeable. | ||||
| func checkAndUpdateStatus(pr *models.PullRequest) { | ||||
| func checkAndUpdateStatus(pr *issues_model.PullRequest) { | ||||
| 	// Status is not changed to conflict means mergeable. | ||||
| 	if pr.Status == models.PullRequestStatusChecking { | ||||
| 		pr.Status = models.PullRequestStatusMergeable | ||||
| 	if pr.Status == issues_model.PullRequestStatusChecking { | ||||
| 		pr.Status = issues_model.PullRequestStatusMergeable | ||||
| 	} | ||||
|  | ||||
| 	// Make sure there is no waiting test to process before leaving the checking status. | ||||
| @@ -162,7 +163,7 @@ func checkAndUpdateStatus(pr *models.PullRequest) { | ||||
|  | ||||
| // getMergeCommit checks if a pull request got merged | ||||
| // Returns the git.Commit of the pull request if merged | ||||
| func getMergeCommit(ctx context.Context, pr *models.PullRequest) (*git.Commit, error) { | ||||
| func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Commit, error) { | ||||
| 	if pr.BaseRepo == nil { | ||||
| 		var err error | ||||
| 		pr.BaseRepo, err = repo_model.GetRepositoryByID(pr.BaseRepoID) | ||||
| @@ -230,7 +231,7 @@ func getMergeCommit(ctx context.Context, pr *models.PullRequest) (*git.Commit, e | ||||
|  | ||||
| // manuallyMerged checks if a pull request got manually merged | ||||
| // When a pull request got manually merged mark the pull request as merged | ||||
| func manuallyMerged(ctx context.Context, pr *models.PullRequest) bool { | ||||
| func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool { | ||||
| 	if err := pr.LoadBaseRepoCtx(ctx); err != nil { | ||||
| 		log.Error("PullRequest[%d].LoadBaseRepo: %v", pr.ID, err) | ||||
| 		return false | ||||
| @@ -254,7 +255,7 @@ func manuallyMerged(ctx context.Context, pr *models.PullRequest) bool { | ||||
| 	if commit != nil { | ||||
| 		pr.MergedCommitID = commit.ID.String() | ||||
| 		pr.MergedUnix = timeutil.TimeStamp(commit.Author.When.Unix()) | ||||
| 		pr.Status = models.PullRequestStatusManuallyMerged | ||||
| 		pr.Status = issues_model.PullRequestStatusManuallyMerged | ||||
| 		merger, _ := user_model.GetUserByEmail(commit.Author.Email) | ||||
|  | ||||
| 		// When the commit author is unknown set the BaseRepo owner as merger | ||||
| @@ -287,7 +288,7 @@ func manuallyMerged(ctx context.Context, pr *models.PullRequest) bool { | ||||
|  | ||||
| // InitializePullRequests checks and tests untested patches of pull requests. | ||||
| func InitializePullRequests(ctx context.Context) { | ||||
| 	prs, err := models.GetPullRequestIDsByCheckStatus(models.PullRequestStatusChecking) | ||||
| 	prs, err := issues_model.GetPullRequestIDsByCheckStatus(issues_model.PullRequestStatusChecking) | ||||
| 	if err != nil { | ||||
| 		log.Error("Find Checking PRs: %v", err) | ||||
| 		return | ||||
| @@ -323,7 +324,7 @@ func testPR(id int64) { | ||||
| 	ctx, _, finished := process.GetManager().AddContext(graceful.GetManager().HammerContext(), fmt.Sprintf("Test PR[%d] from patch checking queue", id)) | ||||
| 	defer finished() | ||||
|  | ||||
| 	pr, err := models.GetPullRequestByID(ctx, id) | ||||
| 	pr, err := issues_model.GetPullRequestByID(ctx, id) | ||||
| 	if err != nil { | ||||
| 		log.Error("GetPullRequestByID[%d]: %v", id, err) | ||||
| 		return | ||||
| @@ -339,7 +340,7 @@ func testPR(id int64) { | ||||
|  | ||||
| 	if err := TestPatch(pr); err != nil { | ||||
| 		log.Error("testPatch[%d]: %v", pr.ID, err) | ||||
| 		pr.Status = models.PullRequestStatusError | ||||
| 		pr.Status = issues_model.PullRequestStatusError | ||||
| 		if err := pr.UpdateCols("status"); err != nil { | ||||
| 			log.Error("update pr [%d] status to PullRequestStatusError failed: %v", pr.ID, err) | ||||
| 		} | ||||
| @@ -350,7 +351,7 @@ func testPR(id int64) { | ||||
|  | ||||
| // CheckPrsForBaseBranch check all pulls with bseBrannch | ||||
| func CheckPrsForBaseBranch(baseRepo *repo_model.Repository, baseBranchName string) error { | ||||
| 	prs, err := models.GetUnmergedPullRequestsByBaseInfo(baseRepo.ID, baseBranchName) | ||||
| 	prs, err := issues_model.GetUnmergedPullRequestsByBaseInfo(baseRepo.ID, baseBranchName) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Lunny Xiao
					Lunny Xiao