2024-05-07 07:36:48 +00:00
|
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package private
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
|
|
|
pull_model "code.gitea.io/gitea/models/pull"
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
|
|
"code.gitea.io/gitea/modules/private"
|
|
|
|
repo_module "code.gitea.io/gitea/modules/repository"
|
|
|
|
"code.gitea.io/gitea/services/contexttest"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 19:41:10 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2024-05-07 07:36:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestHandlePullRequestMerging(t *testing.T) {
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
2024-05-07 07:36:48 +00:00
|
|
|
pr, err := issues_model.GetUnmergedPullRequest(db.DefaultContext, 1, 1, "branch2", "master", issues_model.PullRequestFlowGithub)
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
|
2024-05-07 07:36:48 +00:00
|
|
|
|
|
|
|
user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
|
|
|
|
|
|
|
err = pull_model.ScheduleAutoMerge(db.DefaultContext, user1, pr.ID, repo_model.MergeStyleSquash, "squash merge a pr")
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2024-05-07 07:36:48 +00:00
|
|
|
|
|
|
|
autoMerge := unittest.AssertExistsAndLoadBean(t, &pull_model.AutoMerge{PullID: pr.ID})
|
|
|
|
|
|
|
|
ctx, resp := contexttest.MockPrivateContext(t, "/")
|
|
|
|
handlePullRequestMerging(ctx, &private.HookOptions{
|
|
|
|
PullRequestID: pr.ID,
|
|
|
|
UserID: 2,
|
|
|
|
}, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, []*repo_module.PushUpdateOptions{
|
|
|
|
{NewCommitID: "01234567"},
|
|
|
|
})
|
2024-07-30 19:41:10 +00:00
|
|
|
assert.Empty(t, resp.Body.String())
|
2024-05-07 07:36:48 +00:00
|
|
|
pr, err = issues_model.GetPullRequestByID(db.DefaultContext, pr.ID)
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2024-05-07 07:36:48 +00:00
|
|
|
assert.True(t, pr.HasMerged)
|
|
|
|
assert.EqualValues(t, "01234567", pr.MergedCommitID)
|
|
|
|
|
|
|
|
unittest.AssertNotExistsBean(t, &pull_model.AutoMerge{ID: autoMerge.ID})
|
|
|
|
}
|