Skip to content

Commit

Permalink
fix: add name parameter to group badges
Browse files Browse the repository at this point in the history
  • Loading branch information
Roose, P.A. (Pascal) committed Jul 28, 2023
1 parent 60e264a commit 9db732f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
9 changes: 8 additions & 1 deletion group_badges.go
Expand Up @@ -44,6 +44,7 @@ const (
// https://docs.gitlab.com/ee/api/group_badges.html
type GroupBadge struct {
ID int `json:"id"`
Name string `json:"name"`
LinkURL string `json:"link_url"`
ImageURL string `json:"image_url"`
RenderedLinkURL string `json:"rendered_link_url"`
Expand All @@ -55,7 +56,10 @@ type GroupBadge struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_badges.html#list-all-badges-of-a-group
type ListGroupBadgesOptions ListOptions
type ListGroupBadgesOptions struct {
ListOptions
Name *string `url:"name,omitempty" json:"name,omitempty"`
}

// ListGroupBadges gets a list of a group badges.
//
Expand Down Expand Up @@ -114,6 +118,7 @@ func (s *GroupBadgesService) GetGroupBadge(gid interface{}, badge int, options .
type AddGroupBadgeOptions struct {
LinkURL *string `url:"link_url,omitempty" json:"link_url,omitempty"`
ImageURL *string `url:"image_url,omitempty" json:"image_url,omitempty"`
Name *string `url:"name,omitempty" json:"name,omitempty"`
}

// AddGroupBadge adds a badge to a group.
Expand Down Expand Up @@ -148,6 +153,7 @@ func (s *GroupBadgesService) AddGroupBadge(gid interface{}, opt *AddGroupBadgeOp
type EditGroupBadgeOptions struct {
LinkURL *string `url:"link_url,omitempty" json:"link_url,omitempty"`
ImageURL *string `url:"image_url,omitempty" json:"image_url,omitempty"`
Name *string `url:"name,omitempty" json:"name,omitempty"`
}

// EditGroupBadge updates a badge of a group.
Expand Down Expand Up @@ -201,6 +207,7 @@ func (s *GroupBadgesService) DeleteGroupBadge(gid interface{}, badge int, option
type GroupBadgePreviewOptions struct {
LinkURL *string `url:"link_url,omitempty" json:"link_url,omitempty"`
ImageURL *string `url:"image_url,omitempty" json:"image_url,omitempty"`
Name *string `url:"name,omitempty" json:"name,omitempty"`
}

// PreviewGroupBadge returns how the link_url and image_url final URLs would be after
Expand Down
16 changes: 8 additions & 8 deletions group_badges_test.go
Expand Up @@ -29,15 +29,15 @@ func TestListGroupBadges(t *testing.T) {
mux.HandleFunc("/api/v4/groups/1/badges",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `[{"id":1, "kind":"group"},{"id":2, "kind":"group"}]`)
fmt.Fprint(w, `[{"id":1, "name":"one", "kind":"group"},{"id":2, "name":"two", "kind":"group"}]`)
})

badges, _, err := client.GroupBadges.ListGroupBadges(1, &ListGroupBadgesOptions{})
if err != nil {
t.Errorf("GroupBadges.ListGroupBadges returned error: %v", err)
}

want := []*GroupBadge{{ID: 1, Kind: GroupBadgeKind}, {ID: 2, Kind: GroupBadgeKind}}
want := []*GroupBadge{{ID: 1, Name: "one", Kind: GroupBadgeKind}, {ID: 2, Name: "two", Kind: GroupBadgeKind}}
if !reflect.DeepEqual(want, badges) {
t.Errorf("GroupBadges.ListGroupBadges returned %+v, want %+v", badges, want)
}
Expand All @@ -49,15 +49,15 @@ func TestGetGroupBadge(t *testing.T) {
mux.HandleFunc("/api/v4/groups/1/badges/2",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"id":2, "kind":"group"}`)
fmt.Fprint(w, `{"id":2, "name":"two", "kind":"group"}`)
})

badge, _, err := client.GroupBadges.GetGroupBadge(1, 2)
if err != nil {
t.Errorf("GroupBadges.GetGroupBadge returned error: %v", err)
}

want := &GroupBadge{ID: 2, Kind: GroupBadgeKind}
want := &GroupBadge{ID: 2, Name: "two", Kind: GroupBadgeKind}
if !reflect.DeepEqual(want, badge) {
t.Errorf("GroupBadges.GetGroupBadge returned %+v, want %+v", badge, want)
}
Expand All @@ -69,7 +69,7 @@ func TestAddGroupBadge(t *testing.T) {
mux.HandleFunc("/api/v4/groups/1/badges",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"id":3, "link_url":"LINK", "image_url":"IMAGE", "kind":"group"}`)
fmt.Fprint(w, `{"id":3, "name":"three", "link_url":"LINK", "image_url":"IMAGE", "kind":"group"}`)
})

opt := &AddGroupBadgeOptions{ImageURL: String("IMAGE"), LinkURL: String("LINK")}
Expand All @@ -78,7 +78,7 @@ func TestAddGroupBadge(t *testing.T) {
t.Errorf("GroupBadges.AddGroupBadge returned error: %v", err)
}

want := &GroupBadge{ID: 3, ImageURL: "IMAGE", LinkURL: "LINK", Kind: GroupBadgeKind}
want := &GroupBadge{ID: 3, Name: "three", ImageURL: "IMAGE", LinkURL: "LINK", Kind: GroupBadgeKind}
if !reflect.DeepEqual(want, badge) {
t.Errorf("GroupBadges.AddGroupBadge returned %+v, want %+v", badge, want)
}
Expand All @@ -90,7 +90,7 @@ func TestEditGroupBadge(t *testing.T) {
mux.HandleFunc("/api/v4/groups/1/badges/2",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
fmt.Fprint(w, `{"id":2, "link_url":"NEW_LINK", "image_url":"NEW_IMAGE", "kind":"group"}`)
fmt.Fprint(w, `{"id":2, "name":"two", "link_url":"NEW_LINK", "image_url":"NEW_IMAGE", "kind":"group"}`)
})

opt := &EditGroupBadgeOptions{ImageURL: String("NEW_IMAGE"), LinkURL: String("NEW_LINK")}
Expand All @@ -99,7 +99,7 @@ func TestEditGroupBadge(t *testing.T) {
t.Errorf("GroupBadges.EditGroupBadge returned error: %v", err)
}

want := &GroupBadge{ID: 2, ImageURL: "NEW_IMAGE", LinkURL: "NEW_LINK", Kind: GroupBadgeKind}
want := &GroupBadge{ID: 2, Name: "two", ImageURL: "NEW_IMAGE", LinkURL: "NEW_LINK", Kind: GroupBadgeKind}
if !reflect.DeepEqual(want, badge) {
t.Errorf("GroupBadges.EditGroupBadge returned %+v, want %+v", badge, want)
}
Expand Down

0 comments on commit 9db732f

Please sign in to comment.