From b33f9fa02d136a3b696008c2d384883f6270ee20 Mon Sep 17 00:00:00 2001 From: Jian Yuan Lee Date: Sun, 5 May 2024 03:31:58 +0100 Subject: [PATCH] feat: new OrganizationProjectsService --- sentry/organization_projects.go | 37 +++++++++++++++++++++++++++++++++ sentry/projects.go | 3 --- sentry/sentry.go | 2 ++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 sentry/organization_projects.go diff --git a/sentry/organization_projects.go b/sentry/organization_projects.go new file mode 100644 index 0000000..abaa48c --- /dev/null +++ b/sentry/organization_projects.go @@ -0,0 +1,37 @@ +package sentry + +import ( + "context" + "fmt" +) + +type OrganizationProjectsService service + +type ListOrganizationProjectsParams struct { + ListCursorParams + + Options string `url:"options,omitempty"` + Query string `url:"query,omitempty"` +} + +// List an Organization's Projects +// https://docs.sentry.io/api/organizations/list-an-organizations-projects/ +func (s *OrganizationProjectsService) List(ctx context.Context, organizationSlug string, params *ListOrganizationProjectsParams) ([]*Project, *Response, error) { + u := fmt.Sprintf("0/organizations/%v/projects/", organizationSlug) + u, err := addQuery(u, params) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + projects := []*Project{} + resp, err := s.client.Do(ctx, req, &projects) + if err != nil { + return nil, resp, err + } + return projects, resp, nil +} diff --git a/sentry/projects.go b/sentry/projects.go index 1fa7c58..4b3c7dd 100644 --- a/sentry/projects.go +++ b/sentry/projects.go @@ -94,9 +94,6 @@ type ProjectsService service type ListProjectsParams struct { ListCursorParams - - Options string `url:"options,omitempty"` - Query string `url:"query,omitempty"` } // List projects available. diff --git a/sentry/sentry.go b/sentry/sentry.go index 6ac56ab..a023bb0 100644 --- a/sentry/sentry.go +++ b/sentry/sentry.go @@ -54,6 +54,7 @@ type Client struct { OrganizationCodeMappings *OrganizationCodeMappingsService OrganizationIntegrations *OrganizationIntegrationsService OrganizationMembers *OrganizationMembersService + OrganizationProjects *OrganizationProjectsService OrganizationRepositories *OrganizationRepositoriesService Organizations *OrganizationsService ProjectFilters *ProjectFiltersService @@ -95,6 +96,7 @@ func NewClient(httpClient *http.Client) *Client { c.OrganizationCodeMappings = (*OrganizationCodeMappingsService)(&c.common) c.OrganizationIntegrations = (*OrganizationIntegrationsService)(&c.common) c.OrganizationMembers = (*OrganizationMembersService)(&c.common) + c.OrganizationProjects = (*OrganizationProjectsService)(&c.common) c.OrganizationRepositories = (*OrganizationRepositoriesService)(&c.common) c.Organizations = (*OrganizationsService)(&c.common) c.ProjectFilters = (*ProjectFiltersService)(&c.common)