Skip to content

Commit 966077d

Browse files
Add support for creating new release deployments (#74)
The release deployments in Sentry only support create and list so these are the only two endpoints added
1 parent 9a37263 commit 966077d

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

sentry/release_deployment.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package sentry
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
)
8+
9+
type ReleaseDeploymentsService service
10+
11+
type ReleaseDeployment struct {
12+
ID string `json:"id"`
13+
Name *string `json:"name,omitempty"`
14+
Environment string `json:"environment,omitempty"`
15+
URL *string `json:"url,omitempty"`
16+
Projects []string `json:"projects,omitempty"`
17+
DateStarted *time.Time `json:"dateStarted,omitempty"`
18+
DateFinished *time.Time `json:"dateFinished,omitempty"`
19+
}
20+
21+
// Get a Release Deploy for a project.
22+
func (s *ReleaseDeploymentsService) Get(ctx context.Context, organizationSlug string, version string, deployID string) (*ReleaseDeployment, *Response, error) {
23+
24+
lastCursor := ""
25+
26+
// Search for the deployment ID by using the list endpoint. When we have
27+
// found the first match return immediately
28+
for {
29+
params := ListCursorParams{
30+
Cursor: lastCursor,
31+
}
32+
33+
u := fmt.Sprintf("0/organizations/%v/releases/%s/deploys/", organizationSlug, version)
34+
u, err := addQuery(u, params)
35+
if err != nil {
36+
return nil, nil, err
37+
}
38+
39+
req, err := s.client.NewRequest("GET", u, nil)
40+
if err != nil {
41+
return nil, nil, err
42+
}
43+
44+
deployments := new([]ReleaseDeployment)
45+
resp, err := s.client.Do(ctx, req, deployments)
46+
if err != nil {
47+
return nil, resp, err
48+
}
49+
50+
for i := range *deployments {
51+
d := (*deployments)[i]
52+
if d.ID == deployID {
53+
return &d, resp, nil
54+
}
55+
}
56+
57+
// No matches in the current page and no further pages to check
58+
if resp.Cursor == "" {
59+
return nil, resp, nil
60+
}
61+
lastCursor = resp.Cursor
62+
}
63+
}
64+
65+
// Create a new Release Deploy to a project.
66+
func (s *ReleaseDeploymentsService) Create(ctx context.Context, organizationSlug string, version string, params *ReleaseDeployment) (*ReleaseDeployment, *Response, error) {
67+
u := fmt.Sprintf("0/organizations/%v/releases/%s/deploys/", organizationSlug, version)
68+
req, err := s.client.NewRequest("POST", u, params)
69+
if err != nil {
70+
return nil, nil, err
71+
}
72+
73+
deploy := new(ReleaseDeployment)
74+
resp, err := s.client.Do(ctx, req, deploy)
75+
if err != nil {
76+
return nil, resp, err
77+
}
78+
79+
return deploy, resp, nil
80+
}

sentry/sentry.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type Client struct {
6161
ProjectPlugins *ProjectPluginsService
6262
Projects *ProjectsService
6363
ProjectFilter *ProjectFilterService
64+
ReleaseDeployments *ReleaseDeploymentsService
6465
Teams *TeamsService
6566
}
6667

@@ -96,6 +97,7 @@ func NewClient(httpClient *http.Client) *Client {
9697
c.ProjectOwnerships = (*ProjectOwnershipsService)(&c.common)
9798
c.ProjectPlugins = (*ProjectPluginsService)(&c.common)
9899
c.Projects = (*ProjectsService)(&c.common)
100+
c.ReleaseDeployments = (*ReleaseDeploymentsService)(&c.common)
99101
c.Teams = (*TeamsService)(&c.common)
100102
return c
101103
}

0 commit comments

Comments
 (0)