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