mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package automergequeue
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
issues_model "github.com/hanzoai/git/models/issues"
|
|
"github.com/hanzoai/git/modules/gitrepo"
|
|
"github.com/hanzoai/git/modules/log"
|
|
"github.com/hanzoai/git/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.IsStatusMergeable() {
|
|
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)
|
|
}
|