fix(api): issue state change is not idempotent
The PATCH if issue & pull request switched to use the service
functions instead. However, the service function changing the state is
not idempotent. Instead of doing nothing which changing from open to
open or close to close, it will fail with an error like:
Issue [2472] 0 was already closed
Regression of: 6a4bc0289d
Fixes: https://codeberg.org/forgejo/forgejo/issues/4686
This commit is contained in:
parent
f8bc48f8df
commit
e9e3b8c0f3
4 changed files with 44 additions and 12 deletions
|
@ -236,7 +236,8 @@ func TestAPIEditPull(t *testing.T) {
|
|||
|
||||
newTitle := "edit a this pr"
|
||||
newBody := "edited body"
|
||||
req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d", owner10.Name, repo10.Name, apiPull.Index), &api.EditPullRequestOption{
|
||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d", owner10.Name, repo10.Name, apiPull.Index)
|
||||
req = NewRequestWithJSON(t, http.MethodPatch, urlStr, &api.EditPullRequestOption{
|
||||
Base: "feature/1",
|
||||
Title: newTitle,
|
||||
Body: &newBody,
|
||||
|
@ -251,7 +252,17 @@ func TestAPIEditPull(t *testing.T) {
|
|||
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: pull.Issue.ID, OldTitle: title, NewTitle: newTitle})
|
||||
unittest.AssertExistsAndLoadBean(t, &issues_model.ContentHistory{IssueID: pull.Issue.ID, ContentText: newBody, IsFirstCreated: false})
|
||||
|
||||
req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d", owner10.Name, repo10.Name, pull.Index), &api.EditPullRequestOption{
|
||||
// verify the idempotency of a state change
|
||||
pullState := string(apiPull.State)
|
||||
req = NewRequestWithJSON(t, http.MethodPatch, urlStr, &api.EditPullRequestOption{
|
||||
State: &pullState,
|
||||
}).AddTokenAuth(token)
|
||||
apiPullIdempotent := new(api.PullRequest)
|
||||
resp = MakeRequest(t, req, http.StatusCreated)
|
||||
DecodeJSON(t, resp, apiPullIdempotent)
|
||||
assert.EqualValues(t, apiPull.State, apiPullIdempotent.State)
|
||||
|
||||
req = NewRequestWithJSON(t, http.MethodPatch, urlStr, &api.EditPullRequestOption{
|
||||
Base: "not-exist",
|
||||
}).AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue