From 3c36bd251b04592528592638606f0580f127893f Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Thu, 21 May 2020 10:13:32 +0000 Subject: [PATCH] Copy DeleteFileOptions struct fields into UpdateFileOptions struct (#330) --- gitea/pull_test.go | 12 +++++------- gitea/repo_branch_test.go | 12 +++++------- gitea/repo_file.go | 5 ++++- gitea/repo_file_test.go | 8 +++----- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/gitea/pull_test.go b/gitea/pull_test.go index 1ce7dec..ff3f3c8 100644 --- a/gitea/pull_test.go +++ b/gitea/pull_test.go @@ -134,14 +134,12 @@ func preparePullTest(t *testing.T, c *Client, repoName, forkOrg string) bool { } updatedFile, err := c.UpdateFile(forkRepo.Owner.UserName, forkRepo.Name, "LICENSE", UpdateFileOptions{ - DeleteFileOptions: DeleteFileOptions{ - FileOptions: FileOptions{ - Message: "Overwrite", - BranchName: "master", - NewBranchName: "overwrite_licence", - }, - SHA: masterLicence.SHA, + FileOptions: FileOptions{ + Message: "Overwrite", + BranchName: "master", + NewBranchName: "overwrite_licence", }, + SHA: masterLicence.SHA, Content: "Tk9USElORyBJUyBIRVJFIEFOWU1PUkUKSUYgWU9VIExJS0UgVE8gRklORCBTT01FVEhJTkcKV0FJVCBGT1IgVEhFIEZVVFVSRQo=", }) if !assert.NoError(t, err) || !assert.NotNil(t, updatedFile) { diff --git a/gitea/repo_branch_test.go b/gitea/repo_branch_test.go index 74d50f1..f39cae0 100644 --- a/gitea/repo_branch_test.go +++ b/gitea/repo_branch_test.go @@ -61,14 +61,12 @@ func prepareBranchTest(t *testing.T, c *Client, repoName string) *Repository { } updatedFile, err := c.UpdateFile(origRepo.Owner.UserName, origRepo.Name, "README.md", UpdateFileOptions{ - DeleteFileOptions: DeleteFileOptions{ - FileOptions: FileOptions{ - Message: "update it", - BranchName: "master", - NewBranchName: "update", - }, - SHA: masterLicence.SHA, + FileOptions: FileOptions{ + Message: "update it", + BranchName: "master", + NewBranchName: "update", }, + SHA: masterLicence.SHA, Content: "Tk9USElORyBJUyBIRVJFIEFOWU1PUkUKSUYgWU9VIExJS0UgVE8gRklORCBTT01FVEhJTkcKV0FJVCBGT1IgVEhFIEZVVFVSRQo=", }) if !assert.NoError(t, err) || !assert.NotNil(t, updatedFile) { diff --git a/gitea/repo_file.go b/gitea/repo_file.go index f96cb00..3ef6fa5 100644 --- a/gitea/repo_file.go +++ b/gitea/repo_file.go @@ -46,7 +46,10 @@ type DeleteFileOptions struct { // UpdateFileOptions options for updating 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 UpdateFileOptions struct { - DeleteFileOptions + FileOptions + // sha is the SHA for the file that already exists + // required: true + SHA string `json:"sha"` // content must be base64 encoded // required: true Content string `json:"content"` diff --git a/gitea/repo_file_test.go b/gitea/repo_file_test.go index abd5255..0421946 100644 --- a/gitea/repo_file_test.go +++ b/gitea/repo_file_test.go @@ -35,12 +35,10 @@ func TestFileCreateUpdateGet(t *testing.T) { assert.EqualValues(t, "ZmlsZUEK", base64.StdEncoding.EncodeToString(raw)) updatedFile, err := c.UpdateFile(repo.Owner.UserName, repo.Name, "A", UpdateFileOptions{ - DeleteFileOptions: DeleteFileOptions{ - FileOptions: FileOptions{ - Message: "add a new line", - }, - SHA: newFile.Content.SHA, + FileOptions: FileOptions{ + Message: "add a new line", }, + SHA: newFile.Content.SHA, Content: "ZmlsZUEKCmFuZCBhIG5ldyBsaW5lCg==", }) assert.NoError(t, err)