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 5.3KB

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