summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-02-07 19:32:18 +0100
committerGitHub <noreply@github.com>2021-02-07 19:32:18 +0100
commit5f248d0df290fd08ed54e31424cbb8d8517229e3 (patch)
tree99d0b8dd73d4eceed3e100a69bfa47bd7e94c723 /routers/api
parent240fea8c14434f836677e6c883ef90523950ece5 (diff)
downloadgitea-5f248d0df290fd08ed54e31424cbb8d8517229e3.tar.gz
gitea-5f248d0df290fd08ed54e31424cbb8d8517229e3.zip
[API] Add delete release by tag & fix unreleased inconsistency (#14563)
* DeleteReleaseByTag delete release not git tags * Add api to delete tag (without release) * fix & extend tests * fix swagger doc
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/api.go5
-rw-r--r--routers/api/v1/repo/release_tags.go29
-rw-r--r--routers/api/v1/repo/tag.go56
3 files changed, 72 insertions, 18 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 42b52db936..9c21107a28 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -754,6 +754,7 @@ func Routes() *web.Route {
}, reqToken(), reqAdmin())
m.Group("/tags", func() {
m.Get("", repo.ListTags)
+ m.Delete("/{tag}", repo.DeleteTag)
}, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true))
m.Group("/keys", func() {
m.Combo("").Get(repo.ListDeployKeys).
@@ -862,8 +863,8 @@ func Routes() *web.Route {
})
m.Group("/tags", func() {
m.Combo("/{tag}").
- Get(repo.GetReleaseTag).
- Delete(reqToken(), reqRepoWriter(models.UnitTypeReleases), repo.DeleteReleaseTag)
+ Get(repo.GetReleaseByTag).
+ Delete(reqToken(), reqRepoWriter(models.UnitTypeReleases), repo.DeleteReleaseByTag)
})
}, reqRepoReader(models.UnitTypeReleases))
m.Post("/mirror-sync", reqToken(), reqRepoWriter(models.UnitTypeCode), repo.MirrorSync)
diff --git a/routers/api/v1/repo/release_tags.go b/routers/api/v1/repo/release_tags.go
index 70011a6a8e..4b853d44bb 100644
--- a/routers/api/v1/repo/release_tags.go
+++ b/routers/api/v1/repo/release_tags.go
@@ -5,7 +5,6 @@
package repo
import (
- "errors"
"net/http"
"code.gitea.io/gitea/models"
@@ -14,9 +13,9 @@ import (
releaseservice "code.gitea.io/gitea/services/release"
)
-// GetReleaseTag get a single release of a repository by its tagname
-func GetReleaseTag(ctx *context.APIContext) {
- // swagger:operation GET /repos/{owner}/{repo}/releases/tags/{tag} repository repoGetReleaseTag
+// GetReleaseByTag get a single release of a repository by tag name
+func GetReleaseByTag(ctx *context.APIContext) {
+ // swagger:operation GET /repos/{owner}/{repo}/releases/tags/{tag} repository repoGetReleaseByTag
// ---
// summary: Get a release by tag name
// produces:
@@ -34,7 +33,7 @@ func GetReleaseTag(ctx *context.APIContext) {
// required: true
// - name: tag
// in: path
- // description: tagname of the release to get
+ // description: tag name of the release to get
// type: string
// required: true
// responses:
@@ -67,11 +66,11 @@ func GetReleaseTag(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, convert.ToRelease(release))
}
-// DeleteReleaseTag delete a tag from a repository
-func DeleteReleaseTag(ctx *context.APIContext) {
- // swagger:operation DELETE /repos/{owner}/{repo}/releases/tags/{tag} repository repoDeleteReleaseTag
+// DeleteReleaseByTag delete a release from a repository by tag name
+func DeleteReleaseByTag(ctx *context.APIContext) {
+ // swagger:operation DELETE /repos/{owner}/{repo}/releases/tags/{tag} repository repoDeleteReleaseByTag
// ---
- // summary: Delete a release tag
+ // summary: Delete a release by tag name
// parameters:
// - name: owner
// in: path
@@ -85,7 +84,7 @@ func DeleteReleaseTag(ctx *context.APIContext) {
// required: true
// - name: tag
// in: path
- // description: name of the tag to delete
+ // description: tag name of the release to delete
// type: string
// required: true
// responses:
@@ -93,27 +92,25 @@ func DeleteReleaseTag(ctx *context.APIContext) {
// "$ref": "#/responses/empty"
// "404":
// "$ref": "#/responses/notFound"
- // "409":
- // "$ref": "#/responses/conflict"
tag := ctx.Params(":tag")
release, err := models.GetRelease(ctx.Repo.Repository.ID, tag)
if err != nil {
if models.IsErrReleaseNotExist(err) {
- ctx.Error(http.StatusNotFound, "GetRelease", err)
+ ctx.NotFound()
return
}
ctx.Error(http.StatusInternalServerError, "GetRelease", err)
return
}
- if !release.IsTag {
- ctx.Error(http.StatusConflict, "IsTag", errors.New("a tag attached to a release cannot be deleted directly"))
+ if release.IsTag {
+ ctx.NotFound()
return
}
- if err := releaseservice.DeleteReleaseByID(release.ID, ctx.User, true); err != nil {
+ if err = releaseservice.DeleteReleaseByID(release.ID, ctx.User, false); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
}
diff --git a/routers/api/v1/repo/tag.go b/routers/api/v1/repo/tag.go
index 76c612bea4..ec9b541bd4 100644
--- a/routers/api/v1/repo/tag.go
+++ b/routers/api/v1/repo/tag.go
@@ -5,12 +5,15 @@
package repo
import (
+ "errors"
"net/http"
+ "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/convert"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/routers/api/v1/utils"
+ releaseservice "code.gitea.io/gitea/services/release"
)
// ListTags list all the tags of a repository
@@ -104,3 +107,56 @@ func GetTag(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, convert.ToAnnotatedTag(ctx.Repo.Repository, tag, commit))
}
}
+
+// DeleteTag delete a specific tag of in a repository by name
+func DeleteTag(ctx *context.APIContext) {
+ // swagger:operation DELETE /repos/{owner}/{repo}/tags/{tag} repository repoDeleteTag
+ // ---
+ // summary: Delete a repository's tag by name
+ // produces:
+ // - application/json
+ // parameters:
+ // - name: owner
+ // in: path
+ // description: owner of the repo
+ // type: string
+ // required: true
+ // - name: repo
+ // in: path
+ // description: name of the repo
+ // type: string
+ // required: true
+ // - name: tag
+ // in: path
+ // description: name of tag to delete
+ // type: string
+ // required: true
+ // responses:
+ // "204":
+ // "$ref": "#/responses/empty"
+ // "404":
+ // "$ref": "#/responses/notFound"
+ // "409":
+ // "$ref": "#/responses/conflict"
+
+ tag, err := models.GetRelease(ctx.Repo.Repository.ID, ctx.Params("tag"))
+ if err != nil {
+ if models.IsErrReleaseNotExist(err) {
+ ctx.NotFound()
+ return
+ }
+ ctx.Error(http.StatusInternalServerError, "GetRelease", err)
+ return
+ }
+
+ if !tag.IsTag {
+ ctx.Error(http.StatusConflict, "IsTag", errors.New("a tag attached to a release cannot be deleted directly"))
+ return
+ }
+
+ if err = releaseservice.DeleteReleaseByID(tag.ID, ctx.User, true); err != nil {
+ ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
+ }
+
+ ctx.Status(http.StatusNoContent)
+}