Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for creating new release deployments #74

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions sentry/release_deployment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package sentry

import (
"context"
"fmt"
"time"
)

type ReleaseDeploymentsService service

type ReleaseDeployment struct {
ID string `json:"id"`
Name *string `json:"name,omitempty"`
Environment string `json:"environment,omitempty"`
URL *string `json:"url,omitempty"`
Projects []string `json:"projects,omitempty"`
DateStarted *time.Time `json:"dateStarted,omitempty"`
DateFinished *time.Time `json:"dateFinished,omitempty"`
}

// Get a Release Deploy for a project.
func (s *ReleaseDeploymentsService) Get(ctx context.Context, organizationSlug string, version string, deployID string) (*ReleaseDeployment, *Response, error) {

lastCursor := ""

// Search for the deployment ID by using the list endpoint. When we have
// found the first match return immediately
for {
params := ListCursorParams{
Cursor: lastCursor,
}

u := fmt.Sprintf("0/organizations/%v/releases/%s/deploys/", organizationSlug, version)
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
}

deployments := new([]ReleaseDeployment)
resp, err := s.client.Do(ctx, req, deployments)
if err != nil {
return nil, resp, err
}

for i := range *deployments {
d := (*deployments)[i]
if d.ID == deployID {
return &d, resp, nil
}
}

// No matches in the current page and no further pages to check
if resp.Cursor == "" {
return nil, resp, nil
}
lastCursor = resp.Cursor
}
}

// Create a new Release Deploy to a project.
func (s *ReleaseDeploymentsService) Create(ctx context.Context, organizationSlug string, version string, params *ReleaseDeployment) (*ReleaseDeployment, *Response, error) {
u := fmt.Sprintf("0/organizations/%v/releases/%s/deploys/", organizationSlug, version)
req, err := s.client.NewRequest("POST", u, params)
if err != nil {
return nil, nil, err
}

deploy := new(ReleaseDeployment)
resp, err := s.client.Do(ctx, req, deploy)
if err != nil {
return nil, resp, err
}

return deploy, resp, nil
}
2 changes: 2 additions & 0 deletions sentry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Client struct {
ProjectPlugins *ProjectPluginsService
Projects *ProjectsService
ProjectFilter *ProjectFilterService
ReleaseDeployments *ReleaseDeploymentsService
mvantellingen marked this conversation as resolved.
Show resolved Hide resolved
Teams *TeamsService
}

Expand Down Expand Up @@ -96,6 +97,7 @@ func NewClient(httpClient *http.Client) *Client {
c.ProjectOwnerships = (*ProjectOwnershipsService)(&c.common)
c.ProjectPlugins = (*ProjectPluginsService)(&c.common)
c.Projects = (*ProjectsService)(&c.common)
c.ReleaseDeployments = (*ReleaseDeploymentsService)(&c.common)
mvantellingen marked this conversation as resolved.
Show resolved Hide resolved
c.Teams = (*TeamsService)(&c.common)
return c
}
Expand Down