mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-10-18 08:08:31 +00:00
feat: Add converting mirror repos to normal to the API (#8932)
- Add `POST /repos/{owner}/{repo}/convert` to the API to allow mirror repositories to be converted to normal repositories. - Resolves forgejo/forgejo#7733 Co-authored-by: Charles Martinot <charles.martinot@protonmail.com> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8932 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: mactynow <mactynow@noreply.codeberg.org> Co-committed-by: mactynow <mactynow@noreply.codeberg.org>
This commit is contained in:
parent
8767613338
commit
0b1942150f
8 changed files with 209 additions and 6 deletions
|
@ -672,6 +672,47 @@ func Edit(ctx *context.APIContext) {
|
|||
ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, ctx.Repo.Permission))
|
||||
}
|
||||
|
||||
// Convert converts a mirror to a normal repo
|
||||
func Convert(ctx *context.APIContext) {
|
||||
// swagger:operation POST /repos/{owner}/{repo}/convert repository repoConvert
|
||||
// ---
|
||||
// summary: Convert a mirror repo to a normal repo.
|
||||
// produces:
|
||||
// - application/json
|
||||
// parameters:
|
||||
// - name: owner
|
||||
// in: path
|
||||
// description: owner of the repo to convert
|
||||
// type: string
|
||||
// required: true
|
||||
// - name: repo
|
||||
// in: path
|
||||
// description: name of the repo to convert
|
||||
// type: string
|
||||
// required: true
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/Repository"
|
||||
// "403":
|
||||
// "$ref": "#/responses/forbidden"
|
||||
// "404":
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "422":
|
||||
// "$ref": "#/responses/validationError"
|
||||
|
||||
if err := convertMirrorToNormalRepo(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
repo, err := repo_model.GetRepositoryByID(ctx, ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, convert.ToRepo(ctx, repo, ctx.Repo.Permission))
|
||||
}
|
||||
|
||||
// updateBasicProperties updates the basic properties of a repo: Name, Description, Website and Visibility
|
||||
func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) error {
|
||||
owner := ctx.Repo.Owner
|
||||
|
@ -1140,6 +1181,25 @@ func updateMirror(ctx *context.APIContext, opts api.EditRepoOption) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// convertMirrorToNormalRepository converts a mirror to a normal repo
|
||||
func convertMirrorToNormalRepo(ctx *context.APIContext) error {
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
if !repo.IsMirror {
|
||||
err := errors.New("Repository is not a mirror")
|
||||
ctx.Error(http.StatusUnprocessableEntity, "ConvertMirror", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := repo_service.ConvertMirrorToNormalRepo(ctx, repo); err != nil {
|
||||
log.Error("Failed to Disable Mirror: %s", err)
|
||||
ctx.Error(http.StatusUnprocessableEntity, "ConvertMirror", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete one repository
|
||||
func Delete(ctx *context.APIContext) {
|
||||
// swagger:operation DELETE /repos/{owner}/{repo} repository repoDelete
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue