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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. }
  19. // CreateFileOptions options for creating files
  20. // 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)
  21. type CreateFileOptions struct {
  22. FileOptions
  23. // content must be base64 encoded
  24. // required: true
  25. Content string `json:"content"`
  26. }
  27. // DeleteFileOptions options for deleting files (used for other File structs below)
  28. // 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)
  29. type DeleteFileOptions struct {
  30. FileOptions
  31. // sha is the SHA for the file that already exists
  32. // required: true
  33. SHA string `json:"sha" binding:"Required"`
  34. }
  35. // UpdateFileOptions options for updating files
  36. // 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)
  37. type UpdateFileOptions struct {
  38. DeleteFileOptions
  39. // content must be base64 encoded
  40. // required: true
  41. Content string `json:"content"`
  42. // from_path (optional) is the path of the original file which will be moved/renamed to the path in the URL
  43. FromPath string `json:"from_path" binding:"MaxSize(500)"`
  44. }
  45. // FileLinksResponse contains the links for a repo's file
  46. type FileLinksResponse struct {
  47. Self *string `json:"self"`
  48. GitURL *string `json:"git"`
  49. HTMLURL *string `json:"html"`
  50. }
  51. // ContentsResponse contains information about a repo's entry's (dir, file, symlink, submodule) metadata and content
  52. type ContentsResponse struct {
  53. Name string `json:"name"`
  54. Path string `json:"path"`
  55. SHA string `json:"sha"`
  56. // `type` will be `file`, `dir`, `symlink`, or `submodule`
  57. Type string `json:"type"`
  58. Size int64 `json:"size"`
  59. // `encoding` is populated when `type` is `file`, otherwise null
  60. Encoding *string `json:"encoding"`
  61. // `content` is populated when `type` is `file`, otherwise null
  62. Content *string `json:"content"`
  63. // `target` is populated when `type` is `symlink`, otherwise null
  64. Target *string `json:"target"`
  65. URL *string `json:"url"`
  66. HTMLURL *string `json:"html_url"`
  67. GitURL *string `json:"git_url"`
  68. DownloadURL *string `json:"download_url"`
  69. // `submodule_git_url` is populated when `type` is `submodule`, otherwise null
  70. SubmoduleGitURL *string `json:"submodule_git_url"`
  71. Links *FileLinksResponse `json:"_links"`
  72. }
  73. // FileCommitResponse contains information generated from a Git commit for a repo's file.
  74. type FileCommitResponse struct {
  75. CommitMeta
  76. HTMLURL string `json:"html_url"`
  77. Author *CommitUser `json:"author"`
  78. Committer *CommitUser `json:"committer"`
  79. Parents []*CommitMeta `json:"parents"`
  80. Message string `json:"message"`
  81. Tree *CommitMeta `json:"tree"`
  82. }
  83. // FileResponse contains information about a repo's file
  84. type FileResponse struct {
  85. Content *ContentsResponse `json:"content"`
  86. Commit *FileCommitResponse `json:"commit"`
  87. Verification *PayloadCommitVerification `json:"verification"`
  88. }
  89. // FileDeleteResponse contains information about a repo's file that was deleted
  90. type FileDeleteResponse struct {
  91. Content interface{} `json:"content"` // to be set to nil
  92. Commit *FileCommitResponse `json:"commit"`
  93. Verification *PayloadCommitVerification `json:"verification"`
  94. }