mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 11:52:10 +00:00
[API] Add repoCreateTag (#16165)
* Add API CreateTag * Add Test * API: expose Tag Message
This commit is contained in:
parent
19dedc3fa5
commit
f7cd394680
7 changed files with 180 additions and 3 deletions
|
@ -775,6 +775,7 @@ func Routes() *web.Route {
|
|||
}, reqToken(), reqAdmin())
|
||||
m.Group("/tags", func() {
|
||||
m.Get("", repo.ListTags)
|
||||
m.Post("", reqRepoWriter(models.UnitTypeCode), bind(api.CreateTagOption{}), repo.CreateTag)
|
||||
m.Delete("/{tag}", repo.DeleteTag)
|
||||
}, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(true))
|
||||
m.Group("/keys", func() {
|
||||
|
|
|
@ -6,12 +6,14 @@ package repo
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"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/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
releaseservice "code.gitea.io/gitea/services/release"
|
||||
)
|
||||
|
@ -160,3 +162,62 @@ func DeleteTag(ctx *context.APIContext) {
|
|||
|
||||
ctx.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// CreateTag create a new git tag in a repository
|
||||
func CreateTag(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/tags repository repoCreateTag
|
||||
// ---
|
||||
// summary: Create a new git tag in a repository
|
||||
// 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: body
|
||||
// in: body
|
||||
// schema:
|
||||
// "$ref": "#/definitions/CreateTagOption"
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/AnnotatedTag"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "409":
|
||||
// "$ref": "#/responses/conflict"
|
||||
form := web.GetForm(ctx).(*api.CreateTagOption)
|
||||
|
||||
// If target is not provided use default branch
|
||||
if len(form.Target) == 0 {
|
||||
form.Target = ctx.Repo.Repository.DefaultBranch
|
||||
}
|
||||
|
||||
commit, err := ctx.Repo.GitRepo.GetCommit(form.Target)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusNotFound, "target not found", fmt.Errorf("target not found: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
if err := releaseservice.CreateNewTag(ctx.User, ctx.Repo.Repository, commit.ID.String(), form.TagName, form.Message); err != nil {
|
||||
if models.IsErrTagAlreadyExists(err) {
|
||||
ctx.Error(http.StatusConflict, "tag exist", err)
|
||||
return
|
||||
}
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
tag, err := ctx.Repo.GitRepo.GetTag(form.TagName)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusCreated, convert.ToTag(ctx.Repo.Repository, tag))
|
||||
}
|
||||
|
|
|
@ -158,4 +158,7 @@ type swaggerParameterBodies struct {
|
|||
|
||||
// in:body
|
||||
PullReviewRequestOptions api.PullReviewRequestOptions
|
||||
|
||||
// in:body
|
||||
CreateTagOption api.CreateTagOption
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue