2016-11-07 13:53:13 +00:00
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
2019-03-22 15:38:49 +00:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2016-11-07 13:53:13 +00:00
|
|
|
|
2019-05-11 10:21:34 +00:00
|
|
|
package structs
|
2019-03-22 15:38:49 +00:00
|
|
|
|
|
|
|
// FileOptions options for all file APIs
|
|
|
|
type FileOptions struct {
|
2019-05-30 17:57:55 +00:00
|
|
|
// message (optional) for the commit of this file. if not supplied, a default message will be used
|
2019-06-29 15:19:24 +00:00
|
|
|
Message string `json:"message"`
|
2019-05-30 17:57:55 +00:00
|
|
|
// branch (optional) to base this file from. if not given, the default branch is used
|
2019-08-05 20:39:39 +00:00
|
|
|
BranchName string `json:"branch" binding:"GitRefName;MaxSize(100)"`
|
2019-05-30 17:57:55 +00:00
|
|
|
// new_branch (optional) will make a new branch from `branch` before creating the file
|
2019-08-05 20:39:39 +00:00
|
|
|
NewBranchName string `json:"new_branch" binding:"GitRefName;MaxSize(100)"`
|
2019-05-30 17:57:55 +00:00
|
|
|
// `author` and `committer` are optional (if only one is given, it will be used for the other, otherwise the authenticated user will be used)
|
2019-12-24 02:33:52 +00:00
|
|
|
Author Identity `json:"author"`
|
|
|
|
Committer Identity `json:"committer"`
|
|
|
|
Dates CommitDateOptions `json:"dates"`
|
2021-01-29 08:57:45 +00:00
|
|
|
// Add a Signed-off-by trailer by the committer at the end of the commit log message.
|
|
|
|
Signoff bool `json:"signoff"`
|
2019-03-22 15:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateFileOptions options for creating files
|
2019-05-30 17:57:55 +00:00
|
|
|
// 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)
|
2019-03-22 15:38:49 +00:00
|
|
|
type CreateFileOptions struct {
|
|
|
|
FileOptions
|
2019-05-30 17:57:55 +00:00
|
|
|
// content must be base64 encoded
|
|
|
|
// required: true
|
2023-07-18 18:14:47 +00:00
|
|
|
ContentBase64 string `json:"content"`
|
2019-03-22 15:38:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-28 15:45:33 +00:00
|
|
|
// Branch returns branch name
|
|
|
|
func (o *CreateFileOptions) Branch() string {
|
|
|
|
return o.FileOptions.BranchName
|
|
|
|
}
|
|
|
|
|
2019-03-22 15:38:49 +00:00
|
|
|
// DeleteFileOptions options for deleting files (used for other File structs below)
|
2019-05-30 17:57:55 +00:00
|
|
|
// 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)
|
2019-03-22 15:38:49 +00:00
|
|
|
type DeleteFileOptions struct {
|
|
|
|
FileOptions
|
2019-05-30 17:57:55 +00:00
|
|
|
// sha is the SHA for the file that already exists
|
|
|
|
// required: true
|
2019-03-22 15:38:49 +00:00
|
|
|
SHA string `json:"sha" binding:"Required"`
|
|
|
|
}
|
|
|
|
|
2022-04-28 15:45:33 +00:00
|
|
|
// Branch returns branch name
|
|
|
|
func (o *DeleteFileOptions) Branch() string {
|
|
|
|
return o.FileOptions.BranchName
|
|
|
|
}
|
|
|
|
|
2019-03-22 15:38:49 +00:00
|
|
|
// UpdateFileOptions options for updating files
|
2019-05-30 17:57:55 +00:00
|
|
|
// 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)
|
2019-03-22 15:38:49 +00:00
|
|
|
type UpdateFileOptions struct {
|
|
|
|
DeleteFileOptions
|
2019-05-30 17:57:55 +00:00
|
|
|
// content must be base64 encoded
|
|
|
|
// required: true
|
2023-07-18 18:14:47 +00:00
|
|
|
ContentBase64 string `json:"content"`
|
2019-05-30 17:57:55 +00:00
|
|
|
// from_path (optional) is the path of the original file which will be moved/renamed to the path in the URL
|
2019-03-22 15:38:49 +00:00
|
|
|
FromPath string `json:"from_path" binding:"MaxSize(500)"`
|
|
|
|
}
|
|
|
|
|
2022-04-28 15:45:33 +00:00
|
|
|
// Branch returns branch name
|
|
|
|
func (o *UpdateFileOptions) Branch() string {
|
|
|
|
return o.FileOptions.BranchName
|
|
|
|
}
|
|
|
|
|
2023-05-29 09:41:35 +00:00
|
|
|
// ChangeFileOperation for creating, updating or deleting a file
|
|
|
|
type ChangeFileOperation struct {
|
|
|
|
// indicates what to do with the file
|
|
|
|
// required: true
|
2024-08-09 21:36:03 +00:00
|
|
|
// enum: ["create", "update", "delete"]
|
2023-05-29 09:41:35 +00:00
|
|
|
Operation string `json:"operation" binding:"Required"`
|
|
|
|
// path to the existing or new file
|
|
|
|
// required: true
|
2023-06-07 15:49:58 +00:00
|
|
|
Path string `json:"path" binding:"Required;MaxSize(500)"`
|
|
|
|
// new or updated file content, must be base64 encoded
|
2023-07-18 18:14:47 +00:00
|
|
|
ContentBase64 string `json:"content"`
|
2023-06-07 15:49:58 +00:00
|
|
|
// sha is the SHA for the file that already exists, required for update or delete
|
2023-05-29 09:41:35 +00:00
|
|
|
SHA string `json:"sha"`
|
|
|
|
// old path of the file to move
|
|
|
|
FromPath string `json:"from_path"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ChangeFilesOptions options for creating, updating or deleting multiple files
|
|
|
|
// 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)
|
|
|
|
type ChangeFilesOptions struct {
|
|
|
|
FileOptions
|
2023-06-07 15:49:58 +00:00
|
|
|
// list of file operations
|
|
|
|
// required: true
|
|
|
|
Files []*ChangeFileOperation `json:"files" binding:"Required"`
|
2023-05-29 09:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Branch returns branch name
|
|
|
|
func (o *ChangeFilesOptions) Branch() string {
|
|
|
|
return o.FileOptions.BranchName
|
|
|
|
}
|
|
|
|
|
2022-04-28 15:45:33 +00:00
|
|
|
// FileOptionInterface provides a unified interface for the different file options
|
|
|
|
type FileOptionInterface interface {
|
|
|
|
Branch() string
|
|
|
|
}
|
|
|
|
|
2022-02-09 20:28:55 +00:00
|
|
|
// ApplyDiffPatchFileOptions options for applying a diff patch
|
|
|
|
// 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)
|
|
|
|
type ApplyDiffPatchFileOptions struct {
|
|
|
|
DeleteFileOptions
|
|
|
|
// required: true
|
|
|
|
Content string `json:"content"`
|
|
|
|
}
|
|
|
|
|
2019-03-22 15:38:49 +00:00
|
|
|
// FileLinksResponse contains the links for a repo's file
|
|
|
|
type FileLinksResponse struct {
|
2019-06-29 20:51:10 +00:00
|
|
|
Self *string `json:"self"`
|
|
|
|
GitURL *string `json:"git"`
|
|
|
|
HTMLURL *string `json:"html"`
|
2019-03-22 15:38:49 +00:00
|
|
|
}
|
|
|
|
|
2019-06-29 20:51:10 +00:00
|
|
|
// ContentsResponse contains information about a repo's entry's (dir, file, symlink, submodule) metadata and content
|
|
|
|
type ContentsResponse struct {
|
2022-07-30 08:09:04 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Path string `json:"path"`
|
|
|
|
SHA string `json:"sha"`
|
|
|
|
LastCommitSHA string `json:"last_commit_sha"`
|
2019-06-29 20:51:10 +00:00
|
|
|
// `type` will be `file`, `dir`, `symlink`, or `submodule`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Size int64 `json:"size"`
|
|
|
|
// `encoding` is populated when `type` is `file`, otherwise null
|
|
|
|
Encoding *string `json:"encoding"`
|
|
|
|
// `content` is populated when `type` is `file`, otherwise null
|
|
|
|
Content *string `json:"content"`
|
|
|
|
// `target` is populated when `type` is `symlink`, otherwise null
|
|
|
|
Target *string `json:"target"`
|
|
|
|
URL *string `json:"url"`
|
|
|
|
HTMLURL *string `json:"html_url"`
|
|
|
|
GitURL *string `json:"git_url"`
|
|
|
|
DownloadURL *string `json:"download_url"`
|
|
|
|
// `submodule_git_url` is populated when `type` is `submodule`, otherwise null
|
|
|
|
SubmoduleGitURL *string `json:"submodule_git_url"`
|
|
|
|
Links *FileLinksResponse `json:"_links"`
|
2019-03-22 15:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FileCommitResponse contains information generated from a Git commit for a repo's file.
|
|
|
|
type FileCommitResponse struct {
|
|
|
|
CommitMeta
|
|
|
|
HTMLURL string `json:"html_url"`
|
|
|
|
Author *CommitUser `json:"author"`
|
|
|
|
Committer *CommitUser `json:"committer"`
|
|
|
|
Parents []*CommitMeta `json:"parents"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
Tree *CommitMeta `json:"tree"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// FileResponse contains information about a repo's file
|
|
|
|
type FileResponse struct {
|
2019-06-29 20:51:10 +00:00
|
|
|
Content *ContentsResponse `json:"content"`
|
2019-03-22 15:38:49 +00:00
|
|
|
Commit *FileCommitResponse `json:"commit"`
|
|
|
|
Verification *PayloadCommitVerification `json:"verification"`
|
|
|
|
}
|
|
|
|
|
2023-05-29 09:41:35 +00:00
|
|
|
// FilesResponse contains information about multiple files from a repo
|
|
|
|
type FilesResponse struct {
|
|
|
|
Files []*ContentsResponse `json:"files"`
|
|
|
|
Commit *FileCommitResponse `json:"commit"`
|
|
|
|
Verification *PayloadCommitVerification `json:"verification"`
|
|
|
|
}
|
|
|
|
|
2019-03-22 15:38:49 +00:00
|
|
|
// FileDeleteResponse contains information about a repo's file that was deleted
|
|
|
|
type FileDeleteResponse struct {
|
2023-07-04 18:36:08 +00:00
|
|
|
Content any `json:"content"` // to be set to nil
|
2019-03-22 15:38:49 +00:00
|
|
|
Commit *FileCommitResponse `json:"commit"`
|
|
|
|
Verification *PayloadCommitVerification `json:"verification"`
|
|
|
|
}
|