@ -600,16 +600,23 @@ func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
return nil
return nil
}
}
func ( issue * Issue ) changeStatus ( e * xorm . Session , doer * User , isClosed bool ) ( err error ) {
func ( issue * Issue ) changeStatus ( e * xorm . Session , doer * User , isClosed bool ) ( * Comment , error ) {
// Reload the issue
// Reload the issue
currentIssue , err := getIssueByID ( e , issue . ID )
currentIssue , err := getIssueByID ( e , issue . ID )
if err != nil {
if err != nil {
return err
return nil , err
}
}
// Nothing should be performed if current status is same as target status
// Nothing should be performed if current status is same as target status
if currentIssue . IsClosed == isClosed {
if currentIssue . IsClosed == isClosed {
return nil
if ! issue . IsPull {
return nil , ErrIssueWasClosed {
ID : issue . ID ,
}
}
return nil , ErrPullWasClosed {
ID : issue . ID ,
}
}
}
// Check for open dependencies
// Check for open dependencies
@ -617,11 +624,11 @@ func (issue *Issue) changeStatus(e *xorm.Session, doer *User, isClosed bool) (er
// only check if dependencies are enabled and we're about to close an issue, otherwise reopening an issue would fail when there are unsatisfied dependencies
// only check if dependencies are enabled and we're about to close an issue, otherwise reopening an issue would fail when there are unsatisfied dependencies
noDeps , err := issueNoDependenciesLeft ( e , issue )
noDeps , err := issueNoDependenciesLeft ( e , issue )
if err != nil {
if err != nil {
return err
return nil , err
}
}
if ! noDeps {
if ! noDeps {
return ErrDependenciesLeft { issue . ID }
return nil , ErrDependenciesLeft { issue . ID }
}
}
}
}
@ -633,22 +640,22 @@ func (issue *Issue) changeStatus(e *xorm.Session, doer *User, isClosed bool) (er
}
}
if err = updateIssueCols ( e , issue , "is_closed" , "closed_unix" ) ; err != nil {
if err = updateIssueCols ( e , issue , "is_closed" , "closed_unix" ) ; err != nil {
return err
return nil , err
}
}
// Update issue count of labels
// Update issue count of labels
if err = issue . getLabels ( e ) ; err != nil {
if err = issue . getLabels ( e ) ; err != nil {
return err
return nil , err
}
}
for idx := range issue . Labels {
for idx := range issue . Labels {
if err = updateLabel ( e , issue . Labels [ idx ] ) ; err != nil {
if err = updateLabel ( e , issue . Labels [ idx ] ) ; err != nil {
return err
return nil , err
}
}
}
}
// Update issue count of milestone
// Update issue count of milestone
if err := updateMilestoneClosedNum ( e , issue . MilestoneID ) ; err != nil {
if err := updateMilestoneClosedNum ( e , issue . MilestoneID ) ; err != nil {
return err
return nil , err
}
}
// New action comment
// New action comment
@ -657,43 +664,39 @@ func (issue *Issue) changeStatus(e *xorm.Session, doer *User, isClosed bool) (er
cmtType = CommentTypeReopen
cmtType = CommentTypeReopen
}
}
var opts = & CreateCommentOptions {
return createCommentWithNoAction ( e , & CreateCommentOptions {
Type : cmtType ,
Type : cmtType ,
Doer : doer ,
Doer : doer ,
Repo : issue . Repo ,
Repo : issue . Repo ,
Issue : issue ,
Issue : issue ,
}
comment , err := createCommentWithNoAction ( e , opts )
if err != nil {
return err
}
return sendCreateCommentAction ( e , opts , comment )
} )
}
}
// ChangeStatus changes issue status to open or closed.
// ChangeStatus changes issue status to open or closed.
func ( issue * Issue ) ChangeStatus ( doer * User , isClosed bool ) ( err error ) {
func ( issue * Issue ) ChangeStatus ( doer * User , isClosed bool ) ( * Comment , error ) {
sess := x . NewSession ( )
sess := x . NewSession ( )
defer sess . Close ( )
defer sess . Close ( )
if err = sess . Begin ( ) ; err != nil {
return err
if err : = sess . Begin ( ) ; err != nil {
return nil , err
}
}
if err = issue . loadRepo ( sess ) ; err != nil {
return err
if err : = issue . loadRepo ( sess ) ; err != nil {
return nil , err
}
}
if err = issue . loadPoster ( sess ) ; err != nil {
return err
if err : = issue . loadPoster ( sess ) ; err != nil {
return nil , err
}
}
if err = issue . changeStatus ( sess , doer , isClosed ) ; err != nil {
return err
comment , err := issue . changeStatus ( sess , doer , isClosed )
if err != nil {
return nil , err
}
}
if err = sess . Commit ( ) ; err != nil {
if err = sess . Commit ( ) ; err != nil {
return fmt . Errorf ( "Commit: %v" , err )
return nil , fmt . Errorf ( "Commit: %v" , err )
}
}
return nil
return comment , nil
}
}
// ChangeTitle changes the title of this issue, as the given user.
// ChangeTitle changes the title of this issue, as the given user.