@@ -14,11 +14,25 @@ import (
1414)
1515
1616// CloseIssue close an issue.
17- func CloseIssue (ctx context.Context , issue * issues_model.Issue , doer * user_model.User , commitID string ) error {
18- var comment * issues_model.Comment
17+ func CloseIssue (ctx context.Context , issue * issues_model.Issue , doer * user_model.User , commitID , commentContent string , attachments [] string ) ( * issues_model. Comment , error ) {
18+ var refComment , createdComment * issues_model.Comment
1919 if err := db .WithTx (ctx , func (ctx context.Context ) error {
2020 var err error
21- comment , err = issues_model .CloseIssue (ctx , issue , doer )
21+ if commentContent != "" || len (attachments ) > 0 {
22+ createdComment , err = issues_model .CreateComment (ctx , & issues_model.CreateCommentOptions {
23+ Type : issues_model .CommentTypeComment ,
24+ Doer : doer ,
25+ Repo : issue .Repo ,
26+ Issue : issue ,
27+ Content : commentContent ,
28+ Attachments : attachments ,
29+ })
30+ if err != nil {
31+ return err
32+ }
33+ }
34+
35+ refComment , err = issues_model .CloseIssue (ctx , issue , doer )
2236 if err != nil {
2337 if issues_model .IsErrDependenciesLeft (err ) {
2438 if _ , err := issues_model .FinishIssueStopwatch (ctx , doer , issue ); err != nil {
@@ -31,23 +45,53 @@ func CloseIssue(ctx context.Context, issue *issues_model.Issue, doer *user_model
3145 _ , err = issues_model .FinishIssueStopwatch (ctx , doer , issue )
3246 return err
3347 }); err != nil {
34- return err
48+ return nil , err
3549 }
3650
37- notify_service .IssueChangeStatus (ctx , doer , commitID , issue , comment , true )
51+ if createdComment != nil {
52+ if err := notifyCommentCreated (ctx , doer , issue .Repo , issue , createdComment ); err != nil {
53+ log .Error ("Unable to notify comment created for issue[%d]#%d: %v" , issue .ID , issue .Index , err )
54+ }
55+ }
3856
39- return nil
57+ notify_service .IssueChangeStatus (ctx , doer , commitID , issue , refComment , true )
58+
59+ return createdComment , nil
4060}
4161
42- // ReopenIssue reopen an issue.
62+ // ReopenIssue reopen an issue with or without a comment .
4363// FIXME: If some issues dependent this one are closed, should we also reopen them?
44- func ReopenIssue (ctx context.Context , issue * issues_model.Issue , doer * user_model.User , commitID string ) error {
45- comment , err := issues_model .ReopenIssue (ctx , issue , doer )
64+ func ReopenIssue (ctx context.Context , issue * issues_model.Issue , doer * user_model.User , commitID , commentContent string , attachments []string ) (* issues_model.Comment , error ) {
65+ var createdComment * issues_model.Comment
66+ refComment , err := db .WithTx2 (ctx , func (ctx context.Context ) (* issues_model.Comment , error ) {
67+ var err error
68+ if commentContent != "" || len (attachments ) > 0 {
69+ createdComment , err = issues_model .CreateComment (ctx , & issues_model.CreateCommentOptions {
70+ Type : issues_model .CommentTypeComment ,
71+ Doer : doer ,
72+ Repo : issue .Repo ,
73+ Issue : issue ,
74+ Content : commentContent ,
75+ Attachments : attachments ,
76+ })
77+ if err != nil {
78+ return nil , err
79+ }
80+ }
81+
82+ return issues_model .ReopenIssue (ctx , issue , doer )
83+ })
4684 if err != nil {
47- return err
85+ return nil , err
86+ }
87+
88+ if createdComment != nil {
89+ if err := notifyCommentCreated (ctx , doer , issue .Repo , issue , createdComment ); err != nil {
90+ log .Error ("Unable to notify comment created for issue[%d]#%d: %v" , issue .ID , issue .Index , err )
91+ }
4892 }
4993
50- notify_service .IssueChangeStatus (ctx , doer , commitID , issue , comment , false )
94+ notify_service .IssueChangeStatus (ctx , doer , commitID , issue , refComment , false )
5195
52- return nil
96+ return createdComment , nil
5397}
0 commit comments