Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package automergequeue
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
issues_model "code.gitcaddy.com/server/v3/models/issues"
|
|
"code.gitcaddy.com/server/v3/modules/gitrepo"
|
|
"code.gitcaddy.com/server/v3/modules/log"
|
|
"code.gitcaddy.com/server/v3/modules/queue"
|
|
)
|
|
|
|
var AutoMergeQueue *queue.WorkerPoolQueue[string]
|
|
|
|
var AddToQueue = func(pr *issues_model.PullRequest, sha string) {
|
|
log.Trace("Adding pullID: %d to the pull requests patch checking queue with sha %s", pr.ID, sha)
|
|
if err := AutoMergeQueue.Push(fmt.Sprintf("%d_%s", pr.ID, sha)); err != nil && !errors.Is(err, queue.ErrAlreadyInQueue) {
|
|
log.Error("Error adding pullID: %d to the pull requests patch checking queue %v", pr.ID, err)
|
|
}
|
|
}
|
|
|
|
// StartPRCheckAndAutoMerge start an automerge check and auto merge task for a pull request
|
|
func StartPRCheckAndAutoMerge(ctx context.Context, pull *issues_model.PullRequest) {
|
|
if pull == nil || pull.HasMerged || !pull.CanAutoMerge() {
|
|
return
|
|
}
|
|
|
|
if err := pull.LoadBaseRepo(ctx); err != nil {
|
|
log.Error("LoadBaseRepo: %v", err)
|
|
return
|
|
}
|
|
|
|
gitRepo, err := gitrepo.OpenRepository(ctx, pull.BaseRepo)
|
|
if err != nil {
|
|
log.Error("OpenRepository: %v", err)
|
|
return
|
|
}
|
|
defer gitRepo.Close()
|
|
commitID, err := gitRepo.GetRefCommitID(pull.GetGitHeadRefName())
|
|
if err != nil {
|
|
log.Error("GetRefCommitID: %v", err)
|
|
return
|
|
}
|
|
|
|
AddToQueue(pull, commitID)
|
|
}
|