Fix wrong num closed issues on repository when close issue via commit (#10364)
Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
parent
5dc634dace
commit
efbd7ca39b
2 changed files with 19 additions and 7 deletions
|
@ -39,12 +39,12 @@ func TestAPICreateIssue(t *testing.T) {
|
||||||
defer prepareTestEnv(t)()
|
defer prepareTestEnv(t)()
|
||||||
const body, title = "apiTestBody", "apiTestTitle"
|
const body, title = "apiTestBody", "apiTestTitle"
|
||||||
|
|
||||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
repoBefore := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||||
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repoBefore.OwnerID}).(*models.User)
|
||||||
|
|
||||||
session := loginUser(t, owner.Name)
|
session := loginUser(t, owner.Name)
|
||||||
token := getTokenForLoggedInUser(t, session)
|
token := getTokenForLoggedInUser(t, session)
|
||||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues?state=all&token=%s", owner.Name, repo.Name, token)
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues?state=all&token=%s", owner.Name, repoBefore.Name, token)
|
||||||
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{
|
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{
|
||||||
Body: body,
|
Body: body,
|
||||||
Title: title,
|
Title: title,
|
||||||
|
@ -57,19 +57,23 @@ func TestAPICreateIssue(t *testing.T) {
|
||||||
assert.Equal(t, apiIssue.Title, title)
|
assert.Equal(t, apiIssue.Title, title)
|
||||||
|
|
||||||
models.AssertExistsAndLoadBean(t, &models.Issue{
|
models.AssertExistsAndLoadBean(t, &models.Issue{
|
||||||
RepoID: repo.ID,
|
RepoID: repoBefore.ID,
|
||||||
AssigneeID: owner.ID,
|
AssigneeID: owner.ID,
|
||||||
Content: body,
|
Content: body,
|
||||||
Title: title,
|
Title: title,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
repoAfter := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||||
|
assert.Equal(t, repoBefore.NumIssues+1, repoAfter.NumIssues)
|
||||||
|
assert.Equal(t, repoBefore.NumClosedIssues, repoAfter.NumClosedIssues)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIEditIssue(t *testing.T) {
|
func TestAPIEditIssue(t *testing.T) {
|
||||||
defer prepareTestEnv(t)()
|
defer prepareTestEnv(t)()
|
||||||
|
|
||||||
issueBefore := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 10}).(*models.Issue)
|
issueBefore := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 10}).(*models.Issue)
|
||||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issueBefore.RepoID}).(*models.Repository)
|
repoBefore := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issueBefore.RepoID}).(*models.Repository)
|
||||||
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repoBefore.OwnerID}).(*models.User)
|
||||||
assert.NoError(t, issueBefore.LoadAttributes())
|
assert.NoError(t, issueBefore.LoadAttributes())
|
||||||
assert.Equal(t, int64(1019307200), int64(issueBefore.DeadlineUnix))
|
assert.Equal(t, int64(1019307200), int64(issueBefore.DeadlineUnix))
|
||||||
assert.Equal(t, api.StateOpen, issueBefore.State())
|
assert.Equal(t, api.StateOpen, issueBefore.State())
|
||||||
|
@ -84,7 +88,7 @@ func TestAPIEditIssue(t *testing.T) {
|
||||||
body := "new content!"
|
body := "new content!"
|
||||||
title := "new title from api set"
|
title := "new title from api set"
|
||||||
|
|
||||||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d?token=%s", owner.Name, repo.Name, issueBefore.Index, token)
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d?token=%s", owner.Name, repoBefore.Name, issueBefore.Index, token)
|
||||||
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{
|
req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditIssueOption{
|
||||||
State: &issueState,
|
State: &issueState,
|
||||||
RemoveDeadline: &removeDeadline,
|
RemoveDeadline: &removeDeadline,
|
||||||
|
@ -99,6 +103,7 @@ func TestAPIEditIssue(t *testing.T) {
|
||||||
DecodeJSON(t, resp, &apiIssue)
|
DecodeJSON(t, resp, &apiIssue)
|
||||||
|
|
||||||
issueAfter := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 10}).(*models.Issue)
|
issueAfter := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 10}).(*models.Issue)
|
||||||
|
repoAfter := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issueBefore.RepoID}).(*models.Repository)
|
||||||
|
|
||||||
// check deleted user
|
// check deleted user
|
||||||
assert.Equal(t, int64(500), issueAfter.PosterID)
|
assert.Equal(t, int64(500), issueAfter.PosterID)
|
||||||
|
@ -107,6 +112,9 @@ func TestAPIEditIssue(t *testing.T) {
|
||||||
assert.Equal(t, int64(-1), issueBefore.PosterID)
|
assert.Equal(t, int64(-1), issueBefore.PosterID)
|
||||||
assert.Equal(t, int64(-1), apiIssue.Poster.ID)
|
assert.Equal(t, int64(-1), apiIssue.Poster.ID)
|
||||||
|
|
||||||
|
// check repo change
|
||||||
|
assert.Equal(t, repoBefore.NumClosedIssues+1, repoAfter.NumClosedIssues)
|
||||||
|
|
||||||
// API response
|
// API response
|
||||||
assert.Equal(t, api.StateClosed, apiIssue.State)
|
assert.Equal(t, api.StateClosed, apiIssue.State)
|
||||||
assert.Equal(t, milestone, apiIssue.Milestone.ID)
|
assert.Equal(t, milestone, apiIssue.Milestone.ID)
|
||||||
|
|
|
@ -676,6 +676,10 @@ func (issue *Issue) changeStatus(e *xorm.Session, doer *User, isClosed bool) (*C
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := issue.updateClosedNum(e); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// New action comment
|
// New action comment
|
||||||
cmtType := CommentTypeClose
|
cmtType := CommentTypeClose
|
||||||
if !issue.IsClosed {
|
if !issue.IsClosed {
|
||||||
|
|
Reference in a new issue