code.gitea.io/gitea@v1.19.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 Content 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 Content 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 // FileOptionInterface provides a unified interface for the different file options 68 type FileOptionInterface interface { 69 Branch() string 70 } 71 72 // ApplyDiffPatchFileOptions options for applying a diff patch 73 // 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) 74 type ApplyDiffPatchFileOptions struct { 75 DeleteFileOptions 76 // required: true 77 Content string `json:"content"` 78 } 79 80 // FileLinksResponse contains the links for a repo's file 81 type FileLinksResponse struct { 82 Self *string `json:"self"` 83 GitURL *string `json:"git"` 84 HTMLURL *string `json:"html"` 85 } 86 87 // ContentsResponse contains information about a repo's entry's (dir, file, symlink, submodule) metadata and content 88 type ContentsResponse struct { 89 Name string `json:"name"` 90 Path string `json:"path"` 91 SHA string `json:"sha"` 92 LastCommitSHA string `json:"last_commit_sha"` 93 // `type` will be `file`, `dir`, `symlink`, or `submodule` 94 Type string `json:"type"` 95 Size int64 `json:"size"` 96 // `encoding` is populated when `type` is `file`, otherwise null 97 Encoding *string `json:"encoding"` 98 // `content` is populated when `type` is `file`, otherwise null 99 Content *string `json:"content"` 100 // `target` is populated when `type` is `symlink`, otherwise null 101 Target *string `json:"target"` 102 URL *string `json:"url"` 103 HTMLURL *string `json:"html_url"` 104 GitURL *string `json:"git_url"` 105 DownloadURL *string `json:"download_url"` 106 // `submodule_git_url` is populated when `type` is `submodule`, otherwise null 107 SubmoduleGitURL *string `json:"submodule_git_url"` 108 Links *FileLinksResponse `json:"_links"` 109 } 110 111 // FileCommitResponse contains information generated from a Git commit for a repo's file. 112 type FileCommitResponse struct { 113 CommitMeta 114 HTMLURL string `json:"html_url"` 115 Author *CommitUser `json:"author"` 116 Committer *CommitUser `json:"committer"` 117 Parents []*CommitMeta `json:"parents"` 118 Message string `json:"message"` 119 Tree *CommitMeta `json:"tree"` 120 } 121 122 // FileResponse contains information about a repo's file 123 type FileResponse struct { 124 Content *ContentsResponse `json:"content"` 125 Commit *FileCommitResponse `json:"commit"` 126 Verification *PayloadCommitVerification `json:"verification"` 127 } 128 129 // FileDeleteResponse contains information about a repo's file that was deleted 130 type FileDeleteResponse struct { 131 Content interface{} `json:"content"` // to be set to nil 132 Commit *FileCommitResponse `json:"commit"` 133 Verification *PayloadCommitVerification `json:"verification"` 134 }