Skip to content

Commit bdd260c

Browse files
committed
chore(variables): add description property to Variable struct
1 parent 4879051 commit bdd260c

File tree

3 files changed

+119
-9
lines changed

3 files changed

+119
-9
lines changed

http/swagger.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6573,6 +6573,8 @@ components:
65736573
type: string
65746574
name:
65756575
type: string
6576+
description:
6577+
type: string
65766578
selected:
65776579
type: array
65786580
items:

http/variable_test.go

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,73 @@ func TestVariableService_handleGetVariables(t *testing.T) {
9595
wants: wants{
9696
statusCode: http.StatusOK,
9797
contentType: "application/json; charset=utf-8",
98-
body: `{"variables":[{"id":"6162207574726f71","orgID":"0000000000000001","name":"variable-a","selected":["b"],"arguments":{"type":"constant","values":["a","b"]},"labels":[{"id":"fc3dc670a4be9b9a","name":"label","properties":{"color":"fff000"}}],"links":{"self":"/api/v2/variables/6162207574726f71","labels":"/api/v2/variables/6162207574726f71/labels","org":"/api/v2/orgs/0000000000000001"}},{"id":"61726920617a696f","orgID":"0000000000000001","name":"variable-b","selected":["c"],"arguments":{"type":"map","values":{"a":"b","c":"d"}},"labels":[{"id":"fc3dc670a4be9b9a","name":"label","properties":{"color":"fff000"}}],"links":{"self":"/api/v2/variables/61726920617a696f","labels":"/api/v2/variables/61726920617a696f/labels","org": "/api/v2/orgs/0000000000000001"}}],"links":{"self":"/api/v2/variables?descending=false&limit=20&offset=0"}}`,
98+
body: `{
99+
"links":{
100+
"self":"/api/v2/variables?descending=false&limit=20&offset=0"
101+
},
102+
"variables":[
103+
{
104+
"arguments":{
105+
"type":"constant",
106+
"values":[
107+
"a",
108+
"b"
109+
]
110+
},
111+
"description":"",
112+
"id":"6162207574726f71",
113+
"labels":[
114+
{
115+
"id":"fc3dc670a4be9b9a",
116+
"name":"label",
117+
"properties":{
118+
"color":"fff000"
119+
}
120+
}
121+
],
122+
"links":{
123+
"labels":"/api/v2/variables/6162207574726f71/labels",
124+
"org":"/api/v2/orgs/0000000000000001",
125+
"self":"/api/v2/variables/6162207574726f71"
126+
},
127+
"name":"variable-a",
128+
"orgID":"0000000000000001",
129+
"selected":[
130+
"b"
131+
]
132+
},
133+
{
134+
"arguments":{
135+
"type":"map",
136+
"values":{
137+
"a":"b",
138+
"c":"d"
139+
}
140+
},
141+
"description":"",
142+
"id":"61726920617a696f",
143+
"labels":[
144+
{
145+
"id":"fc3dc670a4be9b9a",
146+
"name":"label",
147+
"properties":{
148+
"color":"fff000"
149+
}
150+
}
151+
],
152+
"links":{
153+
"labels":"/api/v2/variables/61726920617a696f/labels",
154+
"org":"/api/v2/orgs/0000000000000001",
155+
"self":"/api/v2/variables/61726920617a696f"
156+
},
157+
"name":"variable-b",
158+
"orgID":"0000000000000001",
159+
"selected":[
160+
"c"
161+
]
162+
}
163+
]
164+
}`,
99165
},
100166
},
101167
{
@@ -165,7 +231,43 @@ func TestVariableService_handleGetVariables(t *testing.T) {
165231
wants: wants{
166232
statusCode: http.StatusOK,
167233
contentType: "application/json; charset=utf-8",
168-
body: `{"variables":[{"id":"6162207574726f71","orgID":"0000000000000001","name":"variable-a","selected":["b"],"arguments":{"type":"constant","values":["a","b"]},"labels":[{"id":"fc3dc670a4be9b9a","name":"label","properties":{"color": "fff000"}}],"links":{"self":"/api/v2/variables/6162207574726f71","org":"/api/v2/orgs/0000000000000001","labels":"/api/v2/variables/6162207574726f71/labels"}}],"links":{"self":"/api/v2/variables?descending=false&limit=20&offset=0&orgID=0000000000000001"}}`,
234+
body: `{
235+
"links": {
236+
"self": "/api/v2/variables?descending=false&limit=20&offset=0&orgID=0000000000000001"
237+
},
238+
"variables": [
239+
{
240+
"arguments": {
241+
"type": "constant",
242+
"values": [
243+
"a",
244+
"b"
245+
]
246+
},
247+
"description": "",
248+
"id": "6162207574726f71",
249+
"labels": [
250+
{
251+
"id": "fc3dc670a4be9b9a",
252+
"name": "label",
253+
"properties": {
254+
"color": "fff000"
255+
}
256+
}
257+
],
258+
"links": {
259+
"labels": "/api/v2/variables/6162207574726f71/labels",
260+
"org": "/api/v2/orgs/0000000000000001",
261+
"self": "/api/v2/variables/6162207574726f71"
262+
},
263+
"name": "variable-a",
264+
"orgID": "0000000000000001",
265+
"selected": [
266+
"b"
267+
]
268+
}
269+
]
270+
}`,
169271
},
170272
},
171273
}
@@ -251,7 +353,7 @@ func TestVariableService_handleGetVariable(t *testing.T) {
251353
wants: wants{
252354
statusCode: 200,
253355
contentType: "application/json; charset=utf-8",
254-
body: `{"id":"75650d0a636f6d70","orgID":"0000000000000001","name":"variable-a","selected":["b"],"arguments":{"type":"constant","values":["a","b"]},"labels":[],"links":{"self":"/api/v2/variables/75650d0a636f6d70","labels":"/api/v2/variables/75650d0a636f6d70/labels","org":"/api/v2/orgs/0000000000000001"}}
356+
body: `{"id":"75650d0a636f6d70","orgID":"0000000000000001","name":"variable-a","description":"","selected":["b"],"arguments":{"type":"constant","values":["a","b"]},"labels":[],"links":{"self":"/api/v2/variables/75650d0a636f6d70","labels":"/api/v2/variables/75650d0a636f6d70/labels","org":"/api/v2/orgs/0000000000000001"}}
255357
`,
256358
},
257359
},
@@ -384,7 +486,7 @@ func TestVariableService_handlePostVariable(t *testing.T) {
384486
wants: wants{
385487
statusCode: 201,
386488
contentType: "application/json; charset=utf-8",
387-
body: `{"id":"75650d0a636f6d70","orgID":"0000000000000001","name":"my-great-variable","selected":["'foo'"],"arguments":{"type":"constant","values":["bar","foo"]},"labels":[],"links":{"self":"/api/v2/variables/75650d0a636f6d70","labels":"/api/v2/variables/75650d0a636f6d70/labels","org":"/api/v2/orgs/0000000000000001"}}
489+
body: `{"id":"75650d0a636f6d70","orgID":"0000000000000001","name":"my-great-variable","description":"","selected":["'foo'"],"arguments":{"type":"constant","values":["bar","foo"]},"labels":[],"links":{"self":"/api/v2/variables/75650d0a636f6d70","labels":"/api/v2/variables/75650d0a636f6d70/labels","org":"/api/v2/orgs/0000000000000001"}}
388490
`,
389491
},
390492
},
@@ -501,7 +603,7 @@ func TestVariableService_handlePatchVariable(t *testing.T) {
501603
wants: wants{
502604
statusCode: 200,
503605
contentType: "application/json; charset=utf-8",
504-
body: `{"id":"75650d0a636f6d70","orgID":"0000000000000002","name":"new-name","selected":[],"arguments":{"type":"constant","values":[]},"labels":[],"links":{"self":"/api/v2/variables/75650d0a636f6d70","labels":"/api/v2/variables/75650d0a636f6d70/labels","org":"/api/v2/orgs/0000000000000002"}}
606+
body: `{"id":"75650d0a636f6d70","orgID":"0000000000000002","name":"new-name","description":"","selected":[],"arguments":{"type":"constant","values":[]},"labels":[],"links":{"self":"/api/v2/variables/75650d0a636f6d70","labels":"/api/v2/variables/75650d0a636f6d70/labels","org":"/api/v2/orgs/0000000000000002"}}
505607
`,
506608
},
507609
},

variable.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Variable struct {
4747
ID ID `json:"id,omitempty"`
4848
OrganizationID ID `json:"orgID,omitempty"`
4949
Name string `json:"name"`
50+
Description string `json:"description"`
5051
Selected []string `json:"selected"`
5152
Arguments *VariableArguments `json:"arguments"`
5253
}
@@ -83,9 +84,10 @@ func (f VariableFilter) QueryParams() map[string][]string {
8384

8485
// A VariableUpdate describes a set of changes that can be applied to a Variable
8586
type VariableUpdate struct {
86-
Name string `json:"name"`
87-
Selected []string `json:"selected"`
88-
Arguments *VariableArguments `json:"arguments"`
87+
Name string `json:"name"`
88+
Selected []string `json:"selected"`
89+
Description string `json:"description"`
90+
Arguments *VariableArguments `json:"arguments"`
8991
}
9092

9193
// A VariableArguments contains arguments used when expanding a Variable
@@ -129,7 +131,7 @@ func (m *Variable) Valid() error {
129131

130132
// Valid returns an error if a Variable changeset is not valid
131133
func (u *VariableUpdate) Valid() error {
132-
if u.Name == "" && u.Selected == nil && u.Arguments == nil {
134+
if u.Name == "" && u.Description == "" && u.Selected == nil && u.Arguments == nil {
133135
return fmt.Errorf("no fields supplied in update")
134136
}
135137

@@ -150,6 +152,10 @@ func (u *VariableUpdate) Apply(m *Variable) error {
150152
m.Arguments = u.Arguments
151153
}
152154

155+
if u.Description != "" {
156+
m.Description = u.Description
157+
}
158+
153159
return nil
154160
}
155161

0 commit comments

Comments
 (0)