@@ -440,11 +440,11 @@ func UpdateIssueDeadline(ctx *context.APIContext, form api.EditDeadlineOption) {
440
440
ctx .JSON (201 , api.IssueDeadline {Deadline : & deadline })
441
441
}
442
442
443
- // ToggleIssueStopwatch creates or stops a stopwatch for the given issue.
444
- func ToggleIssueStopwatch (ctx * context.APIContext ) {
445
- // swagger:operation POST /repos/{owner}/{repo}/issues/{index}/stopwatch/toggle issue issueToggleStopWatch
443
+ // StartIssueStopwatch creates or stops a stopwatch for the given issue.
444
+ func StartIssueStopwatch (ctx * context.APIContext ) {
445
+ // swagger:operation POST /repos/{owner}/{repo}/issues/{index}/stopwatch/start issue issueStartStopWatch
446
446
// ---
447
- // summary: Toggle stopwatch on an issue.
447
+ // summary: Start stopwatch on an issue.
448
448
// consumes:
449
449
// - application/json
450
450
// produces:
@@ -470,7 +470,7 @@ func ToggleIssueStopwatch(ctx *context.APIContext) {
470
470
// "201":
471
471
// "$ref": "#/responses/empty"
472
472
// "403":
473
- // description: Not repo writer or user does not have rights to toggle stopwatch
473
+ // description: Not repo writer, user does not have rights to toggle stopwatch or trying to start a stopwatch again if it already exists
474
474
// "404":
475
475
// description: Issue not found
476
476
issue , err := models .GetIssueByIndex (ctx .Repo .Repository .ID , ctx .ParamsInt64 (":index" ))
@@ -494,8 +494,80 @@ func ToggleIssueStopwatch(ctx *context.APIContext) {
494
494
return
495
495
}
496
496
497
+ if models .StopwatchExists (ctx .User .ID , issue .ID ) {
498
+ ctx .Error (403 , "StopwatchExists" , "a stopwatch has already been started for this issue" )
499
+ return
500
+ }
501
+
502
+ if err := models .CreateOrStopIssueStopwatch (ctx .User , issue ); err != nil {
503
+ ctx .Error (500 , "CreateOrStopIssueStopwatch" , err )
504
+ return
505
+ }
506
+
507
+ ctx .Status (201 )
508
+ }
509
+
510
+ // StopIssueStopwatch creates or stops a stopwatch for the given issue.
511
+ func StopIssueStopwatch (ctx * context.APIContext ) {
512
+ // swagger:operation POST /repos/{owner}/{repo}/issues/{index}/stopwatch/stop issue issueStopWatch
513
+ // ---
514
+ // summary: Stop an issue's existing stopwatch.
515
+ // consumes:
516
+ // - application/json
517
+ // produces:
518
+ // - application/json
519
+ // parameters:
520
+ // - name: owner
521
+ // in: path
522
+ // description: owner of the repo
523
+ // type: string
524
+ // required: true
525
+ // - name: repo
526
+ // in: path
527
+ // description: name of the repo
528
+ // type: string
529
+ // required: true
530
+ // - name: index
531
+ // in: path
532
+ // description: index of the issue to create or stop the stopwatch on
533
+ // type: integer
534
+ // format: int64
535
+ // required: true
536
+ // responses:
537
+ // "201":
538
+ // "$ref": "#/responses/empty"
539
+ // "403":
540
+ // description: Not repo writer, user does not have rights to toggle stopwatch or trying to stop a non existent stopwatch
541
+ // "404":
542
+ // description: Issue not found
543
+ issue , err := models .GetIssueByIndex (ctx .Repo .Repository .ID , ctx .ParamsInt64 (":index" ))
544
+ if err != nil {
545
+ if models .IsErrIssueNotExist (err ) {
546
+ ctx .Status (404 )
547
+ } else {
548
+ ctx .Error (500 , "GetIssueByIndex" , err )
549
+ }
550
+
551
+ return
552
+ }
553
+
554
+ if ! ctx .Repo .CanWrite (models .UnitTypeIssues ) {
555
+ ctx .Status (403 )
556
+ return
557
+ }
558
+
559
+ if ! ctx .Repo .CanUseTimetracker (issue , ctx .User ) {
560
+ ctx .Status (403 )
561
+ return
562
+ }
563
+
564
+ if ! models .StopwatchExists (ctx .User .ID , issue .ID ) {
565
+ ctx .Error (403 , "StopwatchExists" , "cannot stop a non existent stopwatch" )
566
+ return
567
+ }
568
+
497
569
if err := models .CreateOrStopIssueStopwatch (ctx .User , issue ); err != nil {
498
- ctx .ServerError ( "CreateOrStopIssueStopwatch" , err )
570
+ ctx .Error ( 500 , "CreateOrStopIssueStopwatch" , err )
499
571
return
500
572
}
501
573
0 commit comments