Skip to content

Commit 6e555c5

Browse files
authored
add ability to delete files (#270)
1 parent 1849ed5 commit 6e555c5

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

bitbucket.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,15 @@ type File struct {
198198

199199
// Based on https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/src#post
200200
type RepositoryBlobWriteOptions struct {
201-
Owner string `json:"owner"`
202-
RepoSlug string `json:"repo_slug"`
203-
FilePath string `json:"filepath"`
204-
FileName string `json:"filename"`
205-
Files []File `json:"files"`
206-
Author string `json:"author"`
207-
Message string `json:"message"`
208-
Branch string `json:"branch"`
201+
Owner string `json:"owner"`
202+
RepoSlug string `json:"repo_slug"`
203+
FilePath string `json:"filepath"`
204+
FileName string `json:"filename"`
205+
Files []File `json:"files"`
206+
FilesToDelete []string `json:"files_to_delete"`
207+
Author string `json:"author"`
208+
Message string `json:"message"`
209+
Branch string `json:"branch"`
209210
}
210211

211212
// RepositoryRefOptions represents the options for describing a repository's refs (i.e.

client.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func (c *Client) executePaginated(method string, urlStr string, text string, pag
279279
return result, nil
280280
}
281281

282-
func (c *Client) executeFileUpload(method string, urlStr string, files []File, params map[string]string) (interface{}, error) {
282+
func (c *Client) executeFileUpload(method string, urlStr string, files []File, filesToDelete []string, params map[string]string) (interface{}, error) {
283283
// Prepare a form that you will submit to that URL.
284284
var b bytes.Buffer
285285
w := multipart.NewWriter(&b)
@@ -308,6 +308,13 @@ func (c *Client) executeFileUpload(method string, urlStr string, files []File, p
308308
}
309309
}
310310

311+
for _, filename := range filesToDelete {
312+
err := w.WriteField("files", filename)
313+
if err != nil {
314+
return nil, err
315+
}
316+
}
317+
311318
// Don't forget to close the multipart writer.
312319
// If you don't close it, your request will be missing the terminating boundary.
313320
w.Close()

downloads.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (dl *Downloads) Create(do *DownloadsOptions) (interface{}, error) {
1818
Name: do.FileName,
1919
}}
2020
}
21-
return dl.c.executeFileUpload("POST", urlStr, do.Files, make(map[string]string))
21+
return dl.c.executeFileUpload("POST", urlStr, do.Files, []string{}, make(map[string]string))
2222
}
2323

2424
func (dl *Downloads) List(do *DownloadsOptions) (interface{}, error) {

repository.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func (r *Repository) WriteFileBlob(ro *RepositoryBlobWriteOptions) error {
399399

400400
urlStr := r.c.requestUrl("/repositories/%s/%s/src", ro.Owner, ro.RepoSlug)
401401

402-
_, err := r.c.executeFileUpload("POST", urlStr, ro.Files, m)
402+
_, err := r.c.executeFileUpload("POST", urlStr, ro.Files, ro.FilesToDelete, m)
403403
return err
404404
}
405405

0 commit comments

Comments
 (0)