1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-15 22:54:24 +00:00

wip yES i Know theres is a cycle

This commit is contained in:
6543 2023-07-07 08:00:41 +02:00 committed by Lunny Xiao
parent 059b2718a5
commit f51af184fb
2 changed files with 12 additions and 3 deletions

View File

@ -95,8 +95,8 @@ func RemoveScheduledAutoMerge(ctx context.Context, doer *user_model.User, pull *
}) })
} }
// MergeScheduledPullRequest merges a previously scheduled pull request when all checks succeeded // MergeScheduledPullRequestsBySha merges a previously scheduled pull request(s) when all checks succeeded
func MergeScheduledPullRequest(ctx context.Context, sha string, repo *repo_model.Repository) error { func MergeScheduledPullRequestsBySha(ctx context.Context, sha string, repo *repo_model.Repository) error {
pulls, err := getPullRequestsByHeadSHA(ctx, sha, repo, func(pr *issues_model.PullRequest) bool { pulls, err := getPullRequestsByHeadSHA(ctx, sha, repo, func(pr *issues_model.PullRequest) bool {
return !pr.HasMerged && pr.CanAutoMerge() return !pr.HasMerged && pr.CanAutoMerge()
}) })
@ -111,6 +111,15 @@ func MergeScheduledPullRequest(ctx context.Context, sha string, repo *repo_model
return nil return nil
} }
// MergeScheduledPullRequest merges a previously scheduled pull request when all checks succeeded
func MergeScheduledPullRequest(pull *issues_model.PullRequest) {
if pull == nil || pull.HasMerged || !pull.CanAutoMerge() {
return
}
addToQueue(pull, pull.HeadCommitID)
}
func getPullRequestsByHeadSHA(ctx context.Context, sha string, repo *repo_model.Repository, filter func(*issues_model.PullRequest) bool) (map[int64]*issues_model.PullRequest, error) { func getPullRequestsByHeadSHA(ctx context.Context, sha string, repo *repo_model.Repository, filter func(*issues_model.PullRequest) bool) (map[int64]*issues_model.PullRequest, error) {
gitRepo, err := gitrepo.OpenRepository(ctx, repo) gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil { if err != nil {

View File

@ -115,7 +115,7 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
} }
if status.State.IsSuccess() { if status.State.IsSuccess() {
if err := automerge.MergeScheduledPullRequest(ctx, sha, repo); err != nil { if err := automerge.MergeScheduledPullRequestsBySha(ctx, sha, repo); err != nil {
return fmt.Errorf("MergeScheduledPullRequest[repo_id: %d, user_id: %d, sha: %s]: %w", repo.ID, creator.ID, sha, err) return fmt.Errorf("MergeScheduledPullRequest[repo_id: %d, user_id: %d, sha: %s]: %w", repo.ID, creator.ID, sha, err)
} }
} }