@@ -64,9 +64,9 @@ func ListTags(ctx *context.APIContext) {
6464 ctx .JSON (http .StatusOK , & apiTags )
6565}
6666
67- // GetTag get the tag of a repository.
68- func GetTag (ctx * context.APIContext ) {
69- // swagger:operation GET /repos/{owner}/{repo}/git/tags/{sha} repository GetTag
67+ // GetAnnotatedTag get the tag of a repository.
68+ func GetAnnotatedTag (ctx * context.APIContext ) {
69+ // swagger:operation GET /repos/{owner}/{repo}/git/tags/{sha} repository GetAnnotatedTag
7070 // ---
7171 // summary: Gets the tag object of an annotated tag (not lightweight tags)
7272 // produces:
@@ -100,21 +100,21 @@ func GetTag(ctx *context.APIContext) {
100100 }
101101
102102 if tag , err := ctx .Repo .GitRepo .GetAnnotatedTag (sha ); err != nil {
103- ctx .Error (http .StatusBadRequest , "GetTag " , err )
103+ ctx .Error (http .StatusBadRequest , "GetAnnotatedTag " , err )
104104 } else {
105105 commit , err := tag .Commit ()
106106 if err != nil {
107- ctx .Error (http .StatusBadRequest , "GetTag " , err )
107+ ctx .Error (http .StatusBadRequest , "GetAnnotatedTag " , err )
108108 }
109109 ctx .JSON (http .StatusOK , convert .ToAnnotatedTag (ctx .Repo .Repository , tag , commit ))
110110 }
111111}
112112
113- // DeleteTag delete a specific tag of in a repository by name
114- func DeleteTag (ctx * context.APIContext ) {
115- // swagger:operation DELETE /repos/{owner}/{repo}/tags/{tag} repository repoDeleteTag
113+ // GetTag get the tag of a repository
114+ func GetTag (ctx * context.APIContext ) {
115+ // swagger:operation GET /repos/{owner}/{repo}/tags/{tag} repository repoGetTag
116116 // ---
117- // summary: Delete a repository's tag by name
117+ // summary: Get the tag of a repository by tag name
118118 // produces:
119119 // - application/json
120120 // parameters:
@@ -130,37 +130,22 @@ func DeleteTag(ctx *context.APIContext) {
130130 // required: true
131131 // - name: tag
132132 // in: path
133- // description: name of tag to delete
133+ // description: name of tag
134134 // type: string
135135 // required: true
136136 // responses:
137- // "204 ":
138- // "$ref": "#/responses/empty "
137+ // "200 ":
138+ // "$ref": "#/responses/Tag "
139139 // "404":
140140 // "$ref": "#/responses/notFound"
141- // "409":
142- // "$ref": "#/responses/conflict"
141+ tagName := ctx .Params ("*" )
143142
144- tag , err := models . GetRelease ( ctx .Repo .Repository . ID , ctx . Params ( "tag" ) )
143+ tag , err := ctx .Repo .GitRepo . GetTag ( tagName )
145144 if err != nil {
146- if models .IsErrReleaseNotExist (err ) {
147- ctx .NotFound ()
148- return
149- }
150- ctx .Error (http .StatusInternalServerError , "GetRelease" , err )
145+ ctx .NotFound (tagName )
151146 return
152147 }
153-
154- if ! tag .IsTag {
155- ctx .Error (http .StatusConflict , "IsTag" , errors .New ("a tag attached to a release cannot be deleted directly" ))
156- return
157- }
158-
159- if err = releaseservice .DeleteReleaseByID (tag .ID , ctx .User , true ); err != nil {
160- ctx .Error (http .StatusInternalServerError , "DeleteReleaseByID" , err )
161- }
162-
163- ctx .Status (http .StatusNoContent )
148+ ctx .JSON (http .StatusOK , convert .ToTag (ctx .Repo .Repository , tag ))
164149}
165150
166151// CreateTag create a new git tag in a repository
@@ -187,7 +172,7 @@ func CreateTag(ctx *context.APIContext) {
187172 // "$ref": "#/definitions/CreateTagOption"
188173 // responses:
189174 // "200":
190- // "$ref": "#/responses/AnnotatedTag "
175+ // "$ref": "#/responses/Tag "
191176 // "404":
192177 // "$ref": "#/responses/notFound"
193178 // "409":
@@ -221,3 +206,57 @@ func CreateTag(ctx *context.APIContext) {
221206 }
222207 ctx .JSON (http .StatusCreated , convert .ToTag (ctx .Repo .Repository , tag ))
223208}
209+
210+ // DeleteTag delete a specific tag of in a repository by name
211+ func DeleteTag (ctx * context.APIContext ) {
212+ // swagger:operation DELETE /repos/{owner}/{repo}/tags/{tag} repository repoDeleteTag
213+ // ---
214+ // summary: Delete a repository's tag by name
215+ // produces:
216+ // - application/json
217+ // parameters:
218+ // - name: owner
219+ // in: path
220+ // description: owner of the repo
221+ // type: string
222+ // required: true
223+ // - name: repo
224+ // in: path
225+ // description: name of the repo
226+ // type: string
227+ // required: true
228+ // - name: tag
229+ // in: path
230+ // description: name of tag to delete
231+ // type: string
232+ // required: true
233+ // responses:
234+ // "204":
235+ // "$ref": "#/responses/empty"
236+ // "404":
237+ // "$ref": "#/responses/notFound"
238+ // "409":
239+ // "$ref": "#/responses/conflict"
240+ tagName := ctx .Params ("*" )
241+
242+ tag , err := models .GetRelease (ctx .Repo .Repository .ID , tagName )
243+ if err != nil {
244+ if models .IsErrReleaseNotExist (err ) {
245+ ctx .NotFound ()
246+ return
247+ }
248+ ctx .Error (http .StatusInternalServerError , "GetRelease" , err )
249+ return
250+ }
251+
252+ if ! tag .IsTag {
253+ ctx .Error (http .StatusConflict , "IsTag" , errors .New ("a tag attached to a release cannot be deleted directly" ))
254+ return
255+ }
256+
257+ if err = releaseservice .DeleteReleaseByID (tag .ID , ctx .User , true ); err != nil {
258+ ctx .Error (http .StatusInternalServerError , "DeleteReleaseByID" , err )
259+ }
260+
261+ ctx .Status (http .StatusNoContent )
262+ }
0 commit comments