Skip to content

Commit f1ef4c8

Browse files
Validate: add ability to check if code insights works on an instance (#912)
* wip: add a validation check for being able to create insights * validate: adjust required yaml inputs for creating an Insight * validate: fixed missing common in json * Update CHANGELOG.md Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com> Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com>
1 parent ed6a481 commit f1ef4c8

File tree

2 files changed

+84
-2
lines changed

2 files changed

+84
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
All notable changes to `src-cli` are documented in this file.
1111

1212
## Unreleased
13-
13+
* `src validate` has an added check to determine if an instance is able to create a basic code insight.
1414
### Added
1515

1616
### Changed

cmd/src/validate.go

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ type validationSpec struct {
4242
Config map[string]interface{} `yaml:"config"`
4343
DeleteWhenDone bool `yaml:"deleteWhenDone"`
4444
} `yaml:"externalService"`
45+
CreateInsight struct {
46+
Title string `yaml:"title"`
47+
DataSeries []map[string]interface{} `yaml:"dataSeries"`
48+
} `yaml:"createInsight"`
4549
}
4650

4751
type validator struct {
@@ -68,7 +72,28 @@ const defaultVspec = `{
6872
"maxTries": 5,
6973
"sleepBetweenTriesSeconds": 5
7074
},
71-
"searchQuery": ["repo:^github.com/gorilla/mux$ Router", "repo:^github.com/gorilla/mux$@v1.8.0 Router"]
75+
"searchQuery": ["repo:^github.com/gorilla/mux$ Router", "repo:^github.com/gorilla/mux$@v1.8.0 Router"],
76+
"createInsight": {
77+
"title": "test insight",
78+
"dataSeries": [
79+
{
80+
"query": "lang:javascript",
81+
"label": "javascript",
82+
"repositoryScope": [],
83+
"lineColor": "#6495ED",
84+
"timeScopeUnit": "MONTH",
85+
"timeScopeValue": 1
86+
},
87+
{
88+
"query": "lang:typescript",
89+
"label": "typescript",
90+
"lineColor": "#DE3163",
91+
"repositoryScope": [],
92+
"timeScopeUnit": "MONTH",
93+
"timeScopeValue": 1
94+
}
95+
]
96+
}
7297
}`
7398

7499
func init() {
@@ -275,6 +300,15 @@ func (vd *validator) validate(script []byte, scriptContext map[string]string, is
275300
}
276301
}
277302

303+
if vspec.CreateInsight.Title != "" {
304+
id, err := vd.createInsight(vspec.CreateInsight.Title, vspec.CreateInsight.DataSeries)
305+
if err != nil {
306+
return err
307+
}
308+
309+
fmt.Printf("insight %s(%s) is being added \n", vspec.CreateInsight.Title, id)
310+
}
311+
278312
return nil
279313
}
280314

@@ -406,6 +440,54 @@ func (vd *validator) waitRepoCloned(repoName string, sleepSeconds int, maxTries
406440
return false, nil
407441
}
408442

443+
const vdAddCodeInsight = `
444+
mutation CreateLineChartSearchInsight($input: LineChartSearchInsightInput!) {
445+
createLineChartSearchInsight(input: $input) {
446+
view {
447+
id
448+
}
449+
}
450+
}`
451+
452+
func (vd *validator) createInsight(title string, dataseries []map[string]interface{}) (string, error) {
453+
var resp struct {
454+
CreateLineChartSearchInsight struct {
455+
View struct {
456+
ID string `json:"id"`
457+
} `json:"view"`
458+
} `json:"createLineChartSearchInsight"`
459+
}
460+
var ds []map[string]interface{}
461+
for _, d := range dataseries {
462+
var series = map[string]interface{}{
463+
"query": d["query"],
464+
"options": map[string]interface{}{
465+
"label": d["label"],
466+
"lineColor": d["lineColor"],
467+
},
468+
"repositoryScope": map[string]interface{}{
469+
"repositories": d["repositoryScope"],
470+
},
471+
"timeScope": map[string]interface{}{
472+
"stepInterval": map[string]interface{}{
473+
"unit": d["timeScopeUnit"],
474+
"value": d["timeScopeValue"],
475+
},
476+
},
477+
}
478+
ds = append(ds, series)
479+
}
480+
err := vd.graphQL(vdAddCodeInsight,
481+
map[string]interface{}{"input": map[string]interface{}{
482+
"options": map[string]interface{}{"title": title},
483+
"dataSeries": ds}}, &resp)
484+
if err != nil {
485+
return "", err
486+
}
487+
488+
return resp.CreateLineChartSearchInsight.View.ID, nil
489+
}
490+
409491
const vdUserQuery = `
410492
query User($username: String) {
411493
user(username: $username) {

0 commit comments

Comments
 (0)