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

Commit 33557e2

Browse files
author
Noah Lee
authored
Put files of the api package together (#337)
1 parent 2175558 commit 33557e2

21 files changed

+441
-531
lines changed

internal/interactor/branch.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal/interactor/chat_callback.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal/interactor/chat_user.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal/interactor/commit.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

pkg/api/deployment.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,128 @@
11
package api
22

3+
import (
4+
"context"
5+
"fmt"
6+
"net/url"
7+
"strconv"
8+
9+
"github.com/gitploy-io/gitploy/model/ent"
10+
"github.com/gitploy-io/gitploy/model/ent/deployment"
11+
)
12+
313
type (
414
DeploymentsService service
15+
16+
DeploymentListOptions struct {
17+
ListOptions
18+
19+
Env string
20+
Status deployment.Status
21+
}
22+
23+
DeploymentCreateRequest struct {
24+
Type string `json:"type"`
25+
Ref string `json:"ref"`
26+
Env string `json:"env"`
27+
}
528
)
29+
30+
// List returns the deployment list.
31+
// It returns an error for a bad request.
32+
func (s *DeploymentsService) List(ctx context.Context, namespace, name string, options DeploymentListOptions) ([]*ent.Deployment, error) {
33+
// Build the query.
34+
vals := url.Values{}
35+
36+
vals.Add("page", strconv.Itoa(options.ListOptions.Page))
37+
vals.Add("per_page", strconv.Itoa(options.PerPage))
38+
39+
if options.Env != "" {
40+
vals.Add("env", options.Env)
41+
}
42+
43+
if options.Status != "" {
44+
if err := deployment.StatusValidator(options.Status); err != nil {
45+
return nil, err
46+
}
47+
48+
vals.Add("status", string(options.Status))
49+
}
50+
51+
// Request a server.
52+
req, err := s.client.NewRequest(
53+
"GET",
54+
fmt.Sprintf("api/v1/repos/%s/%s/deployments?%s", namespace, name, vals.Encode()),
55+
nil,
56+
)
57+
if err != nil {
58+
return nil, err
59+
}
60+
61+
var ds []*ent.Deployment
62+
err = s.client.Do(ctx, req, &ds)
63+
if err != nil {
64+
return nil, err
65+
}
66+
67+
return ds, nil
68+
}
69+
70+
// Get returns the deployment.
71+
func (s *DeploymentsService) Get(ctx context.Context, namespace, name string, number int) (*ent.Deployment, error) {
72+
req, err := s.client.NewRequest(
73+
"GET",
74+
fmt.Sprintf("api/v1/repos/%s/%s/deployments/%d", namespace, name, number),
75+
nil,
76+
)
77+
if err != nil {
78+
return nil, err
79+
}
80+
81+
var d *ent.Deployment
82+
err = s.client.Do(ctx, req, &d)
83+
if err != nil {
84+
return nil, err
85+
}
86+
87+
return d, nil
88+
}
89+
90+
// Create requests a server to deploy a specific ref(branch, SHA, tag).
91+
func (s *DeploymentsService) Create(ctx context.Context, namespace, name string, body DeploymentCreateRequest) (*ent.Deployment, error) {
92+
req, err := s.client.NewRequest(
93+
"POST",
94+
fmt.Sprintf("api/v1/repos/%s/%s/deployments", namespace, name),
95+
body,
96+
)
97+
if err != nil {
98+
return nil, err
99+
}
100+
101+
var d *ent.Deployment
102+
err = s.client.Do(ctx, req, &d)
103+
if err != nil {
104+
return nil, err
105+
}
106+
107+
return d, nil
108+
}
109+
110+
// Update requests to trigger the 'waiting' deployment.
111+
func (s *DeploymentsService) Update(ctx context.Context, namespace, name string, number int) (*ent.Deployment, error) {
112+
req, err := s.client.NewRequest(
113+
"PUT",
114+
fmt.Sprintf("api/v1/repos/%s/%s/deployments/%d", namespace, name, number),
115+
nil,
116+
)
117+
if err != nil {
118+
return nil, err
119+
}
120+
121+
var d *ent.Deployment
122+
err = s.client.Do(ctx, req, &d)
123+
if err != nil {
124+
return nil, err
125+
}
126+
127+
return d, nil
128+
}

pkg/api/deployment_create.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

pkg/api/deployment_create_test.go

Lines changed: 0 additions & 48 deletions
This file was deleted.

pkg/api/deployment_get.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

pkg/api/deployment_list.go

Lines changed: 0 additions & 60 deletions
This file was deleted.

pkg/api/deployment_list_test.go

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)