Kaynağa Gözat

Add commits author config to config file

Brendan Abolivier 6 yıl önce
ebeveyn
işleme
fcc253cb7b
İmzalayan: Brendan Abolivier <contact@brendanabolivier.com> GPC anahtar kimliği: 8EF1500759F70623

+ 6
- 0
config.example.yaml Dosyayı Görüntüle

@@ -22,6 +22,12 @@ git:
22 22
     # directory doesn't exist, it will be created and the repository will be
23 23
     # cloned into it.
24 24
     clone_path: /tmp/grafana-dashboards
25
+    # Author of the commit created in the puller.
26
+    commits_author:
27
+        # Author's name.
28
+        name: Grafana Dashboard Manager
29
+        # Author's email.
30
+        email: grafana-dashboard-manager@company.tld
25 31
 
26 32
 # Settings to configure the Git webhook. Currently only GitLab webhooks are
27 33
 # supported.

+ 12
- 4
src/config/config.go Dosyayı Görüntüle

@@ -22,10 +22,18 @@ type GrafanaSettings struct {
22 22
 
23 23
 // GitSettings contains the data required to interact with the Git repository.
24 24
 type GitSettings struct {
25
-	URL            string `yaml:"url"`
26
-	User           string `yaml:"user"`
27
-	PrivateKeyPath string `yaml:"private_key"`
28
-	ClonePath      string `yaml:"clone_path"`
25
+	URL            string              `yaml:"url"`
26
+	User           string              `yaml:"user"`
27
+	PrivateKeyPath string              `yaml:"private_key"`
28
+	ClonePath      string              `yaml:"clone_path"`
29
+	CommitsAuthor  CommitsAuthorConfig `yaml:"commits_author"`
30
+}
31
+
32
+// CommitsAuthorConfig contains the configuration (name + email address) to use
33
+// when commiting to Git.
34
+type CommitsAuthorConfig struct {
35
+	Name  string `yaml:"name"`
36
+	Email string `yaml:"email"`
29 37
 }
30 38
 
31 39
 // WebhookSettings contains the data required to setup the GitLab webhook.

+ 1
- 3
src/puller/puller.go Dosyayı Görüntüle

@@ -87,9 +87,7 @@ func PullGrafanaAndCommit(client *grafana.Client, cfg *config.Config) error {
87 87
 
88 88
 	// Check if there's uncommited changes, and if that's the case, commit them.
89 89
 	if !status.IsClean() {
90
-		if err = commitNewVersions(
91
-			dbVersions, dv, w, cfg.Git.ClonePath,
92
-		); err != nil {
90
+		if err = commitNewVersions(dbVersions, dv, w, cfg); err != nil {
93 91
 			return err
94 92
 		}
95 93
 	}

+ 6
- 4
src/puller/versions.go Dosyayı Görüntüle

@@ -7,6 +7,8 @@ import (
7 7
 	"os"
8 8
 	"time"
9 9
 
10
+	"config"
11
+
10 12
 	gogit "gopkg.in/src-d/go-git.v4"
11 13
 	"gopkg.in/src-d/go-git.v4/plumbing/object"
12 14
 )
@@ -71,9 +73,9 @@ func writeVersions(
71 73
 // file, adding it to the index or creating the commit.
72 74
 func commitNewVersions(
73 75
 	versions map[string]int, dv map[string]diffVersion, worktree *gogit.Worktree,
74
-	clonePath string,
76
+	cfg *config.Config,
75 77
 ) (err error) {
76
-	if err = writeVersions(versions, dv, clonePath); err != nil {
78
+	if err = writeVersions(versions, dv, cfg.Git.ClonePath); err != nil {
77 79
 		return err
78 80
 	}
79 81
 
@@ -83,8 +85,8 @@ func commitNewVersions(
83 85
 
84 86
 	_, err = worktree.Commit(getCommitMessage(dv), &gogit.CommitOptions{
85 87
 		Author: &object.Signature{
86
-			Name:  "Grafana Dashboard Manager",
87
-			Email: "grafana@cozycloud.cc",
88
+			Name:  cfg.Git.CommitsAuthor.Name,
89
+			Email: cfg.Git.CommitsAuthor.Email,
88 90
 			When:  time.Now(),
89 91
 		},
90 92
 	})

+ 1
- 1
src/pusher/webhook.go Dosyayı Görüntüle

@@ -30,7 +30,7 @@ func HandlePush(payload interface{}, header webhooks.Header) {
30 30
 	var err error
31 31
 	for _, commit := range pl.Commits {
32 32
 		// We don't want to process commits made by the puller
33
-		if commit.Author.Email == "grafana@cozycloud.cc" {
33
+		if commit.Author.Email == cfg.Git.CommitsAuthor.Email {
34 34
 			continue
35 35
 		}
36 36