From c305d1026fbe451be4488ebe33f95e2c10f5d0c9 Mon Sep 17 00:00:00 2001 From: taimoor ahmad <139589712+taimoor-at-opslevel@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:25:38 -0400 Subject: [PATCH] Better tag structs and rip out RepositoryTagConnection (#248) * set alias omitempty * changie * taggable constructors * don't need constructors use reflection * remove unnecessary repository tag connection * changie --- .changes/unreleased/Bugfix-20230913-180221.yaml | 3 +++ .../unreleased/Deprecated-20230914-180537.yaml | 3 +++ repository.go | 16 +++++----------- tags.go | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 .changes/unreleased/Bugfix-20230913-180221.yaml create mode 100644 .changes/unreleased/Deprecated-20230914-180537.yaml diff --git a/.changes/unreleased/Bugfix-20230913-180221.yaml b/.changes/unreleased/Bugfix-20230913-180221.yaml new file mode 100644 index 00000000..76c489c3 --- /dev/null +++ b/.changes/unreleased/Bugfix-20230913-180221.yaml @@ -0,0 +1,3 @@ +kind: Bugfix +body: fix using alias only to create a tag +time: 2023-09-13T18:02:21.120286-04:00 diff --git a/.changes/unreleased/Deprecated-20230914-180537.yaml b/.changes/unreleased/Deprecated-20230914-180537.yaml new file mode 100644 index 00000000..3a0ed16a --- /dev/null +++ b/.changes/unreleased/Deprecated-20230914-180537.yaml @@ -0,0 +1,3 @@ +kind: Deprecated +body: removed RepositoryTagConnection since TagConnection already exists +time: 2023-09-14T18:05:37.573959-04:00 diff --git a/repository.go b/repository.go index 56b56b50..2764a373 100644 --- a/repository.go +++ b/repository.go @@ -34,7 +34,7 @@ type Repository struct { Private bool RepoKey string Services *RepositoryServiceConnection - Tags *RepositoryTagConnection + Tags *TagConnection Tier Tier Type string Url string @@ -93,12 +93,6 @@ type ServiceRepositoryConnection struct { TotalCount int } -type RepositoryTagConnection struct { - Nodes []Tag - PageInfo PageInfo - TotalCount int -} - type ServiceRepositoryCreateInput struct { Service IdentifierInput `json:"service"` Repository IdentifierInput `json:"repository"` @@ -137,7 +131,7 @@ func (r *Repository) Hydrate(client *Client) error { } if r.Tags == nil { - r.Tags = &RepositoryTagConnection{} + r.Tags = &TagConnection{} } if r.Tags.PageInfo.HasNextPage { variables := client.InitialPageVariablesPointer() @@ -184,11 +178,11 @@ func (r *Repository) GetServices(client *Client, variables *PayloadVariables) (* return r.Services, nil } -func (r *Repository) GetTags(client *Client, variables *PayloadVariables) (*RepositoryTagConnection, error) { +func (r *Repository) GetTags(client *Client, variables *PayloadVariables) (*TagConnection, error) { var q struct { Account struct { Repository struct { - Tags RepositoryTagConnection `graphql:"tags(after: $after, first: $first)"` + Tags TagConnection `graphql:"tags(after: $after, first: $first)"` } `graphql:"repository(id: $id)"` } } @@ -203,7 +197,7 @@ func (r *Repository) GetTags(client *Client, variables *PayloadVariables) (*Repo return nil, err } if r.Tags == nil { - r.Tags = &RepositoryTagConnection{} + r.Tags = &TagConnection{} } r.Tags.Nodes = append(r.Tags.Nodes, q.Account.Repository.Tags.Nodes...) r.Tags.PageInfo = q.Account.Repository.Tags.PageInfo diff --git a/tags.go b/tags.go index 246c56db..7b35128b 100644 --- a/tags.go +++ b/tags.go @@ -32,7 +32,7 @@ type TagAssignInput struct { } type TagCreateInput struct { - Id ID `json:"id"` + Id ID `json:"id,omitempty"` Alias string `json:"alias,omitempty"` Type TaggableResource `json:"type,omitempty"` Key string `json:"key"`