Repository: xanzy/go-gitlab
Pull request #1377 (2022-02-10 19:27:55)

feat: add project badge names
Signed-off-by: Erkan Zileli <erkan.zileli@trendyol.com>

Fixes: #1373 


Patch:
diff --git a/project_badges.go b/project_badges.go
index 2fce3e0..aa62a1f 100644
--- a/project_badges.go
+++ b/project_badges.go
@@ -27,6 +27,7 @@ import (
 // https://docs.gitlab.com/ee/api/project_badges.html#list-all-badges-of-a-project
 type ProjectBadge 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"`
@@ -48,7 +49,10 @@ type ProjectBadgesService struct {
 //
 // GitLab API docs:
 // https://docs.gitlab.com/ee/api/project_badges.html#list-all-badges-of-a-project
-type ListProjectBadgesOptions ListOptions
+type ListProjectBadgesOptions struct {
+	ListOptions
+	Name *string `url:"name,omitempty" json:"name,omitempty"`
+}
 
 // ListProjectBadges gets a list of a project's badges and its group badges.
 //
@@ -107,6 +111,7 @@ func (s *ProjectBadgesService) GetProjectBadge(pid interface{}, badge int, optio
 type AddProjectBadgeOptions 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"`
 }
 
 // AddProjectBadge adds a badge to a project.
@@ -141,6 +146,7 @@ func (s *ProjectBadgesService) AddProjectBadge(pid interface{}, opt *AddProjectB
 type EditProjectBadgeOptions 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"`
 }
 
 // EditProjectBadge updates a badge of a project.


Test patch:
diff --git a/project_badges_test.go b/project_badges_test.go
index 284caf3..41a41a0 100644
--- a/project_badges_test.go
+++ b/project_badges_test.go
@@ -31,6 +31,7 @@ func TestProjectBadgesService_ListProjectBadges(t *testing.T) {
 
 	want := []*ProjectBadge{{
 		ID:               1,
+		Name:             "Coverage",
 		LinkURL:          "http://example.com/ci_status.svg?project={project_path}&ref={default_branch}",
 		ImageURL:         "https://shields.io/my/badge",
 		RenderedLinkURL:  "http://example.com/ci_status.svg?project=example-org/example-project&ref=master",
@@ -80,6 +81,7 @@ func TestProjectBadgesService_GetProjectBadge(t *testing.T) {
 
 	want := &ProjectBadge{
 		ID:               1,
+		Name:             "Coverage",
 		LinkURL:          "http://example.com/ci_status.svg?project={project_path}&ref={default_branch}",
 		ImageURL:         "https://shields.io/my/badge",
 		RenderedLinkURL:  "http://example.com/ci_status.svg?project=example-org/example-project&ref=master",
@@ -129,6 +131,7 @@ func TestProjectBadgesService_AddProjectBadge(t *testing.T) {
 
 	want := &ProjectBadge{
 		ID:               1,
+		Name:             "mybadge",
 		LinkURL:          "http://example.com/ci_status.svg?project={project_path}&ref={default_branch}",
 		ImageURL:         "https://shields.io/my/badge",
 		RenderedLinkURL:  "http://example.com/ci_status.svg?project=example-org/example-project&ref=master",
@@ -178,6 +181,7 @@ func TestProjectBadgesService_EditProjectBadge(t *testing.T) {
 
 	want := &ProjectBadge{
 		ID:               1,
+		Name:             "mybadge",
 		LinkURL:          "http://example.com/ci_status.svg?project={project_path}&ref={default_branch}",
 		ImageURL:         "https://shields.io/my/badge",
 		RenderedLinkURL:  "http://example.com/ci_status.svg?project=example-org/example-project&ref=master",