1
0
Fork 0

Add an updated_at field to the API calls related to Issue's Labels.

The update date is applied to the issue's comment created to inform
about the modification of the issue's labels.
This commit is contained in:
fluzz 2023-06-06 18:36:19 +02:00
parent f061caa655
commit ea36cf80f5
5 changed files with 74 additions and 2 deletions

View file

@ -4,6 +4,10 @@
package structs package structs
import (
"time"
)
// Label a label to an issue or a pr // Label a label to an issue or a pr
// swagger:model // swagger:model
type Label struct { type Label struct {
@ -45,10 +49,18 @@ type EditLabelOption struct {
IsArchived *bool `json:"is_archived"` IsArchived *bool `json:"is_archived"`
} }
// DeleteLabelOption options for deleting a label
type DeleteLabelsOption struct {
// swagger:strfmt date-time
Updated *time.Time `json:"updated_at"`
}
// IssueLabelsOption a collection of labels // IssueLabelsOption a collection of labels
type IssueLabelsOption struct { type IssueLabelsOption struct {
// list of label IDs // list of label IDs
Labels []int64 `json:"labels"` Labels []int64 `json:"labels"`
// swagger:strfmt date-time
Updated *time.Time `json:"updated_at"`
} }
// LabelTemplate info of a Label template // LabelTemplate info of a Label template

View file

@ -1201,8 +1201,8 @@ func Routes() *web.Route {
m.Combo("").Get(repo.ListIssueLabels). m.Combo("").Get(repo.ListIssueLabels).
Post(reqToken(), bind(api.IssueLabelsOption{}), repo.AddIssueLabels). Post(reqToken(), bind(api.IssueLabelsOption{}), repo.AddIssueLabels).
Put(reqToken(), bind(api.IssueLabelsOption{}), repo.ReplaceIssueLabels). Put(reqToken(), bind(api.IssueLabelsOption{}), repo.ReplaceIssueLabels).
Delete(reqToken(), repo.ClearIssueLabels) Delete(reqToken(), bind(api.DeleteLabelsOption{}), repo.ClearIssueLabels)
m.Delete("/{id}", reqToken(), repo.DeleteIssueLabel) m.Delete("/{id}", reqToken(), bind(api.DeleteLabelsOption{}), repo.DeleteIssueLabel)
}) })
m.Group("/times", func() { m.Group("/times", func() {
m.Combo(""). m.Combo("").

View file

@ -149,6 +149,10 @@ func DeleteIssueLabel(ctx *context.APIContext) {
// type: integer // type: integer
// format: int64 // format: int64
// required: true // required: true
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/DeleteLabelsOption"
// responses: // responses:
// "204": // "204":
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
@ -156,6 +160,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
// "422": // "422":
// "$ref": "#/responses/validationError" // "$ref": "#/responses/validationError"
form := web.GetForm(ctx).(*api.DeleteLabelsOption)
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
@ -172,6 +177,11 @@ func DeleteIssueLabel(ctx *context.APIContext) {
return return
} }
if err := issue_service.SetIssueUpdateDate(ctx, issue, form.Updated, ctx.Doer); err != nil {
ctx.Error(http.StatusForbidden, "SetIssueUpdateDate", err)
return
}
label, err := issues_model.GetLabelByID(ctx, ctx.ParamsInt64(":id")) label, err := issues_model.GetLabelByID(ctx, ctx.ParamsInt64(":id"))
if err != nil { if err != nil {
if issues_model.IsErrLabelNotExist(err) { if issues_model.IsErrLabelNotExist(err) {
@ -269,11 +279,16 @@ func ClearIssueLabels(ctx *context.APIContext) {
// type: integer // type: integer
// format: int64 // format: int64
// required: true // required: true
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/DeleteLabelsOption"
// responses: // responses:
// "204": // "204":
// "$ref": "#/responses/empty" // "$ref": "#/responses/empty"
// "403": // "403":
// "$ref": "#/responses/forbidden" // "$ref": "#/responses/forbidden"
form := web.GetForm(ctx).(*api.DeleteLabelsOption)
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil { if err != nil {
@ -290,6 +305,11 @@ func ClearIssueLabels(ctx *context.APIContext) {
return return
} }
if err := issue_service.SetIssueUpdateDate(ctx, issue, form.Updated, ctx.Doer); err != nil {
ctx.Error(http.StatusForbidden, "SetIssueUpdateDate", err)
return
}
if err := issue_service.ClearLabels(issue, ctx.Doer); err != nil { if err := issue_service.ClearLabels(issue, ctx.Doer); err != nil {
ctx.Error(http.StatusInternalServerError, "ClearLabels", err) ctx.Error(http.StatusInternalServerError, "ClearLabels", err)
return return
@ -320,5 +340,11 @@ func prepareForReplaceOrAdd(ctx *context.APIContext, form api.IssueLabelsOption)
return nil, nil, nil return nil, nil, nil
} }
err = issue_service.SetIssueUpdateDate(ctx, issue, form.Updated, ctx.Doer)
if err != nil {
ctx.Error(http.StatusForbidden, "SetIssueUpdateDate", err)
return nil, nil, err
}
return issue, labels, err return issue, labels, err
} }

View file

@ -47,6 +47,9 @@ type swaggerParameterBodies struct {
// in:body // in:body
IssueLabelsOption api.IssueLabelsOption IssueLabelsOption api.IssueLabelsOption
// in:body
DeleteLabelsOption api.DeleteLabelsOption
// in:body // in:body
CreateKeyOption api.CreateKeyOption CreateKeyOption api.CreateKeyOption

View file

@ -7651,6 +7651,13 @@
"name": "index", "name": "index",
"in": "path", "in": "path",
"required": true "required": true
},
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/DeleteLabelsOption"
}
} }
], ],
"responses": { "responses": {
@ -7703,6 +7710,13 @@
"name": "id", "name": "id",
"in": "path", "in": "path",
"required": true "required": true
},
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/DeleteLabelsOption"
}
} }
], ],
"responses": { "responses": {
@ -17784,6 +17798,18 @@
}, },
"x-go-package": "code.gitea.io/gitea/modules/structs" "x-go-package": "code.gitea.io/gitea/modules/structs"
}, },
"DeleteLabelsOption": {
"description": "DeleteLabelOption options for deleting a label",
"type": "object",
"properties": {
"updated_at": {
"type": "string",
"format": "date-time",
"x-go-name": "Updated"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"DeployKey": { "DeployKey": {
"description": "DeployKey a deploy key", "description": "DeployKey a deploy key",
"type": "object", "type": "object",
@ -19505,6 +19531,11 @@
"format": "int64" "format": "int64"
}, },
"x-go-name": "Labels" "x-go-name": "Labels"
},
"updated_at": {
"type": "string",
"format": "date-time",
"x-go-name": "Updated"
} }
}, },
"x-go-package": "code.gitea.io/gitea/modules/structs" "x-go-package": "code.gitea.io/gitea/modules/structs"