improvement

This commit is contained in:
Lunny Xiao
2026-04-04 16:37:41 -07:00
committed by beardev-in
parent 3557c100c2
commit d06fdf6454
3 changed files with 362 additions and 287 deletions

View File

@@ -1584,14 +1584,14 @@ func Routes() *web.Router {
Delete(reqToken(), reqRepoWriter(unit.TypeProjects), mustNotBeArchived, repo.DeleteProject) Delete(reqToken(), reqRepoWriter(unit.TypeProjects), mustNotBeArchived, repo.DeleteProject)
m.Combo("/columns").Get(repo.ListProjectColumns). m.Combo("/columns").Get(repo.ListProjectColumns).
Post(reqToken(), reqRepoWriter(unit.TypeProjects), mustNotBeArchived, bind(api.CreateProjectColumnOption{}), repo.CreateProjectColumn) Post(reqToken(), reqRepoWriter(unit.TypeProjects), mustNotBeArchived, bind(api.CreateProjectColumnOption{}), repo.CreateProjectColumn)
}) m.Group("/columns/{column_id}", func() {
m.Group("/columns/{id}", func() { m.Combo("").
m.Combo(""). Patch(reqToken(), reqRepoWriter(unit.TypeProjects), mustNotBeArchived, bind(api.EditProjectColumnOption{}), repo.EditProjectColumn).
Patch(reqToken(), reqRepoWriter(unit.TypeProjects), mustNotBeArchived, bind(api.EditProjectColumnOption{}), repo.EditProjectColumn). Delete(reqToken(), reqRepoWriter(unit.TypeProjects), mustNotBeArchived, repo.DeleteProjectColumn)
Delete(reqToken(), reqRepoWriter(unit.TypeProjects), mustNotBeArchived, repo.DeleteProjectColumn) m.Get("/issues", repo.ListProjectColumnIssues)
m.Get("/issues", repo.ListProjectColumnIssues) m.Post("/issues/{issue_id}", reqToken(), reqRepoWriter(unit.TypeProjects), mustNotBeArchived, repo.AddIssueToProjectColumn)
m.Post("/issues/{issue_id}", reqToken(), reqRepoWriter(unit.TypeProjects), mustNotBeArchived, repo.AddIssueToProjectColumn) m.Delete("/issues/{issue_id}", reqToken(), reqRepoWriter(unit.TypeProjects), mustNotBeArchived, repo.RemoveIssueFromProjectColumn)
m.Delete("/issues/{issue_id}", reqToken(), reqRepoWriter(unit.TypeProjects), mustNotBeArchived, repo.RemoveIssueFromProjectColumn) })
}) })
}, reqRepoReader(unit.TypeProjects)) }, reqRepoReader(unit.TypeProjects))
}, repoAssignment(), checkTokenPublicOnly()) }, repoAssignment(), checkTokenPublicOnly())

View File

