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
import (
"time"
)
// Label a label to an issue or a pr
// swagger:model
type Label struct {
@ -45,10 +49,18 @@ type EditLabelOption struct {
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
type IssueLabelsOption struct {
// list of label IDs
Labels []int64 `json:"labels"`
// swagger:strfmt date-time
Updated *time.Time `json:"updated_at"`
}
// LabelTemplate info of a Label template

View file

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

View file

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

View file

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

View file

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