-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
changes_edit.go
232 lines (197 loc) · 8.77 KB
/
changes_edit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package gerrit
import (
"context"
"fmt"
"net/url"
)
// EditInfo entity contains information about a change edit.
type EditInfo struct {
Commit CommitInfo `json:"commit"`
BaseRevision string `json:"baseRevision"`
Fetch map[string]FetchInfo `json:"fetch"`
Files map[string]FileInfo `json:"files,omitempty"`
}
// EditFileInfo entity contains additional information of a file within a change edit.
type EditFileInfo struct {
WebLinks []WebLinkInfo `json:"web_links,omitempty"`
}
// ChangeEditDetailOptions specifies the parameters to the ChangesService.GetChangeEditDetails.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-edit-detail
type ChangeEditDetailOptions struct {
// When request parameter list is provided the response also includes the file list.
List bool `url:"list,omitempty"`
// When base request parameter is provided the file list is computed against this base revision.
Base bool `url:"base,omitempty"`
// When request parameter download-commands is provided fetch info map is also included.
DownloadCommands bool `url:"download-commands,omitempty"`
}
// GetChangeEditDetails retrieves a change edit details.
// As response an EditInfo entity is returned that describes the change edit, or “204 No Content” when change edit doesn’t exist for this change.
// Change edits are stored on special branches and there can be max one edit per user per change.
// Edits aren’t tracked in the database.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-edit-detail
func (s *ChangesService) GetChangeEditDetails(ctx context.Context, changeID string, opt *ChangeEditDetailOptions) (*EditInfo, *Response, error) {
u := fmt.Sprintf("changes/%s/edit", changeID)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
v := new(EditInfo)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// RetrieveMetaDataOfAFileFromChangeEdit retrieves meta data of a file from a change edit.
// Currently only web links are returned.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-edit-meta-data
func (s *ChangesService) RetrieveMetaDataOfAFileFromChangeEdit(ctx context.Context, changeID, filePath string) (*EditFileInfo, *Response, error) {
u := fmt.Sprintf("changes/%s/edit/%s/meta", changeID, filePath)
req, err := s.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
v := new(EditFileInfo)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// RetrieveCommitMessageFromChangeEdit retrieves commit message from change edit.
// The commit message is returned as base64 encoded string.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-edit-message
func (s *ChangesService) RetrieveCommitMessageFromChangeEdit(ctx context.Context, changeID string) (string, *Response, error) {
u := fmt.Sprintf("changes/%s/edit:message", changeID)
return getStringResponseWithoutOptions(ctx, s.client, u)
}
// ChangeFileContentInChangeEdit put content of a file to a change edit.
//
// When change edit doesn’t exist for this change yet it is created.
// When file content isn’t provided, it is wiped out for that file.
// As response “204 No Content” is returned.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#put-edit-file
func (s *ChangesService) ChangeFileContentInChangeEdit(ctx context.Context, changeID, filePath, content string) (*Response, error) {
u := fmt.Sprintf("changes/%s/edit/%s", changeID, url.QueryEscape(filePath))
req, err := s.client.NewRawPutRequest(ctx, u, content)
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.
//
// If a change edit doesn’t exist for this change yet, it is created.
// As response “204 No Content” is returned.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#put-change-edit-message
func (s *ChangesService) ChangeCommitMessageInChangeEdit(ctx context.Context, changeID string, input *ChangeEditMessageInput) (*Response, error) {
u := fmt.Sprintf("changes/%s/edit:message", changeID)
req, err := s.client.NewRequest(ctx, "PUT", u, input)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// DeleteFileInChangeEdit deletes a file from a change edit.
// This deletes the file from the repository completely.
// This is not the same as reverting or restoring a file to its previous contents.
//
// When change edit doesn’t exist for this change yet it is created.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#delete-edit-file
func (s *ChangesService) DeleteFileInChangeEdit(ctx context.Context, changeID, filePath string) (*Response, error) {
u := fmt.Sprintf("changes/%s/edit/%s", changeID, filePath)
return s.client.DeleteRequest(ctx, u, nil)
}
// DeleteChangeEdit deletes change edit.
//
// As response “204 No Content” is returned.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#delete-edit
func (s *ChangesService) DeleteChangeEdit(ctx context.Context, changeID string) (*Response, error) {
u := fmt.Sprintf("changes/%s/edit", changeID)
return s.client.DeleteRequest(ctx, u, nil)
}
// PublishChangeEdit promotes change edit to a regular patch set.
//
// As response “204 No Content” is returned.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#publish-edit
func (s *ChangesService) PublishChangeEdit(ctx context.Context, changeID, notify string) (*Response, error) {
u := fmt.Sprintf("changes/%s/edit:publish", changeID)
req, err := s.client.NewRequest(ctx, "POST", u, map[string]string{
"notify": notify,
})
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// RebaseChangeEdit rebases change edit on top of latest patch set.
//
// When change was rebased on top of latest patch set, response “204 No Content” is returned.
// When change edit is already based on top of the latest patch set, the response “409 Conflict” is returned.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#rebase-edit
func (s *ChangesService) RebaseChangeEdit(ctx context.Context, changeID string) (*Response, error) {
u := fmt.Sprintf("changes/%s/edit:rebase", changeID)
req, err := s.client.NewRequest(ctx, "POST", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// RetrieveFileContentFromChangeEdit retrieves content of a file from a change edit.
//
// The content of the file is returned as text encoded inside base64.
// The Content-Type header will always be text/plain reflecting the outer base64 encoding.
// A Gerrit-specific X-FYI-Content-Type header can be examined to find the server detected content type of the file.
//
// When the specified file was deleted in the change edit “204 No Content” is returned.
// If only the content type is required, callers should use HEAD to avoid downloading the encoded file contents.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-edit-file
func (s *ChangesService) RetrieveFileContentFromChangeEdit(ctx context.Context, changeID, filePath string) (*string, *Response, error) {
u := fmt.Sprintf("changes/%s/edit/%s", changeID, filePath)
req, err := s.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
v := new(string)
resp, err := s.client.Do(req, v)
if err != nil {
return nil, resp, err
}
return v, resp, err
}
// RetrieveFileContentTypeFromChangeEdit retrieves content type of a file from a change edit.
// This is nearly the same as RetrieveFileContentFromChangeEdit.
// But if only the content type is required, callers should use HEAD to avoid downloading the encoded file contents.
//
// For further documentation please have a look at RetrieveFileContentFromChangeEdit.
//
// Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-edit-file
func (s *ChangesService) RetrieveFileContentTypeFromChangeEdit(ctx context.Context, changeID, filePath string) (*Response, error) {
u := fmt.Sprintf("changes/%s/edit/%s", changeID, filePath)
req, err := s.client.NewRequest(ctx, "HEAD", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
/*
Missing Change Edit Endpoints
Restore file content or rename files in Change Edit
*/