From 1f951cdebae314a45b5e4ec1d464f1b4a53c8002 Mon Sep 17 00:00:00 2001 From: David Svantesson Date: Tue, 3 Sep 2019 17:46:24 +0200 Subject: Add API endpoint for accessing repo topics (#7963) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create API endpoints for repo topics. Signed-off-by: David Svantesson * Generate swagger Signed-off-by: David Svantesson * Add documentation to functions Signed-off-by: David Svantesson * Grammar fix Signed-off-by: David Svantesson * Fix function comment Signed-off-by: David Svantesson * Can't use FindTopics when looking for a single repo topic, as it doesnt use exact match Signed-off-by: David Svantesson * Add PUT ​/repos​/{owner}​/{repo}​/topics and remove GET ​/repos​/{owner}​/{repo}​/topics * Ignore if topic is sent twice in same request, refactoring. Signed-off-by: David Svantesson * Fix topic dropdown with api changes. Signed-off-by: David Svantesson * Style fix Signed-off-by: David Svantesson * Update API documentation Signed-off-by: David Svantesson * Better way to handle duplicate topics in slice Signed-off-by: David Svantesson * Make response element TopicName an array of strings, instead of using an array of TopicName Signed-off-by: David Svantesson * Add test cases for API Repo Topics. Signed-off-by: David Svantesson * Fix format of tests Signed-off-by: David Svantesson * Fix comments Signed-off-by: David Svantesson * Fix unit tests after adding some more topics to the test fixture. Signed-off-by: David Svantesson * Update models/topic.go Limit multiple if else if ... Co-Authored-By: Antoine GIRARD * Engine as first parameter in function Co-Authored-By: Antoine GIRARD * Replace magic numbers with http status code constants. Signed-off-by: David Svantesson * Fix variable scope Signed-off-by: David Svantesson * Test one read with login and one with token Signed-off-by: David Svantesson * Add some more tests Signed-off-by: David Svantesson * Apply suggestions from code review Use empty struct for efficiency Co-Authored-By: Lauris BH * Add test case to check access for user with write access Signed-off-by: David Svantesson * Fix access, repo admin required to change topics Signed-off-by: David Svantesson * Correct first test to be without token Signed-off-by: David Svantesson * Any repo reader should be able to access topics. * No need for string pointer Signed-off-by: David Svantesson --- templates/swagger/v1_json.tmpl | 228 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 226 insertions(+), 2 deletions(-) (limited to 'templates') diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index eed60c044c..8cf22251a6 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -5451,6 +5451,155 @@ } } }, + "/repos/{owner}/{repo}/topics": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Get list of topics that a repository has", + "operationId": "repoListTopics", + "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 + } + ], + "responses": { + "200": { + "$ref": "#/responses/TopicNames" + } + } + }, + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Replace list of topics for a repository", + "operationId": "repoUpdateTopics", + "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 + }, + { + "name": "body", + "in": "body", + "schema": { + "$ref": "#/definitions/RepoTopicOptions" + } + } + ], + "responses": { + "204": { + "$ref": "#/responses/empty" + } + } + } + }, + "/repos/{owner}/{repo}/topics/{topic}": { + "put": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Add a topic to a repository", + "operationId": "repoAddTopíc", + "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": "string", + "description": "name of the topic to add", + "name": "topic", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "$ref": "#/responses/empty" + } + } + }, + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Delete a topic from a repository", + "operationId": "repoDeleteTopic", + "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": "string", + "description": "name of the topic to delete", + "name": "topic", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "$ref": "#/responses/empty" + } + } + } + }, "/repositories/{id}": { "get": { "produces": [ @@ -5815,7 +5964,7 @@ ], "responses": { "200": { - "$ref": "#/responses/Repository" + "$ref": "#/responses/TopicListResponse" } } } @@ -9561,6 +9710,21 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "RepoTopicOptions": { + "description": "RepoTopicOptions a collection of repo topic names", + "type": "object", + "properties": { + "topics": { + "description": "list of topic names", + "type": "array", + "items": { + "type": "string" + }, + "x-go-name": "Topics" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "Repository": { "description": "Repository represents a repository", "type": "object", @@ -9874,6 +10038,51 @@ "format": "int64", "x-go-package": "code.gitea.io/gitea/modules/timeutil" }, + "TopicName": { + "description": "TopicName a list of repo topic names", + "type": "object", + "properties": { + "topics": { + "type": "array", + "items": { + "type": "string" + }, + "x-go-name": "TopicNames" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, + "TopicResponse": { + "description": "TopicResponse for returning topics", + "type": "object", + "properties": { + "created": { + "type": "string", + "format": "date-time", + "x-go-name": "Created" + }, + "id": { + "type": "integer", + "format": "int64", + "x-go-name": "ID" + }, + "repo_count": { + "type": "integer", + "format": "int64", + "x-go-name": "RepoCount" + }, + "topic_name": { + "type": "string", + "x-go-name": "Name" + }, + "updated": { + "type": "string", + "format": "date-time", + "x-go-name": "Updated" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "TrackedTime": { "description": "TrackedTime worked time for an issue / pr", "type": "object", @@ -10493,6 +10702,21 @@ } } }, + "TopicListResponse": { + "description": "TopicListResponse", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/TopicResponse" + } + } + }, + "TopicNames": { + "description": "TopicNames", + "schema": { + "$ref": "#/definitions/TopicName" + } + }, "TrackedTime": { "description": "TrackedTime", "schema": { @@ -10569,7 +10793,7 @@ "parameterBodies": { "description": "parameterBodies", "schema": { - "$ref": "#/definitions/DeleteFileOptions" + "$ref": "#/definitions/RepoTopicOptions" } }, "redirect": { -- cgit v1.2.3