Skip to content

Commit

Permalink
Merge pull request #1618 from linkdotnet/fix/#1578
Browse files Browse the repository at this point in the history
fix: Tags in Package as complex object
  • Loading branch information
svanharmelen committed Jan 6, 2023
2 parents 1c9b5e4 + baf8093 commit 3e2faf7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
15 changes: 14 additions & 1 deletion packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Package struct {
Status string `json:"status"`
Links *PackageLinks `json:"_links"`
CreatedAt *time.Time `json:"created_at"`
Tags []string `json:"tags"`
Tags []PackageTag `json:"tags"`
}

func (s Package) String() string {
Expand Down Expand Up @@ -71,6 +71,19 @@ func (s PackageLinks) String() string {
return Stringify(s)
}

// PackageTag holds label information about the package
type PackageTag struct {
ID int `json:"id"`
PackageID int `json:"package_id"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

func (s PackageTag) String() string {
return Stringify(s)
}

// PackageFile represents one file contained within a package.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/packages.html
Expand Down
21 changes: 19 additions & 2 deletions packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"testing"
"time"

"github.com/stretchr/testify/require"
)
Expand All @@ -25,12 +26,21 @@ func TestPackagesService_ListProjectPackages(t *testing.T) {
"web_path": "/foo/bar/-/packages/3",
"delete_api_path": "https://gitlab.example.com/api/v4/projects/1/packages/3"
},
"tags": []
"tags": [
{
"id": 1,
"package_id": 37,
"name": "Some Label",
"created_at": "2023-01-04T20:00:00.000Z",
"updated_at": "2023-01-04T20:00:00.000Z"
}
]
}
]
`)
})

timestamp := time.Date(2023, 1, 4, 20, 0, 0, 0, time.UTC)
want := []*Package{{
ID: 3,
Name: "Hello/0.1@mycompany/stable",
Expand All @@ -40,7 +50,14 @@ func TestPackagesService_ListProjectPackages(t *testing.T) {
WebPath: "/foo/bar/-/packages/3",
DeleteAPIPath: "https://gitlab.example.com/api/v4/projects/1/packages/3",
},
Tags: []string{},
Tags: []PackageTag{
{
ID: 1,
PackageID: 37,
Name: "Some Label",
CreatedAt: timestamp,
UpdatedAt: timestamp,
}},
}}

ps, resp, err := client.Packages.ListProjectPackages(3, nil)
Expand Down

0 comments on commit 3e2faf7

Please sign in to comment.