@@ -22,6 +22,23 @@ type FileOptions struct {
2222 Signoff bool `json:"signoff"`
2323}
2424
25+ type FileOptionsWithSHA struct {
26+ FileOptions
27+ // the blob ID (SHA) for the file that already exists, it is required for changing existing files
28+ // required: true
29+ SHA string `json:"sha" binding:"Required"`
30+ }
31+
32+ func (f * FileOptions ) GetFileOptions () * FileOptions {
33+ return f
34+ }
35+
36+ type FileOptionsInterface interface {
37+ GetFileOptions () * FileOptions
38+ }
39+
40+ var _ FileOptionsInterface = (* FileOptions )(nil )
41+
2542// CreateFileOptions options for creating files
2643// 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)
2744type CreateFileOptions struct {
@@ -31,55 +48,38 @@ type CreateFileOptions struct {
3148 ContentBase64 string `json:"content"`
3249}
3350
34- // Branch returns branch name
35- func (o * CreateFileOptions ) Branch () string {
36- return o .FileOptions .BranchName
37- }
38-
3951// DeleteFileOptions options for deleting files (used for other File structs below)
4052// 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)
4153type DeleteFileOptions struct {
42- FileOptions
43- // sha is the SHA for the file that already exists
44- // required: true
45- SHA string `json:"sha" binding:"Required"`
46- }
47-
48- // Branch returns branch name
49- func (o * DeleteFileOptions ) Branch () string {
50- return o .FileOptions .BranchName
54+ FileOptionsWithSHA
5155}
5256
5357// UpdateFileOptions options for updating files
5458// 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)
5559type UpdateFileOptions struct {
56- DeleteFileOptions
60+ FileOptionsWithSHA
5761 // content must be base64 encoded
5862 // required: true
5963 ContentBase64 string `json:"content"`
6064 // from_path (optional) is the path of the original file which will be moved/renamed to the path in the URL
6165 FromPath string `json:"from_path" binding:"MaxSize(500)"`
6266}
6367
64- // Branch returns branch name
65- func (o * UpdateFileOptions ) Branch () string {
66- return o .FileOptions .BranchName
67- }
68-
69- // FIXME: ChangeFileOperation.SHA is NOT required for update or delete if last commit is provided in the options.
68+ // FIXME: there is no LastCommitID in FileOptions, actually it should be an alternative to the SHA in ChangeFileOperation
7069
7170// ChangeFileOperation for creating, updating or deleting a file
7271type ChangeFileOperation struct {
73- // indicates what to do with the file
72+ // indicates what to do with the file: "create" for creating a new file, "update" for updating an existing file,
73+ // "upload" for creating or updating a file, "rename" for renaming a file, and "delete" for deleting an existing file.
7474 // required: true
75- // enum: create,update,delete
75+ // enum: create,update,upload,rename, delete
7676 Operation string `json:"operation" binding:"Required"`
7777 // path to the existing or new file
7878 // required: true
7979 Path string `json:"path" binding:"Required;MaxSize(500)"`
80- // new or updated file content, must be base64 encoded
80+ // new or updated file content, it must be base64 encoded
8181 ContentBase64 string `json:"content"`
82- // sha is the SHA for the file that already exists, required for update or delete
82+ // the blob ID ( SHA) for the file that already exists, required for changing existing files
8383 SHA string `json:"sha"`
8484 // old path of the file to move
8585 FromPath string `json:"from_path"`
@@ -94,20 +94,10 @@ type ChangeFilesOptions struct {
9494 Files []* ChangeFileOperation `json:"files" binding:"Required"`
9595}
9696
97- // Branch returns branch name
98- func (o * ChangeFilesOptions ) Branch () string {
99- return o .FileOptions .BranchName
100- }
101-
102- // FileOptionInterface provides a unified interface for the different file options
103- type FileOptionInterface interface {
104- Branch () string
105- }
106-
10797// ApplyDiffPatchFileOptions options for applying a diff patch
10898// 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)
10999type ApplyDiffPatchFileOptions struct {
110- DeleteFileOptions
100+ FileOptions
111101 // required: true
112102 Content string `json:"content"`
113103}
0 commit comments