Bläddra i källkod

Ignore files/dashboards which name start with 'test'

Brendan Abolivier 6 år sedan
förälder
incheckning
343ad16b42
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
2 ändrade filer med 18 tillägg och 7 borttagningar
  1. 10
    3
      src/puller/puller.go
  2. 8
    4
      src/pusher/webhook.go

+ 10
- 3
src/puller/puller.go Visa fil

5
 	"encoding/json"
5
 	"encoding/json"
6
 	"io/ioutil"
6
 	"io/ioutil"
7
 	"os"
7
 	"os"
8
+	"strings"
8
 
9
 
9
 	"config"
10
 	"config"
10
 	"git"
11
 	"git"
19
 	newVersion int
20
 	newVersion int
20
 }
21
 }
21
 
22
 
22
-// PullGrafanaAndCommit pulls all the dashboards from Grafana then commits each
23
-// of them to Git except for those that have a newer or equal version number
24
-// already versionned in the repo
23
+// PullGrafanaAndCommit pulls all the dashboards from Grafana except the ones
24
+// which name/slug starts with "test", then commits each of them to Git except
25
+// for those that have a newer or equal version number already versionned in
26
+// the repo.
25
 func PullGrafanaAndCommit(client *grafana.Client, cfg *config.Config) error {
27
 func PullGrafanaAndCommit(client *grafana.Client, cfg *config.Config) error {
26
 	// Clone or pull the repo
28
 	// Clone or pull the repo
27
 	repo, err := git.Sync(cfg.Git)
29
 	repo, err := git.Sync(cfg.Git)
50
 
52
 
51
 	// Iterate over the dashboards URIs
53
 	// Iterate over the dashboards URIs
52
 	for _, uri := range uris {
54
 	for _, uri := range uris {
55
+		// Don't process any dashboard which name/slug starts with "test"
56
+		if strings.HasPrefix(uri, "db/test") {
57
+			continue
58
+		}
59
+
53
 		// Retrieve the dashboard JSON
60
 		// Retrieve the dashboard JSON
54
 		dashboard, err := client.GetDashboard(uri)
61
 		dashboard, err := client.GetDashboard(uri)
55
 		if err != nil {
62
 		if err != nil {

+ 8
- 4
src/pusher/webhook.go Visa fil

58
 			continue
58
 			continue
59
 		}
59
 		}
60
 
60
 
61
-		// Push all added files
61
+		// Push all added files, except the ones which name starts with "test"
62
 		for _, addedFile := range commit.Added {
62
 		for _, addedFile := range commit.Added {
63
-			filesToPush[addedFile] = true
63
+			if !strings.HasPrefix(addedFile, "test") {
64
+				filesToPush[addedFile] = true
65
+			}
64
 		}
66
 		}
65
 
67
 
66
-		// Push all modified files
68
+		// Push all modified files, except the ones which name starts with "test"
67
 		for _, modifiedFile := range commit.Modified {
69
 		for _, modifiedFile := range commit.Modified {
68
-			filesToPush[modifiedFile] = true
70
+			if !strings.HasPrefix(addedFile, "test") {
71
+				filesToPush[modifiedFile] = true
72
+			}
69
 		}
73
 		}
70
 
74
 
71
 		// TODO: Remove a dashboard when its file gets deleted?
75
 		// TODO: Remove a dashboard when its file gets deleted?