Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions changes_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package gerrit

import (
"context"
"encoding/base64"
"fmt"
"net/http"
"net/url"
)

Expand Down Expand Up @@ -107,6 +109,28 @@ func (s *ChangesService) ChangeFileContentInChangeEdit(ctx context.Context, chan
return s.client.Do(req, nil)
}

func (s *ChangesService) ChangeFileContentInChangeEditNew(ctx context.Context, changeID, filePath string, content []byte, fileMode *int) (*Response, error) {
u := fmt.Sprintf("changes/%s/edit/%s", changeID, url.QueryEscape(filePath))

payload := struct {
Data string `json:"binary_content"`
FileMode int `json:"file_mode,omitempty"` // FileMode is optional
}{
Data: "data:text/plain;base64," + base64.StdEncoding.EncodeToString(content),
}

if fileMode != nil {
payload.FileMode = *fileMode
}

req, err := s.client.NewRequest(ctx, http.MethodPut, u, payload)
if err != nil {
return nil, err
}

return s.client.Do(req, nil)
}

// ChangeCommitMessageInChangeEdit modify commit message.
// The request body needs to include a ChangeEditMessageInput entity.
//
Expand Down