2022-02-09 20:28:55 +00:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-02-09 20:28:55 +00:00
|
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2025-06-26 02:25:20 +08:00
|
|
|
"code.gitea.io/gitea/modules/util"
|
2024-02-27 15:12:22 +08:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2022-02-09 20:28:55 +00:00
|
|
|
"code.gitea.io/gitea/services/repository/files"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ApplyDiffPatch handles API call for applying a patch
|
|
|
|
|
func ApplyDiffPatch(ctx *context.APIContext) {
|
|
|
|
|
// swagger:operation POST /repos/{owner}/{repo}/diffpatch repository repoApplyDiffPatch
|
|
|
|
|
// ---
|
|
|
|
|
// summary: Apply diff patch to repository
|
|
|
|
|
// consumes:
|
|
|
|
|
// - application/json
|
|
|
|
|
// 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
|
|
|
|
|
// required: true
|
|
|
|
|
// schema:
|
2025-10-09 22:09:14 +05:30
|
|
|
// "$ref": "#/definitions/ApplyDiffPatchFileOptions"
|
2022-02-09 20:28:55 +00:00
|
|
|
// responses:
|
|
|
|
|
// "200":
|
|
|
|
|
// "$ref": "#/responses/FileResponse"
|
2023-09-13 04:37:54 +02:00
|
|
|
// "404":
|
|
|
|
|
// "$ref": "#/responses/notFound"
|
2023-09-22 01:43:29 +02:00
|
|
|
// "423":
|
|
|
|
|
// "$ref": "#/responses/repoArchivedError"
|
2025-06-26 02:25:20 +08:00
|
|
|
apiOpts, changeRepoFileOpts := getAPIChangeRepoFileOptions[*api.ApplyDiffPatchFileOptions](ctx)
|
2022-02-09 20:28:55 +00:00
|
|
|
opts := &files.ApplyDiffPatchOptions{
|
2025-06-26 02:25:20 +08:00
|
|
|
Content: apiOpts.Content,
|
|
|
|
|
Message: util.IfZero(apiOpts.Message, "apply-patch"),
|
2022-02-09 20:28:55 +00:00
|
|
|
|
2025-06-26 02:25:20 +08:00
|
|
|
OldBranch: changeRepoFileOpts.OldBranch,
|
|
|
|
|
NewBranch: changeRepoFileOpts.NewBranch,
|
|
|
|
|
Committer: changeRepoFileOpts.Committer,
|
|
|
|
|
Author: changeRepoFileOpts.Author,
|
|
|
|
|
Dates: changeRepoFileOpts.Dates,
|
|
|
|
|
Signoff: changeRepoFileOpts.Signoff,
|
2022-02-09 20:28:55 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-22 08:03:22 +01:00
|
|
|
fileResponse, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, opts)
|
2022-02-09 20:28:55 +00:00
|
|
|
if err != nil {
|
2025-06-26 02:25:20 +08:00
|
|
|
handleChangeRepoFilesError(ctx, err)
|
2022-02-09 20:28:55 +00:00
|
|
|
} else {
|
|
|
|
|
ctx.JSON(http.StatusCreated, fileResponse)
|
|
|
|
|
}
|
|
|
|
|
}
|