Skip to content

Commit 11ab706

Browse files
feat: marketplace improvements for latest management
1 parent 05d59d7 commit 11ab706

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

internal/client/request.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ func parseRequestAndResponse(req *http.Request, resp *http.Response) *Response {
257257
rawResponse: resp,
258258
rawRequest: req,
259259
body: body,
260+
header: resp.Header,
260261
statusCode: resp.StatusCode,
261262
}
262263
}

internal/client/response.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type Response struct {
5858
rawRequest *http.Request
5959

6060
body []byte
61+
header http.Header
6162
statusCode int
6263
err error
6364
}
@@ -67,6 +68,10 @@ func (r *Response) RawRequest() *http.Request {
6768
return r.rawRequest
6869
}
6970

71+
func (r *Response) Header() http.Header {
72+
return r.header
73+
}
74+
7075
// Error return the response status code
7176
func (r *Response) StatusCode() int {
7277
return r.statusCode

internal/cmd/marketplace/delete.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,13 @@ func deleteItemByItemIDAndVersion(ctx context.Context, client *client.APIClient,
126126
return fmt.Errorf("error executing request: %w", err)
127127
}
128128

129-
return checkDeleteResponseErrors(resp)
129+
if err := checkDeleteResponseErrors(resp); err != nil {
130+
return err
131+
}
132+
133+
asd := resp.Header().Get("X-Marketplace-Item-Latest-Version:")
134+
fmt.Printf("\nasd %s\n", asd)
135+
return nil
130136
}
131137

132138
func checkDeleteResponseErrors(resp *client.Response) error {

internal/cmd/marketplace/list_versions.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,22 @@ func getItemVersions(ctx context.Context, client *client.APIClient, companyID, i
101101
}
102102

103103
func printItemVersionList(releases *[]marketplace.Release, p printer.IPrinter) {
104-
p.Keys("Version", "Name", "Description")
104+
p.Keys("Version", "Name", "Description", "Latest")
105105

106106
for _, release := range *releases {
107107
description := "-"
108108
if release.Description != "" {
109109
description = release.Description
110110
}
111+
latestCheck := ""
112+
if release.Latest {
113+
latestCheck = "✅"
114+
}
111115
p.Record(
112116
release.Version,
113117
release.Name,
114118
description,
119+
latestCheck,
115120
)
116121
}
117122
p.Print()

internal/cmd/marketplace/list_versions_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const (
4040
"version": "1.0.0",
4141
"reference": "655342ce0f991db238fd73e4",
4242
"security": false,
43+
"isLatest": true,
4344
"releaseNote": "-",
4445
"visibility": {
4546
"public": true
@@ -89,6 +90,7 @@ func TestGetItemVersions(t *testing.T) {
8990
{
9091
Name: "Some Awesome Service",
9192
Description: "The Awesome Service allows to do some amazing stuff.",
93+
Latest: true,
9294
Version: "1.0.0",
9395
},
9496
{

internal/resources/marketplace/marketplace.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type UploadImageResponse struct {
6767
type Release struct {
6868
Version string `json:"version"`
6969
Name string `json:"name"`
70+
Latest bool `json:"isLatest"`
7071
Description string `json:"description"`
7172
}
7273

0 commit comments

Comments
 (0)