Skip to content

Add test for IsUserAllowedToMerge with action user #31094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

lunny
Copy link
Member

@lunny lunny commented May 27, 2024

Add a test for #31056

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 27, 2024
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label May 27, 2024
@@ -65,3 +72,16 @@ func Test_expandDefaultMergeMessage(t *testing.T) {
})
}
}

func Test_IsUserAllowedToMerge(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func Test_IsUserAllowedToMerge(t *testing.T) {
func Test_ActionsUserCannotMerge(t *testing.T) {

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 27, 2024
@yp05327
Copy link
Contributor

yp05327 commented May 29, 2024

image
The root reason is here.
We only check the permission, and ignore the doer when white list is disabled.
Action user has the permission, but should not be allowed to merge.
So if you change the permission in test, it will fail.

Copy link
Contributor

@yp05327 yp05327 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test is not correct

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 29, 2024
@yp05327
Copy link
Contributor

yp05327 commented May 29, 2024

more details:
image
if you print the permission and the user, you can see action user has the permission, so IsUserMergeWhitelisted will return true.
image

the workflow

name: test
on : push

jobs:  
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Test
        run: |
          jq -n '{
              "Do": "merge",
              "MergeCommitID": "xxxxxxxx",
              "MergeMessageField": "MergeMessageField",
              "MergeTitleField": "MergeTitleField",
              "delete_branch_after_merge": true,
              "force_merge": false,
              "head_commit_id": "xxxxxxxx",
              "merge_when_checks_succeed": true
          }' | curl "http://172.17.0.2:3000/api/v1/repos/testorg/testaction/pulls/5/merge" -H "accept: application/json" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Content-Type: application/json" -d @-

@yp05327
Copy link
Contributor

yp05327 commented May 29, 2024

the write permission comes from here:
image

@lunny
Copy link
Member Author

lunny commented May 30, 2024

Replaced by #31173

@lunny lunny closed this May 30, 2024
@lunny lunny deleted the lunny/test_for_IsUserAllowedToMerge branch May 30, 2024 07:20
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Aug 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged modifies/go Pull requests that update Go code type/testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants