Skip to content

Commit fa39bca

Browse files
committed
api: make updating name optional in repo edit
and path escape the new name param
1 parent 827098a commit fa39bca

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

api/repos.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func apiReposCreate(c *gin.Context) {
167167

168168
type reposEditParams struct {
169169
// Name of repository to modify
170-
Name *string `binding:"required" json:"Name" example:"repo1"`
170+
Name *string ` json:"Name" example:"new-repo-name"`
171171
// Change Comment of repository
172172
Comment *string ` json:"Comment" example:"example repo"`
173173
// Change Default Distribution for publishing
@@ -179,7 +179,7 @@ type reposEditParams struct {
179179
// @Summary Update Repository
180180
// @Description **Update local repository meta information**
181181
// @Tags Repos
182-
// @Param name path string true "Repository name"
182+
// @Param name path string true "Repository name to modify"
183183
// @Consume json
184184
// @Param request body reposEditParams true "Parameters"
185185
// @Produce json
@@ -192,15 +192,20 @@ func apiReposEdit(c *gin.Context) {
192192
if c.Bind(&b) != nil {
193193
return
194194
}
195+
if b.Name != nil {
196+
new_name, err := url.PathUnescape(*b.Name)
197+
if err != nil {
198+
AbortWithJSONError(c, 400, err)
199+
return
200+
}
201+
*b.Name = new_name
202+
}
203+
195204

196205
collectionFactory := context.NewCollectionFactory()
197206
collection := collectionFactory.LocalRepoCollection()
198207

199-
name, err := url.PathUnescape(c.Params.ByName("name"))
200-
if err != nil {
201-
AbortWithJSONError(c, 400, err)
202-
return
203-
}
208+
name := c.Params.ByName("name") // repo to modify
204209
repo, err := collection.ByName(name)
205210
if err != nil {
206211
AbortWithJSONError(c, 404, err)

0 commit comments

Comments
 (0)