@@ -20,8 +20,20 @@ type FileOptions struct {
2020 Dates CommitDateOptions `json:"dates"`
2121 // Add a Signed-off-by trailer by the committer at the end of the commit log message.
2222 Signoff bool `json:"signoff"`
23+ // sha is the SHA for the file that already exists
24+ SHA string `json:"sha"`
25+ }
26+
27+ func (f * FileOptions ) GetFileOptions () * FileOptions {
28+ return f
29+ }
30+
31+ type FileOptionsInterface interface {
32+ GetFileOptions () * FileOptions
2333}
2434
35+ var _ FileOptionsInterface = (* FileOptions )(nil )
36+
2537// CreateFileOptions options for creating files
2638// 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)
2739type CreateFileOptions struct {
@@ -31,55 +43,38 @@ type CreateFileOptions struct {
3143 ContentBase64 string `json:"content"`
3244}
3345
34- // Branch returns branch name
35- func (o * CreateFileOptions ) Branch () string {
36- return o .FileOptions .BranchName
37- }
38-
3946// DeleteFileOptions options for deleting files (used for other File structs below)
4047// 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)
4148type DeleteFileOptions struct {
4249 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
5150}
5251
5352// UpdateFileOptions options for updating files
5453// 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)
5554type UpdateFileOptions struct {
56- DeleteFileOptions
55+ FileOptions
5756 // content must be base64 encoded
5857 // required: true
5958 ContentBase64 string `json:"content"`
6059 // from_path (optional) is the path of the original file which will be moved/renamed to the path in the URL
6160 FromPath string `json:"from_path" binding:"MaxSize(500)"`
6261}
6362
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.
63+ // FIXME: there is no LastCommitID in FileOptions, actually it should be an alternative to the SHA in ChangeFileOperation
7064
7165// ChangeFileOperation for creating, updating or deleting a file
7266type ChangeFileOperation struct {
73- // indicates what to do with the file
67+ // indicates what to do with the file: "create" for creating a new file, "update" for updating an existing file,
68+ // "upload" for creating or updating a file, "rename" for renaming a file, and "delete" for deleting an existing file.
7469 // required: true
75- // enum: create,update,delete
70+ // enum: create,update,upload,rename, delete
7671 Operation string `json:"operation" binding:"Required"`
7772 // path to the existing or new file
7873 // required: true
7974 Path string `json:"path" binding:"Required;MaxSize(500)"`
80- // new or updated file content, must be base64 encoded
75+ // new or updated file content, it must be base64 encoded
8176 ContentBase64 string `json:"content"`
82- // sha is the SHA for the file that already exists, required for update or delete
77+ // sha is the SHA for the file that already exists, required for changing existing files
8378 SHA string `json:"sha"`
8479 // old path of the file to move
8580 FromPath string `json:"from_path"`
@@ -94,20 +89,10 @@ type ChangeFilesOptions struct {
9489 Files []* ChangeFileOperation `json:"files" binding:"Required"`
9590}
9691
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-
10792// ApplyDiffPatchFileOptions options for applying a diff patch
10893// 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)
10994type ApplyDiffPatchFileOptions struct {
110- DeleteFileOptions
95+ FileOptions
11196 // required: true
11297 Content string `json:"content"`
11398}
0 commit comments