|
| 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 | +} |
0 commit comments