From 95c31f875913644f06c606cddbb4f5d3bfa76573 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 27 May 2024 10:04:48 +0800 Subject: [PATCH 1/2] Add test for IsUserAllowedToMerge with action user --- services/pull/merge_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/services/pull/merge_test.go b/services/pull/merge_test.go index 6df6f55d46115..b06614d2cfa6d 100644 --- a/services/pull/merge_test.go +++ b/services/pull/merge_test.go @@ -6,6 +6,12 @@ package pull import ( "testing" + "code.gitea.io/gitea/models/db" + issues_model "code.gitea.io/gitea/models/issues" + "code.gitea.io/gitea/models/perm/access" + repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/models/user" "github.com/stretchr/testify/assert" ) @@ -65,3 +71,16 @@ func Test_expandDefaultMergeMessage(t *testing.T) { }) } } + +func Test_IsUserAllowedToMerge(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2}) + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: pr.BaseRepoID}) + + perm, err := access.GetUserRepoPermission(db.DefaultContext, repo, user.NewActionsUser()) + assert.NoError(t, err) + + allowed, err := IsUserAllowedToMerge(db.DefaultContext, pr, perm, user.NewActionsUser()) + assert.NoError(t, err) + assert.False(t, allowed) +} From 5e3eb8446b5112c6511dc31feef817a9e1157079 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 27 May 2024 12:15:24 +0800 Subject: [PATCH 2/2] Fix lint --- services/pull/merge_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/services/pull/merge_test.go b/services/pull/merge_test.go index b06614d2cfa6d..219511b6c7207 100644 --- a/services/pull/merge_test.go +++ b/services/pull/merge_test.go @@ -12,6 +12,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" "code.gitea.io/gitea/models/user" + "github.com/stretchr/testify/assert" )