API endpoint for changing/creating/deleting multiple files (#24887)
This PR creates an API endpoint for creating/updating/deleting multiple files in one API call similar to the solution provided by [GitLab](https://docs.gitlab.com/ee/api/commits.html#create-a-commit-with-multiple-files-and-actions). To archive this, the CreateOrUpdateRepoFile and DeleteRepoFIle functions in files service are unified into one function supporting multiple files and actions. Resolves #14619
This commit is contained in:
parent
245f2c08db
commit
275d4b7e3f
16 changed files with 1309 additions and 778 deletions
|
@ -64,6 +64,35 @@ func (o *UpdateFileOptions) Branch() string {
|
|||
return o.FileOptions.BranchName
|
||||
}
|
||||
|
||||
// ChangeFileOperation for creating, updating or deleting a file
|
||||
type ChangeFileOperation struct {
|
||||
// indicates what to do with the file
|
||||
// required: true
|
||||
// enum: create,update,delete
|
||||
Operation string `json:"operation" binding:"Required"`
|
||||
// path to the existing or new file
|
||||
Path string `json:"path" binding:"MaxSize(500)"`
|
||||
// content must be base64 encoded
|
||||
// required: true
|
||||
Content string `json:"content"`
|
||||
// sha is the SHA for the file that already exists, required for update, delete
|
||||
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
|
||||
Files []*ChangeFileOperation `json:"files"`
|
||||
}
|
||||
|
||||
// Branch returns branch name
|
||||
func (o *ChangeFilesOptions) Branch() string {
|
||||
return o.FileOptions.BranchName
|
||||
}
|
||||
|
||||
// FileOptionInterface provides a unified interface for the different file options
|
||||
type FileOptionInterface interface {
|
||||
Branch() string
|
||||
|
@ -126,6 +155,13 @@ type FileResponse struct {
|
|||
Verification *PayloadCommitVerification `json:"verification"`
|
||||
}
|
||||
|
||||
// FilesResponse contains information about multiple files from a repo
|
||||
type FilesResponse struct {
|
||||
Files []*ContentsResponse `json:"files"`
|
||||
Commit *FileCommitResponse `json:"commit"`
|
||||
Verification *PayloadCommitVerification `json:"verification"`
|
||||
}
|
||||
|
||||
// FileDeleteResponse contains information about a repo's file that was deleted
|
||||
type FileDeleteResponse struct {
|
||||
Content interface{} `json:"content"` // to be set to nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue