Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit b5e0812

Browse files
authored
Merge pull request #2027 from houstonj1/feat/harbor-integration
Add support for Harbor Integration
2 parents 8733605 + e6a0bbf commit b5e0812

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed

services.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,103 @@ func (s *ServicesService) DeleteGithubService(pid interface{}, options ...Reques
767767
return s.client.Do(req, nil)
768768
}
769769

770+
// HarborService represents the Harbor service settings.
771+
//
772+
// GitLab API docs:
773+
// https://docs.gitlab.com/ee/api/integrations.html#harbor
774+
type HarborService struct {
775+
Service
776+
Properties *HarborServiceProperties `json:"properties"`
777+
}
778+
779+
// HarborServiceProperties represents Harbor specific properties.
780+
//
781+
// GitLab API docs:
782+
// https://docs.gitlab.com/ee/api/integrations.html#harbor
783+
type HarborServiceProperties struct {
784+
URL string `json:"url"`
785+
ProjectName string `json:"project_name"`
786+
Username string `json:"username"`
787+
Password string `json:"password"`
788+
UseInheritedSettings bool `json:"use_inherited_settings"`
789+
}
790+
791+
// GetHarborService gets Harbor service settings for a project.
792+
//
793+
// GitLab API docs:
794+
// https://docs.gitlab.com/ee/api/integrations.html#get-harbor-settings
795+
func (s *ServicesService) GetHarborService(pid interface{}, options ...RequestOptionFunc) (*HarborService, *Response, error) {
796+
project, err := parseID(pid)
797+
if err != nil {
798+
return nil, nil, err
799+
}
800+
u := fmt.Sprintf("projects/%s/integrations/harbor", PathEscape(project))
801+
802+
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
803+
if err != nil {
804+
return nil, nil, err
805+
}
806+
807+
svc := new(HarborService)
808+
resp, err := s.client.Do(req, svc)
809+
if err != nil {
810+
return nil, resp, err
811+
}
812+
813+
return svc, resp, nil
814+
}
815+
816+
// SetHarborServiceOptions represents the available SetHarborService()
817+
// options.
818+
//
819+
// GitLab API docs:
820+
// https://docs.gitlab.com/ee/api/integrations.html#set-up-harbor
821+
type SetHarborServiceOptions struct {
822+
URL *string `url:"url,omitempty" json:"url,omitempty"`
823+
ProjectName *string `url:"project_name,omitempty" json:"project_name,omitempty"`
824+
Username *string `url:"username,omitempty" json:"username,omitempty"`
825+
Password *string `url:"password,omitempty" json:"password,omitempty"`
826+
UseInheritedSettings *bool `url:"use_inherited_settings,omitempty" json:"use_inherited_settings,omitempty"`
827+
}
828+
829+
// SetHarborService sets Harbor service for a project.
830+
//
831+
// GitLab API docs:
832+
// https://docs.gitlab.com/ee/api/integrations.html#set-up-harbor
833+
func (s *ServicesService) SetHarborService(pid interface{}, opt *SetHarborServiceOptions, options ...RequestOptionFunc) (*Response, error) {
834+
project, err := parseID(pid)
835+
if err != nil {
836+
return nil, err
837+
}
838+
u := fmt.Sprintf("projects/%s/integrations/harbor", PathEscape(project))
839+
840+
req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
841+
if err != nil {
842+
return nil, err
843+
}
844+
845+
return s.client.Do(req, nil)
846+
}
847+
848+
// DeleteHarborService deletes Harbor service for a project.
849+
//
850+
// GitLab API docs:
851+
// https://docs.gitlab.com/ee/api/integrations.html#disable-harbor
852+
func (s *ServicesService) DeleteHarborService(pid interface{}, options ...RequestOptionFunc) (*Response, error) {
853+
project, err := parseID(pid)
854+
if err != nil {
855+
return nil, err
856+
}
857+
u := fmt.Sprintf("projects/%s/integrations/harbor", PathEscape(project))
858+
859+
req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
860+
if err != nil {
861+
return nil, err
862+
}
863+
864+
return s.client.Do(req, nil)
865+
}
866+
770867
// SlackApplication represents GitLab for slack application settings.
771868
//
772869
// GitLab API docs:

services_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,58 @@ func TestDeleteEmailsOnPushService(t *testing.T) {
327327
}
328328
}
329329

330+
func TestGetHarborService(t *testing.T) {
331+
mux, client := setup(t)
332+
333+
mux.HandleFunc("/api/v4/projects/1/integrations/harbor", func(w http.ResponseWriter, r *http.Request) {
334+
testMethod(t, r, http.MethodGet)
335+
fmt.Fprint(w, `{"id":1}`)
336+
})
337+
want := &HarborService{Service: Service{ID: 1}}
338+
339+
service, _, err := client.Services.GetHarborService(1)
340+
if err != nil {
341+
t.Fatalf("Services.GetHarborService returns an error: %v", err)
342+
}
343+
if !reflect.DeepEqual(want, service) {
344+
t.Errorf("Services.GetHarborService returned %+v, want %+v", service, want)
345+
}
346+
}
347+
348+
func TestSetHarborService(t *testing.T) {
349+
mux, client := setup(t)
350+
351+
mux.HandleFunc("/api/v4/projects/1/integrations/harbor", func(w http.ResponseWriter, r *http.Request) {
352+
testMethod(t, r, http.MethodPut)
353+
})
354+
355+
opt := &SetHarborServiceOptions{
356+
URL: Ptr("url"),
357+
ProjectName: Ptr("project"),
358+
Username: Ptr("user"),
359+
Password: Ptr("pass"),
360+
UseInheritedSettings: Ptr(false),
361+
}
362+
363+
_, err := client.Services.SetHarborService(1, opt)
364+
if err != nil {
365+
t.Fatalf("Services.SetHarborService returns an error: %v", err)
366+
}
367+
}
368+
369+
func TestDeleteHarborService(t *testing.T) {
370+
mux, client := setup(t)
371+
372+
mux.HandleFunc("/api/v4/projects/1/integrations/harbor", func(w http.ResponseWriter, r *http.Request) {
373+
testMethod(t, r, http.MethodDelete)
374+
})
375+
376+
_, err := client.Services.DeleteHarborService(1)
377+
if err != nil {
378+
t.Fatalf("Services.DeleteHarborService returns an error: %v", err)
379+
}
380+
}
381+
330382
func TestGetSlackApplication(t *testing.T) {
331383
mux, client := setup(t)
332384

0 commit comments

Comments
 (0)