Przeglądaj źródła

Ignore files/dashboards which name start with 'test'

Brendan Abolivier 6 lat temu
rodzic
commit
343ad16b42
Podpisane przez: Brendan Abolivier <contact@brendanabolivier.com> ID klucza GPG: 8EF1500759F70623
2 zmienionych plików z 18 dodań i 7 usunięć
  1. 10
    3
      src/puller/puller.go
  2. 8
    4
      src/pusher/webhook.go

+ 10
- 3
src/puller/puller.go Wyświetl plik

@@ -5,6 +5,7 @@ import (
5 5
 	"encoding/json"
6 6
 	"io/ioutil"
7 7
 	"os"
8
+	"strings"
8 9
 
9 10
 	"config"
10 11
 	"git"
@@ -19,9 +20,10 @@ type diffVersion struct {
19 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 27
 func PullGrafanaAndCommit(client *grafana.Client, cfg *config.Config) error {
26 28
 	// Clone or pull the repo
27 29
 	repo, err := git.Sync(cfg.Git)
@@ -50,6 +52,11 @@ func PullGrafanaAndCommit(client *grafana.Client, cfg *config.Config) error {
50 52
 
51 53
 	// Iterate over the dashboards URIs
52 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 60
 		// Retrieve the dashboard JSON
54 61
 		dashboard, err := client.GetDashboard(uri)
55 62
 		if err != nil {

+ 8
- 4
src/pusher/webhook.go Wyświetl plik

@@ -58,14 +58,18 @@ func HandlePush(payload interface{}, header webhooks.Header) {
58 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 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 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 75
 		// TODO: Remove a dashboard when its file gets deleted?