Commit 39ce5fd6 authored by Sander van Harmelen's avatar Sander van Harmelen Committed by GitHub

When deleting a repository file, the API returns a 204 (#201)

So no content is given, which is in contrast with the API docs and makes this a backwards incompatible change.
parent 55af103d
package main package main
import ( import (
"encoding/base64"
"log" "log"
"github.com/xanzy/go-gitlab" "github.com/xanzy/go-gitlab"
...@@ -13,7 +12,6 @@ func repositoryFileExample() { ...@@ -13,7 +12,6 @@ func repositoryFileExample() {
// Create a new repository file // Create a new repository file
cf := &gitlab.CreateFileOptions{ cf := &gitlab.CreateFileOptions{
Branch: gitlab.String("master"), Branch: gitlab.String("master"),
Encoding: gitlab.String("text"),
Content: gitlab.String("My file contents"), Content: gitlab.String("My file contents"),
CommitMessage: gitlab.String("Adding a test file"), CommitMessage: gitlab.String("Adding a test file"),
} }
...@@ -25,7 +23,6 @@ func repositoryFileExample() { ...@@ -25,7 +23,6 @@ func repositoryFileExample() {
// Update a repository file // Update a repository file
uf := &gitlab.UpdateFileOptions{ uf := &gitlab.UpdateFileOptions{
Branch: gitlab.String("master"), Branch: gitlab.String("master"),
Encoding: gitlab.String("text"),
Content: gitlab.String("My file content"), Content: gitlab.String("My file content"),
CommitMessage: gitlab.String("Fixing typo"), CommitMessage: gitlab.String("Fixing typo"),
} }
...@@ -42,14 +39,5 @@ func repositoryFileExample() { ...@@ -42,14 +39,5 @@ func repositoryFileExample() {
log.Fatal(err) log.Fatal(err)
} }
if f.Encoding == "base64" {
content, err := base64.StdEncoding.DecodeString(f.Content)
if err != nil {
log.Fatal(err)
}
log.Printf("File contains: %s", string(content))
} else {
log.Printf("File contains: %s", f.Content) log.Printf("File contains: %s", f.Content)
}
} }
...@@ -218,23 +218,17 @@ type DeleteFileOptions struct { ...@@ -218,23 +218,17 @@ type DeleteFileOptions struct {
// //
// GitLab API docs: // GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#delete-existing-file-in-repository // https://docs.gitlab.com/ce/api/repository_files.html#delete-existing-file-in-repository
func (s *RepositoryFilesService) DeleteFile(pid interface{}, fileName string, opt *DeleteFileOptions, options ...OptionFunc) (*FileInfo, *Response, error) { func (s *RepositoryFilesService) DeleteFile(pid interface{}, fileName string, opt *DeleteFileOptions, options ...OptionFunc) (*Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
u := fmt.Sprintf("projects/%s/repository/files/%s", url.QueryEscape(project), url.QueryEscape(fileName)) u := fmt.Sprintf("projects/%s/repository/files/%s", url.QueryEscape(project), url.QueryEscape(fileName))
req, err := s.client.NewRequest("DELETE", u, opt, options) req, err := s.client.NewRequest("DELETE", u, opt, options)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
f := new(FileInfo) return s.client.Do(req, nil)
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, err
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment