소스 검색

Ignore files/dashboards which name start with 'test'

Brendan Abolivier 6 년 전
부모
커밋
343ad16b42
로그인 계정: Brendan Abolivier <contact@brendanabolivier.com> GPG 키 ID: 8EF1500759F70623
2개의 변경된 파일18개의 추가작업 그리고 7개의 파일을 삭제
  1. 10
    3
      src/puller/puller.go
  2. 8
    4
      src/pusher/webhook.go

+ 10
- 3
src/puller/puller.go 파일 보기

@@ -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 파일 보기

@@ -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?