Skip to content

Conversation

kemzeb
Copy link
Member

@kemzeb kemzeb commented Sep 14, 2025

Fix #35463.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 14, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Sep 14, 2025
@kemzeb
Copy link
Member Author

kemzeb commented Sep 14, 2025

The logic has been implemented, but for tests I need to figure out how to work with the git database in the test environment.

Did not see issues when manual-testing the following:

  • Merge with delete branch when merge repo setting is set
  • Merge with delete branch when merge API form field is set
  • Merge without either fields set

@kemzeb
Copy link
Member Author

kemzeb commented Sep 29, 2025

Update: Will get to adding the tests, just been busy.

@kemzeb
Copy link
Member Author

kemzeb commented Oct 19, 2025

I already written the API integration tests, just having problems with the test repos. I need to use the git hooks in repo1 as they are used, among other things, to update pull request information.

However, I am getting "pre-receive hook declined" when the test code attempts to push back the changes to the original repo from the temp repo that is created by Gitea. Looking for solutions.

@kemzeb
Copy link
Member Author

kemzeb commented Oct 19, 2025

Created some integration tests covering some of the merge request API.

One thing I realized is that my changes will delete the branch after merge even if delete_branch_after_merge is not specified as a form field. I think the form field should take precedence over the repo setting equivalent. If the form field is not defined, we turn to the repo settings to make a determination.

Though, the form field is defined as a bool, not as some optional type. Need to figure out how to handle this.

@kemzeb kemzeb marked this pull request as ready for review October 19, 2025 20:11
@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 Oct 20, 2025
@lunny lunny added this to the 1.26.0 milestone Oct 20, 2025
})
}

func creatPullRequestWithCommit(t *testing.T, user *user_model.User, token, newBranch string, repo *repo_model.Repository) *api.PullRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicates:

  • createFileInBranch
  • doAPICreatePullRequest

Copy link
Member Author

Choose a reason for hiding this comment

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

da4bb40 uses doAPICreatePullRequest(), but I don't think I can use createFileInBranch() as it won't allow me to create a new branch

Copy link
Contributor

Choose a reason for hiding this comment

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

It can be done with some small changes 64db368

MakeRequest(t, req, http.StatusOK)
doCheckBranchExists(t, owner, token, newBranch, repo, http.StatusOK)
// make sure we cannot perform a merge on the same PR
MakeRequest(t, req, http.StatusUnprocessableEntity)
Copy link
Contributor

@wxiaoguang wxiaoguang Oct 21, 2025

Choose a reason for hiding this comment

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

This test is not right. StatusUnprocessableEntity is caused by reused req, it is an error caused by client, but not the "already merged" error.

The "already merged" error code is 405 (well, it is abused ... but old code does so)

Comment on lines 1038 to 1049
// for agit flow, we should not delete the agit reference after merge
if form.DeleteBranchAfterMerge && pr.Flow == issues_model.PullRequestFlowGithub {
// FIXME: old code has that comment above. Is that comment valid? What would go wrong if a agit branch is deleted after merge?
// * If a agit branch can be deleted after merge, then fix the comment and maybe other related code
// * If a agit branch should not be deleted, then we need to fix the logic and add more tests
Copy link
Contributor

Choose a reason for hiding this comment

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

Now we have a new question, I think it needs to be addressed.

Maybe @lunny @a1012112796 have some ideas

Copy link
Contributor

Choose a reason for hiding this comment

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

I answered myself by rewriting the old code, and fixed more legacy problems together.

@wxiaoguang wxiaoguang force-pushed the fix/inherit-merge-api-delete-branch-repo-settings branch 2 times, most recently from eeaef77 to 8438de6 Compare October 21, 2025 11:18
@github-actions github-actions bot added the modifies/templates This PR modifies the template files label Oct 21, 2025
@wxiaoguang wxiaoguang force-pushed the fix/inherit-merge-api-delete-branch-repo-settings branch from 8438de6 to a68474a Compare October 21, 2025 11:32
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/v1.25 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merging a PR via the API does not honor the Delete pull request branch after merge by default setting

4 participants