diff --git a/modules/structs/issue_label.go b/modules/structs/issue_label.go index 16bd0b3c94..000215d71d 100644 --- a/modules/structs/issue_label.go +++ b/modules/structs/issue_label.go @@ -13,6 +13,8 @@ type Label struct { Name string `json:"name"` // example: false Exclusive bool `json:"exclusive"` + // example: 0 + ExclusiveOrder int `json:"exclusive_order"` // example: false IsArchived bool `json:"is_archived"` // example: 00aabb diff --git a/modules/structs/project_workflow.go b/modules/structs/project_workflow.go index b735ccdf84..fcfd8f92c0 100644 --- a/modules/structs/project_workflow.go +++ b/modules/structs/project_workflow.go @@ -40,22 +40,11 @@ type ProjectWorkflowColumnOption struct { Color string `json:"color"` } -// ProjectWorkflowLabelOption represents a selectable project label. -// swagger:model -type ProjectWorkflowLabelOption struct { - ID int64 `json:"id"` - Name string `json:"name"` - Color string `json:"color"` - Description string `json:"description"` - Exclusive bool `json:"exclusive"` - ExclusiveOrder int `json:"exclusive_order"` -} - // ProjectWorkflowOptions represents the project workflow configuration options. // swagger:model type ProjectWorkflowOptions struct { Columns []*ProjectWorkflowColumnOption `json:"columns"` - Labels []*ProjectWorkflowLabelOption `json:"labels"` + Labels []*Label `json:"labels"` } // ProjectWorkflowFilterOptions represents editable workflow filters. diff --git a/routers/api/v1/repo/project_workflow.go b/routers/api/v1/repo/project_workflow.go index 4d6c603556..57007d5e1f 100644 --- a/routers/api/v1/repo/project_workflow.go +++ b/routers/api/v1/repo/project_workflow.go @@ -334,13 +334,13 @@ func GetProjectWorkflowOptions(ctx *api_context.APIContext) { } options := &api.ProjectWorkflowOptions{ Columns: make([]*api.ProjectWorkflowColumnOption, 0, len(columns)), - Labels: make([]*api.ProjectWorkflowLabelOption, 0, len(labels)), + Labels: make([]*api.Label, 0, len(labels)), } for _, column := range columns { options.Columns = append(options.Columns, &api.ProjectWorkflowColumnOption{ID: column.ID, Title: column.Title, Color: column.Color}) } for _, label := range labels { - options.Labels = append(options.Labels, &api.ProjectWorkflowLabelOption{ + options.Labels = append(options.Labels, &api.Label{ ID: label.ID, Name: label.Name, Color: label.Color, diff --git a/routers/web/projects/workflows.go b/routers/web/projects/workflows.go index fc643fb36a..139d236e35 100644 --- a/routers/web/projects/workflows.go +++ b/routers/web/projects/workflows.go @@ -15,6 +15,7 @@ import ( project_model "code.gitea.io/gitea/models/project" "code.gitea.io/gitea/models/unit" "code.gitea.io/gitea/modules/json" + api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/services/context" project_service "code.gitea.io/gitea/services/projects" @@ -241,14 +242,9 @@ func renderWorkflowsOptions(ctx *context.Context, project *project_model.Project return } - type Column struct { - ID int64 `json:"id"` - Title string `json:"title"` - Color string `json:"color"` - } - outputColumns := make([]*Column, 0, len(columns)) + outputColumns := make([]*api.ProjectWorkflowColumnOption, 0, len(columns)) for _, col := range columns { - outputColumns = append(outputColumns, &Column{ + outputColumns = append(outputColumns, &api.ProjectWorkflowColumnOption{ ID: col.ID, Title: col.Title, Color: col.Color, @@ -261,17 +257,9 @@ func renderWorkflowsOptions(ctx *context.Context, project *project_model.Project return } - type Label struct { - ID int64 `json:"id"` - Name string `json:"name"` - Color string `json:"color"` - Description string `json:"description"` - Exclusive bool `json:"exclusive"` - ExclusiveOrder int `json:"exclusiveOrder"` - } - outputLabels := make([]*Label, 0, len(labels)) + outputLabels := make([]*api.Label, 0, len(labels)) for _, label := range labels { - outputLabels = append(outputLabels, &Label{ + outputLabels = append(outputLabels, &api.Label{ ID: label.ID, Name: label.Name, Color: label.Color, @@ -281,9 +269,9 @@ func renderWorkflowsOptions(ctx *context.Context, project *project_model.Project }) } - ctx.JSON(http.StatusOK, map[string]any{ - "columns": outputColumns, - "labels": outputLabels, + ctx.JSON(http.StatusOK, api.ProjectWorkflowOptions{ + Columns: outputColumns, + Labels: outputLabels, }) } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index b4428d3a78..666fb2051a 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -27558,6 +27558,12 @@ "x-go-name": "Exclusive", "example": false }, + "exclusive_order": { + "type": "integer", + "format": "int64", + "x-go-name": "ExclusiveOrder", + "example": 0 + }, "id": { "description": "ID is the unique identifier for the label", "type": "integer", @@ -28812,39 +28818,6 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "ProjectWorkflowLabelOption": { - "type": "object", - "title": "ProjectWorkflowLabelOption represents a selectable project label.", - "properties": { - "color": { - "type": "string", - "x-go-name": "Color" - }, - "description": { - "type": "string", - "x-go-name": "Description" - }, - "exclusive": { - "type": "boolean", - "x-go-name": "Exclusive" - }, - "exclusive_order": { - "type": "integer", - "format": "int64", - "x-go-name": "ExclusiveOrder" - }, - "id": { - "type": "integer", - "format": "int64", - "x-go-name": "ID" - }, - "name": { - "type": "string", - "x-go-name": "Name" - } - }, - "x-go-package": "code.gitea.io/gitea/modules/structs" - }, "ProjectWorkflowOptions": { "type": "object", "title": "ProjectWorkflowOptions represents the project workflow configuration options.", @@ -28859,7 +28832,7 @@ "labels": { "type": "array", "items": { - "$ref": "#/definitions/ProjectWorkflowLabelOption" + "$ref": "#/definitions/Label" }, "x-go-name": "Labels" } diff --git a/templates/swagger/v1_openapi3_json.tmpl b/templates/swagger/v1_openapi3_json.tmpl index bb7629cfe6..b3186951ec 100644 --- a/templates/swagger/v1_openapi3_json.tmpl +++ b/templates/swagger/v1_openapi3_json.tmpl @@ -7235,6 +7235,12 @@ "type": "boolean", "x-go-name": "Exclusive" }, + "exclusive_order": { + "example": 0, + "format": "int64", + "type": "integer", + "x-go-name": "ExclusiveOrder" + }, "id": { "description": "ID is the unique identifier for the label", "format": "int64", @@ -8507,39 +8513,6 @@ "type": "object", "x-go-package": "code.gitea.io/gitea/modules/structs" }, - "ProjectWorkflowLabelOption": { - "properties": { - "color": { - "type": "string", - "x-go-name": "Color" - }, - "description": { - "type": "string", - "x-go-name": "Description" - }, - "exclusive": { - "type": "boolean", - "x-go-name": "Exclusive" - }, - "exclusive_order": { - "format": "int64", - "type": "integer", - "x-go-name": "ExclusiveOrder" - }, - "id": { - "format": "int64", - "type": "integer", - "x-go-name": "ID" - }, - "name": { - "type": "string", - "x-go-name": "Name" - } - }, - "title": "ProjectWorkflowLabelOption represents a selectable project label.", - "type": "object", - "x-go-package": "code.gitea.io/gitea/modules/structs" - }, "ProjectWorkflowOptions": { "properties": { "columns": { @@ -8551,7 +8524,7 @@ }, "labels": { "items": { - "$ref": "#/components/schemas/ProjectWorkflowLabelOption" + "$ref": "#/components/schemas/Label" }, "type": "array", "x-go-name": "Labels" diff --git a/tests/integration/api_project_workflow_test.go b/tests/integration/api_project_workflow_test.go index 65d630b92b..3a31ffbf76 100644 --- a/tests/integration/api_project_workflow_test.go +++ b/tests/integration/api_project_workflow_test.go @@ -49,7 +49,7 @@ func TestAPIRepoProjectWorkflows(t *testing.T) { var options api.ProjectWorkflowOptions require.NoError(t, json.Unmarshal(resp.Body.Bytes(), &options)) assert.Contains(t, options.Columns, &api.ProjectWorkflowColumnOption{ID: column.ID, Title: column.Title, Color: column.Color}) - assert.Contains(t, options.Labels, &api.ProjectWorkflowLabelOption{ID: label.ID, Name: label.Name, Color: label.Color, Description: label.Description, Exclusive: label.Exclusive, ExclusiveOrder: label.ExclusiveOrder}) + assert.Contains(t, options.Labels, &api.Label{ID: label.ID, Name: label.Name, Color: label.Color, Description: label.Description, Exclusive: label.Exclusive, ExclusiveOrder: label.ExclusiveOrder}) }) var workflow api.ProjectWorkflow