mirror of
https://github.com/go-gitea/gitea.git
synced 2025-02-02 15:09:33 -05:00
Fix merge/automerge a pull request from actions runner task
This commit is contained in:
parent
a989404e23
commit
2bfdb662a5
@ -197,6 +197,7 @@ Gitea or set your environment appropriately.`, "")
|
|||||||
PullRequestID: prID,
|
PullRequestID: prID,
|
||||||
DeployKeyID: deployKeyID,
|
DeployKeyID: deployKeyID,
|
||||||
ActionPerm: int(actionPerm),
|
ActionPerm: int(actionPerm),
|
||||||
|
PushTrigger: repo_module.PushTrigger(os.Getenv(repo_module.EnvPushTrigger)),
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner := bufio.NewScanner(os.Stdin)
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
@ -74,7 +74,7 @@ func GetScheduledMergeByPullID(ctx context.Context, pullID int64) (bool, *AutoMe
|
|||||||
return false, nil, err
|
return false, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doer, err := user_model.GetUserByID(ctx, scheduledPRM.DoerID)
|
doer, err := user_model.GetPossibleUserByID(ctx, scheduledPRM.DoerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, nil, err
|
return false, nil, err
|
||||||
}
|
}
|
||||||
|
@ -332,7 +332,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
|
|||||||
|
|
||||||
func loadContextCacheUser(ctx context.Context, id int64) (*user_model.User, error) {
|
func loadContextCacheUser(ctx context.Context, id int64) (*user_model.User, error) {
|
||||||
return cache.GetWithContextCache(ctx, "hook_post_receive_user", id, func() (*user_model.User, error) {
|
return cache.GetWithContextCache(ctx, "hook_post_receive_user", id, func() (*user_model.User, error) {
|
||||||
return user_model.GetUserByID(ctx, id)
|
return user_model.GetPossibleUserByID(ctx, id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,14 +5,12 @@ package automerge
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
access_model "code.gitea.io/gitea/models/perm/access"
|
|
||||||
pull_model "code.gitea.io/gitea/models/pull"
|
pull_model "code.gitea.io/gitea/models/pull"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
@ -275,26 +273,15 @@ func handlePullRequestAutoMerge(pullID int64, sha string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Merge if all checks succeeded
|
// Merge if all checks succeeded
|
||||||
doer, err := user_model.GetUserByID(ctx, scheduledPRM.DoerID)
|
// Use GetPossibleUserByID to allow merging by deleted users or bot users
|
||||||
|
doer, err := user_model.GetPossibleUserByID(ctx, scheduledPRM.DoerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to get scheduled User[%d]: %v", scheduledPRM.DoerID, err)
|
log.Error("Unable to get scheduled User[%d]: %v", scheduledPRM.DoerID, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
perm, err := access_model.GetUserRepoPermission(ctx, pr.HeadRepo, doer)
|
// We don't check doer's permission here because their permissions have been checked
|
||||||
if err != nil {
|
// before ids were written to the auto_merge table
|
||||||
log.Error("GetUserRepoPermission %-v: %v", pr.HeadRepo, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := pull_service.CheckPullMergeable(ctx, doer, &perm, pr, pull_service.MergeCheckTypeGeneral, false); err != nil {
|
|
||||||
if errors.Is(err, pull_service.ErrUserNotAllowedToMerge) {
|
|
||||||
log.Info("%-v was scheduled to automerge by an unauthorized user", pr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Error("%-v CheckPullMergeable: %v", pr, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := pull_service.Merge(ctx, pr, doer, baseGitRepo, scheduledPRM.MergeStyle, "", scheduledPRM.Message, true); err != nil {
|
if err := pull_service.Merge(ctx, pr, doer, baseGitRepo, scheduledPRM.MergeStyle, "", scheduledPRM.Message, true); err != nil {
|
||||||
log.Error("pull_service.Merge: %v", err)
|
log.Error("pull_service.Merge: %v", err)
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
git_model "code.gitea.io/gitea/models/git"
|
git_model "code.gitea.io/gitea/models/git"
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
|
"code.gitea.io/gitea/models/perm"
|
||||||
access_model "code.gitea.io/gitea/models/perm/access"
|
access_model "code.gitea.io/gitea/models/perm/access"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
"code.gitea.io/gitea/models/unit"
|
"code.gitea.io/gitea/models/unit"
|
||||||
@ -331,6 +332,9 @@ func doMergeAndPush(ctx context.Context, pr *issues_model.PullRequest, doer *use
|
|||||||
)
|
)
|
||||||
|
|
||||||
mergeCtx.env = append(mergeCtx.env, repo_module.EnvPushTrigger+"="+string(pushTrigger))
|
mergeCtx.env = append(mergeCtx.env, repo_module.EnvPushTrigger+"="+string(pushTrigger))
|
||||||
|
if pushTrigger == repo_module.PushTriggerPRMergeToBase {
|
||||||
|
mergeCtx.env = append(mergeCtx.env, fmt.Sprintf("%s=%d", repo_module.EnvActionPerm, perm.AccessModeWrite))
|
||||||
|
}
|
||||||
pushCmd := git.NewCommand(ctx, "push", "origin").AddDynamicArguments(baseBranch + ":" + git.BranchPrefix + pr.BaseBranch)
|
pushCmd := git.NewCommand(ctx, "push", "origin").AddDynamicArguments(baseBranch + ":" + git.BranchPrefix + pr.BaseBranch)
|
||||||
|
|
||||||
// Push back to upstream.
|
// Push back to upstream.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user