You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_file.go 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2019 The Gitea Authors. All rights reserved.
  3. // SPDX-License-Identifier: MIT
  4. package structs
  5. // FileOptions options for all file APIs
  6. type FileOptions struct {
  7. // message (optional) for the commit of this file. if not supplied, a default message will be used
  8. Message string `json:"message"`
  9. // branch (optional) to base this file from. if not given, the default branch is used
  10. BranchName string `json:"branch" binding:"GitRefName;MaxSize(100)"`
  11. // new_branch (optional) will make a new branch from `branch` before creating the file
  12. NewBranchName string `json:"new_branch" binding:"GitRefName;MaxSize(100)"`
  13. // `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
  14. Author Identity `json:"author"`
  15. Committer Identity `json:"committer"`
  16. Dates CommitDateOptions `json:"dates"`
  17. // Add a Signed-off-by trailer by the committer at the end of the commit log message.
  18. Signoff bool `json:"signoff"`
  19. }
  20. // CreateFileOptions options for creating files
  21. // Note: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
  22. type CreateFileOptions struct {
  23. FileOptions
  24. // content must be base64 encoded
  25. // required: true
  26. ContentBase64 string `json:"content"`
  27. }
  28. // Branch returns branch name
  29. func (o *CreateFileOptions) Branch() string {
  30. return o.FileOptions.BranchName
  31. }
  32. // DeleteFileOptions options for deleting files (used for other File structs below)
  33. // Note: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
  34. type DeleteFileOptions struct {
  35. FileOptions
  36. // sha is the SHA for the file that already exists
  37. // required: true
  38. SHA string `json:"sha" binding:"Required"`
  39. }
  40. // Branch returns branch name
  41. func (o *DeleteFileOptions) Branch() string {
  42. return o.FileOptions.BranchName
  43. }
  44. // UpdateFileOptions options for updating files
  45. // Note: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
  46. type UpdateFileOptions struct {
  47. DeleteFileOptions
  48. // content must be base64 encoded
  49. // required: true
  50. ContentBase64 string `json:"content"`
  51. // from_path (optional) is the path of the original file which will be moved/renamed to the path in the URL
  52. FromPath string `json:"from_path" binding:"MaxSize(500)"`
  53. }
  54. // Branch returns branch name
  55. func (o *UpdateFileOptions) Branch() string {
  56. return o.FileOptions.BranchName
  57. }
  58. // ChangeFileOperation for creating, updating or deleting a file
  59. type ChangeFileOperation struct {
  60. // indicates what to do with the file
  61. // required: true
  62. // enum: create,update,delete
  63. Operation string `json:"operation" binding:"Required"`
  64. // path to the existing or new file
  65. // required: true
  66. Path string `json:"path" binding:"Required;MaxSize(500)"`
  67. // new or updated file content, must be base64 encoded
  68. ContentBase64 string `json:"content"`
  69. // sha is the SHA for the file that already exists, required for update or delete
  70. SHA string `json:"sha"`
  71. // old path of the file to move
  72. FromPath string `json:"from_path"`
  73. }
  74. // ChangeFilesOptions options for creating, updating or deleting multiple files
  75. // Note: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
  76. type ChangeFilesOptions struct {
  77. FileOptions
  78. // list of file operations
  79. // required: true
  80. Files []*ChangeFileOperation `json:"files" binding:"Required"`
  81. }
  82. // Branch returns branch name
  83. func (o *ChangeFilesOptions) Branch() string {
  84. return o.FileOptions.BranchName
  85. }
  86. // FileOptionInterface provides a unified interface for the different file options
  87. type FileOptionInterface interface {
  88. Branch() string
  89. }
  90. // ApplyDiffPatchFileOptions options for applying a diff patch
  91. // Note: `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
  92. type ApplyDiffPatchFileOptions struct {
  93. DeleteFileOptions
  94. // required: true
  95. Content string `json:"content"`
  96. }
  97. // FileLinksResponse contains the links for a repo's file
  98. type FileLinksResponse struct {
  99. Self *string `json:"self"`
  100. GitURL *string `json:"git"`
  101. HTMLURL *string `json:"html"`
  102. }
  103. // ContentsResponse contains information about a repo's entry's (dir, file, symlink, submodule) metadata and content
  104. type ContentsResponse struct {
  105. Name string `json:"name"`
  106. Path string `json:"path"`
  107. SHA string `json:"sha"`
  108. LastCommitSHA string `json:"last_commit_sha"`
  109. // `type` will be `file`, `dir`, `symlink`, or `submodule`
  110. Type string `json:"type"`
  111. Size int64 `json:"size"`
  112. // `encoding` is populated when `type` is `file`, otherwise null
  113. Encoding *string `json:"encoding"`
  114. // `content` is populated when `type` is `file`, otherwise null
  115. Content *string `json:"content"`
  116. // `target` is populated when `type` is `symlink`, otherwise null
  117. Target *string `json:"target"`
  118. URL *string `json:"url"`
  119. HTMLURL *string `json:"html_url"`
  120. GitURL *string `json:"git_url"`
  121. DownloadURL *string `json:"download_url"`
  122. // `submodule_git_url` is populated when `type` is `submodule`, otherwise null
  123. SubmoduleGitURL *string `json:"submodule_git_url"`
  124. Links *FileLinksResponse `json:"_links"`
  125. }
  126. // FileCommitResponse contains information generated from a Git commit for a repo's file.
  127. type FileCommitResponse struct {
  128. CommitMeta
  129. HTMLURL string `json:"html_url"`
  130. Author *CommitUser `json:"author"`
  131. Committer *CommitUser `json:"committer"`
  132. Parents []*CommitMeta `json:"parents"`
  133. Message string `json:"message"`
  134. Tree *CommitMeta `json:"tree"`
  135. }
  136. // FileResponse contains information about a repo's file
  137. type FileResponse struct {
  138. Content *ContentsResponse `json:"content"`
  139. Commit *FileCommitResponse `json:"commit"`
  140. Verification *PayloadCommitVerification `json:"verification"`
  141. }
  142. // FilesResponse contains information about multiple files from a repo
  143. type FilesResponse struct {
  144. Files []*ContentsResponse `json:"files"`
  145. Commit *FileCommitResponse `json:"commit"`
  146. Verification *PayloadCommitVerification `json:"verification"`
  147. }
  148. // FileDeleteResponse contains information about a repo's file that was deleted
  149. type FileDeleteResponse struct {
  150. Content any `json:"content"` // to be set to nil
  151. Commit *FileCommitResponse `json:"commit"`
  152. Verification *PayloadCommitVerification `json:"verification"`
  153. }