Repository: xanzy/go-gitlab
Pull request #1522 (2022-08-09 16:28:04)

Add DeletePackageFile in PackagesService
Add DeletePackageFile function in PackagesService.

Here is the [Gitlab API documentation](https://docs.gitlab.com/ee/api/packages.html#delete-a-package-file).


Patch:
diff --git a/gitlab.go b/gitlab.go
index 08b2006..234f58a 100644
--- a/gitlab.go
+++ b/gitlab.go
@@ -23,6 +23,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"io"
+	"io/ioutil"
 	"math/rand"
 	"mime/multipart"
 	"net/http"
@@ -884,7 +885,7 @@ func CheckResponse(r *http.Response) error {
 	}
 
 	errorResponse := &ErrorResponse{Response: r}
-	data, err := io.ReadAll(r.Body)
+	data, err := ioutil.ReadAll(r.Body)
 	if err == nil && data != nil {
 		errorResponse.Body = data
 
diff --git a/jobs.go b/jobs.go
index c70e120..b238fc8 100644
--- a/jobs.go
+++ b/jobs.go
@@ -48,11 +48,10 @@ type Job struct {
 	ID                int        `json:"id"`
 	Name              string     `json:"name"`
 	Pipeline          struct {
-		ID        int    `json:"id"`
-		ProjectID int    `json:"project_id"`
-		Ref       string `json:"ref"`
-		Sha       string `json:"sha"`
-		Status    string `json:"status"`
+		ID     int    `json:"id"`
+		Ref    string `json:"ref"`
+		Sha    string `json:"sha"`
+		Status string `json:"status"`
 	} `json:"pipeline"`
 	Ref       string `json:"ref"`
 	Artifacts []struct {
diff --git a/packages.go b/packages.go
index 06a1937..d3e2be3 100644
--- a/packages.go
+++ b/packages.go
@@ -224,3 +224,22 @@ func (s *PackagesService) DeleteProjectPackage(pid interface{}, pkg int, options
 
 	return s.client.Do(req, nil)
 }
+
+// DeletePackageFile deletes a file in project package
+//
+// GitLab API docs:
+// https://docs.gitlab.com/ee/api/packages.html#delete-a-package-file
+func (s *PackagesService) DeletePackageFile(pid interface{}, pkg, file int, options ...RequestOptionFunc) (*Response, error) {
+	project, err := parseID(pid)
+	if err != nil {
+		return nil, err
+	}
+	u := fmt.Sprintf("projects/%s/packages/%d/package_files/%d", PathEscape(project), pkg, file)
+
+	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
+	if err != nil {
+		return nil, err
+	}
+
+	return s.client.Do(req, nil)
+}


Test patch:
diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml
index bbeaaf8..6b7a3f5 100644
--- a/.github/workflows/lint_and_test.yml
+++ b/.github/workflows/lint_and_test.yml
@@ -10,7 +10,7 @@ jobs:
     name: Lint and Test - ${{ matrix.go-version }}
     strategy:
       matrix:
-        go-version: [1.18.x, 1.19.x, 1.x]
+        go-version: [1.16.x, 1.17.x, 1.x]
         platform: [ubuntu-latest]
     runs-on: ${{ matrix.platform }}
     steps:
diff --git a/commits_test.go b/commits_test.go
index 7c08ec8..7f022b2 100644
--- a/commits_test.go
+++ b/commits_test.go
@@ -19,7 +19,7 @@ package gitlab
 import (
 	"encoding/json"
 	"fmt"
-	"io"
+	"io/ioutil"
 	"net/http"
 	"reflect"
 	"testing"
@@ -108,7 +108,7 @@ func TestSetCommitStatus(t *testing.T) {
 
 	mux.HandleFunc("/api/v4/projects/1/statuses/b0b3a907f41409829b307a28b82fdbd552ee5a27", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, http.MethodPost)
-		body, err := io.ReadAll(r.Body)
+		body, err := ioutil.ReadAll(r.Body)
 		require.NoError(t, err)
 
 		var content SetCommitStatusOptions
diff --git a/gitlab_test.go b/gitlab_test.go
index 860e7fb..666739f 100644
--- a/gitlab_test.go
+++ b/gitlab_test.go
@@ -21,6 +21,7 @@ import (
 	"context"
 	"errors"
 	"io"
+	"io/ioutil"
 	"log"
 	"net/http"
 	"net/http/httptest"
@@ -134,7 +135,7 @@ func TestCheckResponse(t *testing.T) {
 	resp := &http.Response{
 		Request:    req.Request,
 		StatusCode: http.StatusBadRequest,
-		Body: io.NopCloser(strings.NewReader(`
+		Body: ioutil.NopCloser(strings.NewReader(`
 		{
 			"message": {
 				"prop1": [
@@ -191,7 +192,7 @@ func TestRequestWithContext(t *testing.T) {
 }
 
 func loadFixture(filePath string) []byte {
-	content, err := os.ReadFile(filePath)
+	content, err := ioutil.ReadFile(filePath)
 	if err != nil {
 		log.Fatal(err)
 	}
diff --git a/group_import_export_test.go b/group_import_export_test.go
index 96454ef..d1c5db0 100644
--- a/group_import_export_test.go
+++ b/group_import_export_test.go
@@ -2,7 +2,7 @@ package gitlab
 
 import (
 	"fmt"
-	"io"
+	"io/ioutil"
 	"log"
 	"net/http"
 	"os"
@@ -42,7 +42,7 @@ func TestGroupExportDownload(t *testing.T) {
 		t.Errorf("GroupImportExport.ExportDownload returned error: %v", err)
 	}
 
-	data, err := io.ReadAll(export)
+	data, err := ioutil.ReadAll(export)
 	if err != nil {
 		t.Errorf("Error reading export: %v", err)
 	}
@@ -58,7 +58,7 @@ func TestGroupImport(t *testing.T) {
 	defer teardown(server)
 
 	content := []byte("temporary file's content")
-	tmpfile, err := os.CreateTemp(os.TempDir(), "example.*.tar.gz")
+	tmpfile, err := ioutil.TempFile("", "example.*.tar.gz")
 	if err != nil {
 		tmpfile.Close()
 		log.Fatal(err)
diff --git a/jobs_test.go b/jobs_test.go
index 8a171a8..0abe9b0 100644
--- a/jobs_test.go
+++ b/jobs_test.go
@@ -18,7 +18,7 @@ package gitlab
 
 import (
 	"fmt"
-	"io"
+	"io/ioutil"
 	"net/http"
 	"reflect"
 	"testing"
@@ -70,7 +70,6 @@ func TestJobsService_ListProjectJobs(t *testing.T) {
     "name": "teaspoon",
     "pipeline": {
       "id": 6,
-      "project_id": 1,
       "ref": "master",
       "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
       "status": "pending"
@@ -101,7 +100,6 @@ func TestJobsService_ListProjectJobs(t *testing.T) {
     "name": "rspec:other",
     "pipeline": {
       "id": 6,
-      "project_id": 1,
       "ref": "master",
       "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
       "status": "pending"
@@ -135,17 +133,15 @@ func TestJobsService_ListProjectJobs(t *testing.T) {
 			Name:         "teaspoon",
 			TagList:      []string{"docker runner", "ubuntu18"},
 			Pipeline: struct {
-				ID        int    `json:"id"`
-				ProjectID int    `json:"project_id"`
-				Ref       string `json:"ref"`
-				Sha       string `json:"sha"`
-				Status    string `json:"status"`
+				ID     int    `json:"id"`
+				Ref    string `json:"ref"`
+				Sha    string `json:"sha"`
+				Status string `json:"status"`
 			}{
-				ID:        6,
-				ProjectID: 1,
-				Ref:       "master",
-				Sha:       "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
-				Status:    "pending",
+				ID:     6,
+				Ref:    "master",
+				Sha:    "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
+				Status: "pending",
 			},
 			Ref:           "master",
 			Stage:         "test",
@@ -169,17 +165,15 @@ func TestJobsService_ListProjectJobs(t *testing.T) {
 			Name:         "rspec:other",
 			TagList:      []string{"docker runner", "win10-2004"},
 			Pipeline: struct {
-				ID        int    `json:"id"`
-				ProjectID int    `json:"project_id"`
-				Ref       string `json:"ref"`
-				Sha       string `json:"sha"`
-				Status    string `json:"status"`
+				ID     int    `json:"id"`
+				Ref    string `json:"ref"`
+				Sha    string `json:"sha"`
+				Status string `json:"status"`
 			}{
-				ID:        6,
-				ProjectID: 1,
-				Ref:       "master",
-				Sha:       "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
-				Status:    "pending",
+				ID:     6,
+				Ref:    "master",
+				Sha:    "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd",
+				Status: "pending",
 			},
 			Ref:    "master",
 			Stage:  "test",
@@ -208,7 +202,7 @@ func TestDownloadSingleArtifactsFileByTagOrBranch(t *testing.T) {
 		t.Fatalf("Jobs.DownloadSingleArtifactsFileByTagOrBranch returns an error: %v", err)
 	}
 
-	content, err := io.ReadAll(reader)
+	content, err := ioutil.ReadAll(reader)
 	if err != nil {
 		t.Fatalf("Jobs.DownloadSingleArtifactsFileByTagOrBranch error reading: %v", err)
 	}
diff --git a/projects_test.go b/projects_test.go
index c21d328..f495b3f 100644
--- a/projects_test.go
+++ b/projects_test.go
@@ -19,6 +19,7 @@ package gitlab
 import (
 	"bytes"
 	"fmt"
+	"io/ioutil"
 	"net/http"
 	"os"
 	"reflect"
@@ -451,7 +452,7 @@ func TestUploadFile_Retry(t *testing.T) {
 	mux, server, client := setup(t)
 	defer teardown(server)
 
-	tf, _ := os.CreateTemp(os.TempDir(), "test")
+	tf, _ := ioutil.TempFile(os.TempDir(), "test")
 	defer os.Remove(tf.Name())
 
 	isFirstRequest := true
diff --git a/releases_test.go b/releases_test.go
index c02891f..0d0fcd8 100644
--- a/releases_test.go
+++ b/releases_test.go
@@ -18,7 +18,7 @@ package gitlab
 
 import (
 	"fmt"
-	"io"
+	"io/ioutil"
 	"net/http"
 	"strings"
 	"testing"
@@ -71,7 +71,7 @@ func TestReleasesService_CreateRelease(t *testing.T) {
 	mux.HandleFunc("/api/v4/projects/1/releases",
 		func(w http.ResponseWriter, r *http.Request) {
 			testMethod(t, r, http.MethodPost)
-			b, err := io.ReadAll(r.Body)
+			b, err := ioutil.ReadAll(r.Body)
 			if err != nil {
 				t.Fatalf("unable to read request body")
 			}
@@ -116,7 +116,7 @@ func TestReleasesService_CreateReleaseWithAsset(t *testing.T) {
 	mux.HandleFunc("/api/v4/projects/1/releases",
 		func(w http.ResponseWriter, r *http.Request) {
 			testMethod(t, r, http.MethodPost)
-			b, err := io.ReadAll(r.Body)
+			b, err := ioutil.ReadAll(r.Body)
 			if err != nil {
 				t.Fatalf("unable to read request body")
 			}
@@ -166,7 +166,7 @@ func TestReleasesService_CreateReleaseWithAssetAndNameMetadata(t *testing.T) {
 	mux.HandleFunc("/api/v4/projects/1/releases",
 		func(w http.ResponseWriter, r *http.Request) {
 			testMethod(t, r, http.MethodPost)
-			b, err := io.ReadAll(r.Body)
+			b, err := ioutil.ReadAll(r.Body)
 			if err != nil {
 				t.Fatalf("unable to read request body")
 			}
@@ -216,7 +216,7 @@ func TestReleasesService_CreateReleaseWithMilestones(t *testing.T) {
 	mux.HandleFunc("/api/v4/projects/1/releases",
 		func(w http.ResponseWriter, r *http.Request) {
 			testMethod(t, r, http.MethodPost)
-			b, err := io.ReadAll(r.Body)
+			b, err := ioutil.ReadAll(r.Body)
 			if err != nil {
 				t.Fatalf("unable to read request body")
 			}
@@ -262,7 +262,7 @@ func TestReleasesService_CreateReleaseWithReleasedAt(t *testing.T) {
 	mux.HandleFunc("/api/v4/projects/1/releases",
 		func(w http.ResponseWriter, r *http.Request) {
 			testMethod(t, r, http.MethodPost)
-			b, err := io.ReadAll(r.Body)
+			b, err := ioutil.ReadAll(r.Body)
 			if err != nil {
 				t.Fatalf("unable to read request body")
 			}
@@ -308,7 +308,7 @@ func TestReleasesService_UpdateRelease(t *testing.T) {
 	mux.HandleFunc("/api/v4/projects/1/releases/v0.1",
 		func(w http.ResponseWriter, r *http.Request) {
 			testMethod(t, r, http.MethodPut)
-			b, err := io.ReadAll(r.Body)
+			b, err := ioutil.ReadAll(r.Body)
 			if err != nil {
 				t.Fatalf("unable to read request body")
 			}
@@ -344,7 +344,7 @@ func TestReleasesService_UpdateReleaseWithMilestones(t *testing.T) {
 	mux.HandleFunc("/api/v4/projects/1/releases/v0.1",
 		func(w http.ResponseWriter, r *http.Request) {
 			testMethod(t, r, http.MethodPut)
-			b, err := io.ReadAll(r.Body)
+			b, err := ioutil.ReadAll(r.Body)
 			if err != nil {
 				t.Fatalf("unable to read request body")
 			}
@@ -381,7 +381,7 @@ func TestReleasesService_UpdateReleaseWithReleasedAt(t *testing.T) {
 	mux.HandleFunc("/api/v4/projects/1/releases/v0.1",
 		func(w http.ResponseWriter, r *http.Request) {
 			testMethod(t, r, http.MethodPut)
-			b, err := io.ReadAll(r.Body)
+			b, err := ioutil.ReadAll(r.Body)
 			if err != nil {
 				t.Fatalf("unable to read request body")
 			}
diff --git a/runners_test.go b/runners_test.go
index ee8cfed..27faf18 100644
--- a/runners_test.go
+++ b/runners_test.go
@@ -56,17 +56,15 @@ func TestListRunnersJobs(t *testing.T) {
 	}
 
 	pipeline := struct {
-		ID        int    `json:"id"`
-		ProjectID int    `json:"project_id"`
-		Ref       string `json:"ref"`
-		Sha       string `json:"sha"`
-		Status    string `json:"status"`
+		ID     int    `json:"id"`
+		Ref    string `json:"ref"`
+		Sha    string `json:"sha"`
+		Status string `json:"status"`
 	}{
-		ID:        8777,
-		ProjectID: 3252,
-		Ref:       "master",
-		Sha:       "6c016b801a88f4bd31f927fc045b5c746a6f823e",
-		Status:    "failed",
+		ID:     8777,
+		Ref:    "master",
+		Sha:    "6c016b801a88f4bd31f927fc045b5c746a6f823e",
+		Status: "failed",
 	}
 
 	want := []*Job{