|
| 1 | +package client |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "net/http" |
| 7 | + |
| 8 | + v1pb "github.com/bytebase/bytebase/proto/generated-go/v1" |
| 9 | +) |
| 10 | + |
| 11 | +// ListReviewConfig will return review configs. |
| 12 | +func (c *client) ListReviewConfig(ctx context.Context) (*v1pb.ListReviewConfigsResponse, error) { |
| 13 | + req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("%s/%s/reviewConfigs", c.url, c.version), nil) |
| 14 | + if err != nil { |
| 15 | + return nil, err |
| 16 | + } |
| 17 | + |
| 18 | + body, err := c.doRequest(req) |
| 19 | + if err != nil { |
| 20 | + return nil, err |
| 21 | + } |
| 22 | + |
| 23 | + var res v1pb.ListReviewConfigsResponse |
| 24 | + if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil { |
| 25 | + return nil, err |
| 26 | + } |
| 27 | + |
| 28 | + return &res, nil |
| 29 | +} |
| 30 | + |
| 31 | +// GetReviewConfig gets the review config by full name. |
| 32 | +func (c *client) GetReviewConfig(ctx context.Context, reviewName string) (*v1pb.ReviewConfig, error) { |
| 33 | + body, err := c.getResource(ctx, reviewName) |
| 34 | + if err != nil { |
| 35 | + return nil, err |
| 36 | + } |
| 37 | + |
| 38 | + var res v1pb.ReviewConfig |
| 39 | + if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil { |
| 40 | + return nil, err |
| 41 | + } |
| 42 | + |
| 43 | + return &res, nil |
| 44 | +} |
| 45 | + |
| 46 | +// UpsertReviewConfig updates or creates the review config. |
| 47 | +func (c *client) UpsertReviewConfig(ctx context.Context, patch *v1pb.ReviewConfig, updateMasks []string) (*v1pb.ReviewConfig, error) { |
| 48 | + body, err := c.updateResource(ctx, patch.Name, patch, updateMasks, true /* allow missing */) |
| 49 | + if err != nil { |
| 50 | + return nil, err |
| 51 | + } |
| 52 | + |
| 53 | + var res v1pb.ReviewConfig |
| 54 | + if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil { |
| 55 | + return nil, err |
| 56 | + } |
| 57 | + |
| 58 | + return &res, nil |
| 59 | +} |
| 60 | + |
| 61 | +// DeleteReviewConfig deletes the review config. |
| 62 | +func (c *client) DeleteReviewConfig(ctx context.Context, reviewName string) error { |
| 63 | + return c.deleteResource(ctx, reviewName) |
| 64 | +} |
0 commit comments