gitea源码

patch.go 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repo
  4. import (
  5. "net/http"
  6. api "code.gitea.io/gitea/modules/structs"
  7. "code.gitea.io/gitea/modules/util"
  8. "code.gitea.io/gitea/services/context"
  9. "code.gitea.io/gitea/services/repository/files"
  10. )
  11. // ApplyDiffPatch handles API call for applying a patch
  12. func ApplyDiffPatch(ctx *context.APIContext) {
  13. // swagger:operation POST /repos/{owner}/{repo}/diffpatch repository repoApplyDiffPatch
  14. // ---
  15. // summary: Apply diff patch to repository
  16. // consumes:
  17. // - application/json
  18. // produces:
  19. // - application/json
  20. // parameters:
  21. // - name: owner
  22. // in: path
  23. // description: owner of the repo
  24. // type: string
  25. // required: true
  26. // - name: repo
  27. // in: path
  28. // description: name of the repo
  29. // type: string
  30. // required: true
  31. // - name: body
  32. // in: body
  33. // required: true
  34. // schema:
  35. // "$ref": "#/definitions/UpdateFileOptions"
  36. // responses:
  37. // "200":
  38. // "$ref": "#/responses/FileResponse"
  39. // "404":
  40. // "$ref": "#/responses/notFound"
  41. // "423":
  42. // "$ref": "#/responses/repoArchivedError"
  43. apiOpts, changeRepoFileOpts := getAPIChangeRepoFileOptions[*api.ApplyDiffPatchFileOptions](ctx)
  44. opts := &files.ApplyDiffPatchOptions{
  45. Content: apiOpts.Content,
  46. Message: util.IfZero(apiOpts.Message, "apply-patch"),
  47. OldBranch: changeRepoFileOpts.OldBranch,
  48. NewBranch: changeRepoFileOpts.NewBranch,
  49. Committer: changeRepoFileOpts.Committer,
  50. Author: changeRepoFileOpts.Author,
  51. Dates: changeRepoFileOpts.Dates,
  52. Signoff: changeRepoFileOpts.Signoff,
  53. }
  54. fileResponse, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, opts)
  55. if err != nil {
  56. handleChangeRepoFilesError(ctx, err)
  57. } else {
  58. ctx.JSON(http.StatusCreated, fileResponse)
  59. }
  60. }