Skip to content

Commit 36f2306

Browse files
committed
allow issue stopwatch to be toggled via an api call
1 parent acaf5c9 commit 36f2306

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

routers/api/v1/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ func RegisterRoutes(m *macaron.Macaron) {
557557
})
558558

559559
m.Combo("/deadline").Post(reqToken(), bind(api.EditDeadlineOption{}), repo.UpdateIssueDeadline)
560+
m.Post("/stopwatch/toggle", reqToken(), repo.ToggleIssueStopwatch)
560561
})
561562
}, mustEnableIssuesOrPulls)
562563
m.Group("/labels", func() {

routers/api/v1/repo/issue.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,65 @@ func UpdateIssueDeadline(ctx *context.APIContext, form api.EditDeadlineOption) {
439439

440440
ctx.JSON(201, api.IssueDeadline{Deadline: &deadline})
441441
}
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
446+
// ---
447+
// summary: Toggle stopwatch on an issue.
448+
// consumes:
449+
// - application/json
450+
// produces:
451+
// - application/json
452+
// parameters:
453+
// - name: owner
454+
// in: path
455+
// description: owner of the repo
456+
// type: string
457+
// required: true
458+
// - name: repo
459+
// in: path
460+
// description: name of the repo
461+
// type: string
462+
// required: true
463+
// - name: index
464+
// in: path
465+
// description: index of the issue to create or stop the stopwatch on
466+
// type: integer
467+
// format: int64
468+
// required: true
469+
// responses:
470+
// "201":
471+
// "$ref": "#/responses/empty"
472+
// "403":
473+
// description: Not repo writer or user does not have rights to toggle stopwatch
474+
// "404":
475+
// description: Issue not found
476+
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
477+
if err != nil {
478+
if models.IsErrIssueNotExist(err) {
479+
ctx.Status(404)
480+
} else {
481+
ctx.Error(500, "GetIssueByIndex", err)
482+
}
483+
484+
return
485+
}
486+
487+
if !ctx.Repo.CanWrite(models.UnitTypeIssues) {
488+
ctx.Status(403)
489+
return
490+
}
491+
492+
if !ctx.Repo.CanUseTimetracker(issue, ctx.User) {
493+
ctx.Status(403)
494+
return
495+
}
496+
497+
if err := models.CreateOrStopIssueStopwatch(ctx.User, issue); err != nil {
498+
ctx.ServerError("CreateOrStopIssueStopwatch", err)
499+
return
500+
}
501+
502+
ctx.Status(201)
503+
}

templates/swagger/v1_json.tmpl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,6 +2924,56 @@
29242924
}
29252925
}
29262926
},
2927+
"/repos/{owner}/{repo}/issues/{index}/stopwatch/toggle": {
2928+
"post": {
2929+
"consumes": [
2930+
"application/json"
2931+
],
2932+
"produces": [
2933+
"application/json"
2934+
],
2935+
"tags": [
2936+
"issue"
2937+
],
2938+
"summary": "Toggle stopwatch on an issue.",
2939+
"operationId": "issueToggleStopWatch",
2940+
"parameters": [
2941+
{
2942+
"type": "string",
2943+
"description": "owner of the repo",
2944+
"name": "owner",
2945+
"in": "path",
2946+
"required": true
2947+
},
2948+
{
2949+
"type": "string",
2950+
"description": "name of the repo",
2951+
"name": "repo",
2952+
"in": "path",
2953+
"required": true
2954+
},
2955+
{
2956+
"type": "integer",
2957+
"format": "int64",
2958+
"description": "index of the issue to create or stop the stopwatch on",
2959+
"name": "index",
2960+
"in": "path",
2961+
"required": true
2962+
}
2963+
],
2964+
"responses": {
2965+
"201": {
2966+
"$ref": "#/responses/empty"
2967+
},
2968+
"403": {
2969+
"description": "Not repo writer or user does not have rights to toggle stopwatch"
2970+
},
2971+
"404": {
2972+
"description": "Issue not found"
2973+
}
2974+
}
2975+
}
2976+
},
29272977
"/repos/{owner}/{repo}/keys": {
29282978
"get": {
29292979
"produces": [

0 commit comments

Comments
 (0)