@@ -33,7 +33,7 @@ func getRepoProjectByID(ctx *context.APIContext) *project_model.Project {
} }
func getRepoProjectColumn(ctx *context.APIContext) *project_model.Column { func getRepoProjectColumn(ctx *context.APIContext) *project_model.Column {
column, err := project_model.GetColumn(ctx, ctx.PathParamInt64("id")) column, err := project_model.GetColumn(ctx, ctx.PathParamInt64("column_id"))
if err != nil { if err != nil {
if project_model.IsErrProjectColumnNotExist(err) { if project_model.IsErrProjectColumnNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
@@ -42,7 +42,7 @@ func getRepoProjectColumn(ctx *context.APIContext) *project_model.Column {
} }
return nil return nil
} }
_, err = project_model.GetProjectForRepoByID(ctx, ctx.Repo.Repository.ID, column.ProjectID) p, err := project_model.GetProjectForRepoByID(ctx, ctx.Repo.Repository.ID, column.ProjectID)
if err != nil { if err != nil {
if project_model.IsErrProjectNotExist(err) { if project_model.IsErrProjectNotExist(err) {
ctx.APIErrorNotFound() ctx.APIErrorNotFound()
@@ -51,6 +51,11 @@ func getRepoProjectColumn(ctx *context.APIContext) *project_model.Column {
} }
return nil return nil
} }
if p.ID != ctx.PathParamInt64("id") {
ctx.APIErrorNotFound()
return nil
}
return column return column
} }
@@ -466,7 +471,7 @@ func CreateProjectColumn(ctx *context.APIContext) {
// EditProjectColumn updates a column // EditProjectColumn updates a column
func EditProjectColumn(ctx *context.APIContext) { func EditProjectColumn(ctx *context.APIContext) {
// swagger:operation PATCH /repos/{owner}/{repo}/projects/columns/{id} repository repoEditProjectColumn // swagger:operation PATCH /repos/{owner}/{repo}/projects/{id}/columns/{column_id} repository repoEditProjectColumn
// --- // ---
// summary: Edit a project column // summary: Edit a project column
// consumes: // consumes:
@@ -486,6 +491,12 @@ func EditProjectColumn(ctx *context.APIContext) {
// required: true // required: true
// - name: id // - name: id
// in: path // in: path
// description: id of the project
// type: integer
// format: int64
// required: true
// - name: column_id
// in: path
// description: id of the column // description: id of the column
// type: integer // type: integer
// format: int64 // format: int64
@@ -534,7 +545,7 @@ func EditProjectColumn(ctx *context.APIContext) {
// DeleteProjectColumn deletes a column // DeleteProjectColumn deletes a column
func DeleteProjectColumn(ctx *context.APIContext) { func DeleteProjectColumn(ctx *context.APIContext) {
// swagger:operation DELETE /repos/{owner}/{repo}/projects/columns/{id} repository repoDeleteProjectColumn // swagger:operation DELETE /repos/{owner}/{repo}/projects/{id}/columns/{column_id} repository repoDeleteProjectColumn
// --- // ---
// summary: Delete a project column // summary: Delete a project column
// parameters: // parameters:
@@ -550,6 +561,12 @@ func DeleteProjectColumn(ctx *context.APIContext) {
// required: true // required: true
// - name: id // - name: id
// in: path // in: path
// description: id of the project
// type: integer
// format: int64
// required: true
// - name: column_id
// in: path
// description: id of the column // description: id of the column
// type: integer // type: integer
// format: int64 // format: int64
@@ -575,7 +592,7 @@ func DeleteProjectColumn(ctx *context.APIContext) {
// ListProjectColumnIssues lists all issues in a project column // ListProjectColumnIssues lists all issues in a project column
func ListProjectColumnIssues(ctx *context.APIContext) { func ListProjectColumnIssues(ctx *context.APIContext) {
// swagger:operation GET /repos/{owner}/{repo}/projects/columns/{id}/issues repository repoListProjectColumnIssues // swagger:operation GET /repos/{owner}/{repo}/projects/{id}/columns/{column_id}/issues repository repoListProjectColumnIssues
// --- // ---
// summary: List issues in a project column // summary: List issues in a project column
// produces: // produces:
@@ -593,6 +610,12 @@ func ListProjectColumnIssues(ctx *context.APIContext) {
// required: true // required: true
// - name: id // - name: id
// in: path // in: path
// description: id of the project
// type: integer
// format: int64
// required: true
// - name: column_id
// in: path
// description: id of the column // description: id of the column
// type: integer // type: integer
// format: int64 // format: int64
@@ -644,7 +667,7 @@ func ListProjectColumnIssues(ctx *context.APIContext) {
// AddIssueToProjectColumn adds an issue to a project column // AddIssueToProjectColumn adds an issue to a project column
func AddIssueToProjectColumn(ctx *context.APIContext) { func AddIssueToProjectColumn(ctx *context.APIContext) {
// swagger:operation POST /repos/{owner}/{repo}/projects/columns/{id}/issues/{issue_id} repository repoAddIssueToProjectColumn // swagger:operation POST /repos/{owner}/{repo}/projects/{id}/columns/{column_id}/issues/{issue_id} repository repoAddIssueToProjectColumn
// --- // ---
// summary: Add an issue to a project column // summary: Add an issue to a project column
// consumes: // consumes:
@@ -664,6 +687,12 @@ func AddIssueToProjectColumn(ctx *context.APIContext) {
// required: true // required: true
// - name: id // - name: id
// in: path // in: path
// description: id of the project
// type: integer
// format: int64
// required: true
// - name: column_id
// in: path
// description: id of the column // description: id of the column
// type: integer // type: integer
// format: int64 // format: int64
@@ -714,7 +743,7 @@ func AddIssueToProjectColumn(ctx *context.APIContext) {
// RemoveIssueFromProjectColumn remove an issue from a project column // RemoveIssueFromProjectColumn remove an issue from a project column
func RemoveIssueFromProjectColumn(ctx *context.APIContext) { func RemoveIssueFromProjectColumn(ctx *context.APIContext) {
// swagger:operation DELETE /repos/{owner}/{repo}/projects/columns/{id}/issues/{issue_id} repository repoRemoveIssueFromProjectColumn // swagger:operation DELETE /repos/{owner}/{repo}/projects/{id}/columns/{column_id}/issues/{issue_id} repository repoRemoveIssueFromProjectColumn
// --- // ---
// summary: Remove an issue from a project column // summary: Remove an issue from a project column
// consumes: // consumes:
@@ -734,6 +763,12 @@ func RemoveIssueFromProjectColumn(ctx *context.APIContext) {
// required: true // required: true
// - name: id // - name: id
// in: path // in: path
// description: id of the project
// type: integer
// format: int64
// required: true
// - name: column_id
// in: path
// description: id of the column // description: id of the column
// type: integer // type: integer
// format: int64 // format: int64

View File

@@ -13632,278 +13632,6 @@
} }
} }
}, },
"/repos/{owner}/{repo}/projects/columns/{id}": {
"delete": {
"tags": [
"repository"
],
"summary": "Delete a project column",
"operationId": "repoDeleteProjectColumn",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the column",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"$ref": "#/responses/empty"
},
"404": {
"$ref": "#/responses/notFound"
}
}
},
"patch": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Edit a project column",
"operationId": "repoEditProjectColumn",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the column",
"name": "id",
"in": "path",
"required": true
},
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/EditProjectColumnOption"
}
}
],
"responses": {
"200": {
"$ref": "#/responses/ProjectColumn"
},
"404": {
"$ref": "#/responses/notFound"
},
"422": {
"$ref": "#/responses/validationError"
}
}
}
},
"/repos/{owner}/{repo}/projects/columns/{id}/issues": {
"get": {
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "List issues in a project column",
"operationId": "repoListProjectColumnIssues",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the column",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "page number of results to return (1-based)",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "page size of results",
"name": "limit",
"in": "query"
}
],
"responses": {
"200": {
"$ref": "#/responses/IssueList"
},
"404": {
"$ref": "#/responses/notFound"
}
}
}
},
"/repos/{owner}/{repo}/projects/columns/{id}/issues/{issue_id}": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Add an issue to a project column",
"operationId": "repoAddIssueToProjectColumn",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the column",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the issue",
"name": "issue_id",
"in": "path",
"required": true
}
],
"responses": {
"201": {
"$ref": "#/responses/empty"
},
"403": {
"$ref": "#/responses/forbidden"
},
"404": {
"$ref": "#/responses/notFound"
},
"422": {
"$ref": "#/responses/validationError"
}
}
},
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Remove an issue from a project column",
"operationId": "repoRemoveIssueFromProjectColumn",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the column",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the issue",
"name": "issue_id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"$ref": "#/responses/empty"
},
"403": {
"$ref": "#/responses/forbidden"
},
"404": {
"$ref": "#/responses/notFound"
},
"422": {
"$ref": "#/responses/validationError"
}
}
}
},
"/repos/{owner}/{repo}/projects/{id}": { "/repos/{owner}/{repo}/projects/{id}": {
"get": { "get": {
"produces": [ "produces": [
@@ -14153,6 +13881,318 @@
} }
} }
}, },
"/repos/{owner}/{repo}/projects/{id}/columns/{column_id}": {
"delete": {
"tags": [
"repository"
],
"summary": "Delete a project column",
"operationId": "repoDeleteProjectColumn",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the project",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the column",
"name": "column_id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"$ref": "#/responses/empty"
},
"404": {
"$ref": "#/responses/notFound"
}
}
},
"patch": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Edit a project column",
"operationId": "repoEditProjectColumn",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the project",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the column",
"name": "column_id",
"in": "path",
"required": true
},
{
"name": "body",
"in": "body",
"schema": {
"$ref": "#/definitions/EditProjectColumnOption"
}
}
],
"responses": {
"200": {
"$ref": "#/responses/ProjectColumn"
},
"404": {
"$ref": "#/responses/notFound"
},
"422": {
"$ref": "#/responses/validationError"
}
}
}
},
"/repos/{owner}/{repo}/projects/{id}/columns/{column_id}/issues": {
"get": {
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "List issues in a project column",
"operationId": "repoListProjectColumnIssues",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the project",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the column",
"name": "column_id",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "page number of results to return (1-based)",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "page size of results",
"name": "limit",
"in": "query"
}
],
"responses": {
"200": {
"$ref": "#/responses/IssueList"
},
"404": {
"$ref": "#/responses/notFound"
}
}
}
},
"/repos/{owner}/{repo}/projects/{id}/columns/{column_id}/issues/{issue_id}": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Add an issue to a project column",
"operationId": "repoAddIssueToProjectColumn",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the project",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the column",
"name": "column_id",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the issue",
"name": "issue_id",
"in": "path",
"required": true
}
],
"responses": {
"201": {
"$ref": "#/responses/empty"
},
"403": {
"$ref": "#/responses/forbidden"
},
"404": {
"$ref": "#/responses/notFound"
},
"422": {
"$ref": "#/responses/validationError"
}
}
},
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "Remove an issue from a project column",
"operationId": "repoRemoveIssueFromProjectColumn",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the project",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the column",
"name": "column_id",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "id of the issue",
"name": "issue_id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"$ref": "#/responses/empty"
},
"403": {
"$ref": "#/responses/forbidden"
},
"404": {
"$ref": "#/responses/notFound"
},
"422": {
"$ref": "#/responses/validationError"
}
}
}
},
"/repos/{owner}/{repo}/pulls": { "/repos/{owner}/{repo}/pulls": {
"get": { "get": {
"produces": [ "produces": [