@@ -188,33 +188,45 @@ func CreateIssue(ctx *middleware.Context, params martini.Params) {
188
188
}
189
189
190
190
func CreateIssuePost (ctx * middleware.Context , params martini.Params , form auth.CreateIssueForm ) {
191
- ctx .Data ["Title" ] = "Create issue"
192
- ctx .Data ["IsRepoToolbarIssues" ] = true
193
- ctx .Data ["IsRepoToolbarIssuesList" ] = false
194
- ctx .Data ["AttachmentsEnabled" ] = setting .AttachmentEnabled
191
+ send := func (status int , data interface {}, err error ) {
192
+ log .Error ("issue.Comment(?): %s" , err )
193
+
194
+ if err != nil {
195
+ ctx .JSON (status , map [string ]interface {}{
196
+ "ok" : false ,
197
+ "status" : status ,
198
+ "error" : err .Error (),
199
+ })
200
+ } else {
201
+ ctx .JSON (status , map [string ]interface {}{
202
+ "ok" : true ,
203
+ "status" : status ,
204
+ "data" : data ,
205
+ })
206
+ }
207
+ }
195
208
196
209
var err error
197
210
// Get all milestones.
198
- ctx . Data [ "OpenMilestones" ] , err = models .GetMilestones (ctx .Repo .Repository .Id , false )
211
+ _ , err = models .GetMilestones (ctx .Repo .Repository .Id , false )
199
212
if err != nil {
200
- ctx . Handle (500 , "issue.ViewIssue(GetMilestones.1): %v" , err )
213
+ send (500 , nil , err )
201
214
return
202
215
}
203
- ctx . Data [ "ClosedMilestones" ] , err = models .GetMilestones (ctx .Repo .Repository .Id , true )
216
+ _ , err = models .GetMilestones (ctx .Repo .Repository .Id , true )
204
217
if err != nil {
205
- ctx . Handle (500 , "issue.ViewIssue(GetMilestones.2): %v" , err )
218
+ send (500 , nil , err )
206
219
return
207
220
}
208
221
209
- us , err : = models .GetCollaborators (strings .TrimPrefix (ctx .Repo .RepoLink , "/" ))
222
+ _ , err = models .GetCollaborators (strings .TrimPrefix (ctx .Repo .RepoLink , "/" ))
210
223
if err != nil {
211
- ctx . Handle (500 , "issue.CreateIssue(GetCollaborators)" , err )
224
+ send (500 , nil , err )
212
225
return
213
226
}
214
- ctx .Data ["Collaborators" ] = us
215
227
216
228
if ctx .HasError () {
217
- ctx . HTML ( 200 , ISSUE_CREATE )
229
+ send ( 400 , nil , errors . New ( ctx . Flash . ErrorMsg ) )
218
230
return
219
231
}
220
232
@@ -233,11 +245,11 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C
233
245
Content : form .Content ,
234
246
}
235
247
if err := models .NewIssue (issue ); err != nil {
236
- ctx . Handle (500 , "issue.CreateIssue(NewIssue)" , err )
248
+ send (500 , nil , err )
237
249
return
238
250
} else if err := models .NewIssueUserPairs (issue .RepoId , issue .Id , ctx .Repo .Owner .Id ,
239
251
ctx .User .Id , form .AssigneeId , ctx .Repo .Repository .Name ); err != nil {
240
- ctx . Handle (500 , "issue.CreateIssue(NewIssueUserPairs)" , err )
252
+ send (500 , nil , err )
241
253
return
242
254
}
243
255
@@ -253,7 +265,7 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C
253
265
}
254
266
255
267
if err := models .UpdateMentions (ms , issue .Id ); err != nil {
256
- ctx . Handle (500 , "issue.CreateIssue(UpdateMentions)" , err )
268
+ send (500 , nil , err )
257
269
return
258
270
}
259
271
}
@@ -272,15 +284,15 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C
272
284
}
273
285
// Notify watchers.
274
286
if err := models .NotifyWatchers (act ); err != nil {
275
- ctx . Handle (500 , "issue.CreateIssue(NotifyWatchers)" , err )
287
+ send (500 , nil , err )
276
288
return
277
289
}
278
290
279
291
// Mail watchers and mentions.
280
292
if setting .Service .EnableNotifyMail {
281
293
tos , err := mailer .SendIssueNotifyMail (ctx .User , ctx .Repo .Owner , ctx .Repo .Repository , issue )
282
294
if err != nil {
283
- ctx . Handle (500 , "issue.CreateIssue(SendIssueNotifyMail)" , err )
295
+ send (500 , nil , err )
284
296
return
285
297
}
286
298
@@ -295,13 +307,13 @@ func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.C
295
307
}
296
308
if err = mailer .SendIssueMentionMail (ctx .Render , ctx .User , ctx .Repo .Owner ,
297
309
ctx .Repo .Repository , issue , models .GetUserEmailsByNames (newTos )); err != nil {
298
- ctx . Handle (500 , "issue.CreateIssue(SendIssueMentionMail)" , err )
310
+ send (500 , nil , err )
299
311
return
300
312
}
301
313
}
302
314
log .Trace ("%d Issue created: %d" , ctx .Repo .Repository .Id , issue .Id )
303
315
304
- ctx . Redirect ( fmt .Sprintf ("/%s/%s/issues/%d" , params ["username" ], params ["reponame" ], issue .Index ))
316
+ send ( 200 , fmt .Sprintf ("/%s/%s/issues/%d" , params ["username" ], params ["reponame" ], issue .Index ), nil )
305
317
}
306
318
307
319
func checkLabels (labels , allLabels []* models.Label ) {
@@ -698,19 +710,38 @@ func uploadFiles(ctx *middleware.Context, issueId, commentId int64) {
698
710
}
699
711
700
712
func Comment (ctx * middleware.Context , params martini.Params ) {
713
+ send := func (status int , data interface {}, err error ) {
714
+ log .Error ("issue.Comment(?): %s" , err )
715
+
716
+ if err != nil {
717
+ ctx .JSON (status , map [string ]interface {}{
718
+ "ok" : false ,
719
+ "status" : status ,
720
+ "error" : err .Error (),
721
+ })
722
+ } else {
723
+ ctx .JSON (status , map [string ]interface {}{
724
+ "ok" : true ,
725
+ "status" : status ,
726
+ "data" : data ,
727
+ })
728
+ }
729
+ }
730
+
701
731
index , err := base .StrTo (ctx .Query ("issueIndex" )).Int64 ()
702
732
if err != nil {
703
- ctx . Handle (404 , "issue.Comment(get index)" , err )
733
+ send (404 , nil , err )
704
734
return
705
735
}
706
736
707
737
issue , err := models .GetIssueByIndex (ctx .Repo .Repository .Id , index )
708
738
if err != nil {
709
739
if err == models .ErrIssueNotExist {
710
- ctx . Handle (404 , "issue.Comment" , err )
740
+ send (404 , nil , err )
711
741
} else {
712
- ctx . Handle (200 , "issue.Comment(get issue)" , err )
742
+ send (200 , nil , err )
713
743
}
744
+
714
745
return
715
746
}
716
747
@@ -724,17 +755,17 @@ func Comment(ctx *middleware.Context, params martini.Params) {
724
755
(strings .Contains (newStatus , "Close" ) && ! issue .IsClosed ) {
725
756
issue .IsClosed = ! issue .IsClosed
726
757
if err = models .UpdateIssue (issue ); err != nil {
727
- ctx . Handle (500 , "issue.Comment(UpdateIssue)" , err )
758
+ send (500 , nil , err )
728
759
return
729
760
} else if err = models .UpdateIssueUserPairsByStatus (issue .Id , issue .IsClosed ); err != nil {
730
- ctx . Handle (500 , "issue.Comment(UpdateIssueUserPairsByStatus)" , err )
761
+ send (500 , nil , err )
731
762
return
732
763
}
733
764
734
765
// Change open/closed issue counter for the associated milestone
735
766
if issue .MilestoneId > 0 {
736
767
if err = models .ChangeMilestoneIssueStats (issue ); err != nil {
737
- ctx . Handle (500 , "issue.Comment(ChangeMilestoneIssueStats)" , err )
768
+ send (500 , nil , err )
738
769
}
739
770
}
740
771
@@ -744,7 +775,7 @@ func Comment(ctx *middleware.Context, params martini.Params) {
744
775
}
745
776
746
777
if _ , err = models .CreateComment (ctx .User .Id , ctx .Repo .Repository .Id , issue .Id , 0 , 0 , cmtType , "" , nil ); err != nil {
747
- ctx . Handle (200 , "issue.Comment(create status change comment)" , err )
778
+ send (200 , nil , err )
748
779
return
749
780
}
750
781
log .Trace ("%s Issue(%d) status changed: %v" , ctx .Req .RequestURI , issue .Id , ! issue .IsClosed )
@@ -760,7 +791,7 @@ func Comment(ctx *middleware.Context, params martini.Params) {
760
791
switch params ["action" ] {
761
792
case "new" :
762
793
if comment , err = models .CreateComment (ctx .User .Id , ctx .Repo .Repository .Id , issue .Id , 0 , 0 , models .COMMENT , content , nil ); err != nil {
763
- ctx . Handle (500 , "issue.Comment(create comment)" , err )
794
+ send (500 , nil , err )
764
795
return
765
796
}
766
797
@@ -772,7 +803,7 @@ func Comment(ctx *middleware.Context, params martini.Params) {
772
803
}
773
804
774
805
if err := models .UpdateMentions (ms , issue .Id ); err != nil {
775
- ctx . Handle (500 , "issue.CreateIssue(UpdateMentions)" , err )
806
+ send (500 , nil , err )
776
807
return
777
808
}
778
809
}
@@ -800,7 +831,7 @@ func Comment(ctx *middleware.Context, params martini.Params) {
800
831
RepoName : ctx .Repo .Repository .LowerName ,
801
832
}
802
833
if err = models .NotifyWatchers (act ); err != nil {
803
- ctx . Handle (500 , "issue.CreateIssue(NotifyWatchers)" , err )
834
+ send (500 , nil , err )
804
835
return
805
836
}
806
837
@@ -809,7 +840,7 @@ func Comment(ctx *middleware.Context, params martini.Params) {
809
840
issue .Content = content
810
841
tos , err := mailer .SendIssueNotifyMail (ctx .User , ctx .Repo .Owner , ctx .Repo .Repository , issue )
811
842
if err != nil {
812
- ctx . Handle (500 , "issue.Comment(SendIssueNotifyMail)" , err )
843
+ send (500 , nil , err )
813
844
return
814
845
}
815
846
@@ -824,12 +855,13 @@ func Comment(ctx *middleware.Context, params martini.Params) {
824
855
}
825
856
if err = mailer .SendIssueMentionMail (ctx .Render , ctx .User , ctx .Repo .Owner ,
826
857
ctx .Repo .Repository , issue , models .GetUserEmailsByNames (newTos )); err != nil {
827
- ctx . Handle (500 , "issue.Comment(SendIssueMentionMail)" , err )
858
+ send (500 , nil , err )
828
859
return
829
860
}
830
861
}
831
862
832
- ctx .Redirect (fmt .Sprintf ("%s/issues/%d" , ctx .Repo .RepoLink , index ))
863
+ log .Error ("url: %#v" , fmt .Sprintf ("%s/issues/%d" , ctx .Repo .RepoLink , index ))
864
+ send (200 , fmt .Sprintf ("%s/issues/%d" , ctx .Repo .RepoLink , index ), nil )
833
865
}
834
866
835
867
func NewLabel (ctx * middleware.Context , form auth.CreateLabelForm ) {
0 commit comments