From 6246b32569b6be538c6576334e2d555ed689f9ac Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sun, 19 Mar 2017 16:44:57 +0800 Subject: [PATCH 1/2] ability to customize yaml path --- model/config.go | 2 -- server/build.go | 6 ++---- server/hook.go | 5 ++--- server/repo.go | 1 + store/datastore/ddl/mysql/12.sql | 2 +- store/datastore/ddl/postgres/12.sql | 2 +- store/datastore/ddl/sqlite3/12.sql | 2 +- 7 files changed, 8 insertions(+), 12 deletions(-) diff --git a/model/config.go b/model/config.go index 393d5e3ba..76c3f7d49 100644 --- a/model/config.go +++ b/model/config.go @@ -3,8 +3,6 @@ package model // Config defines system configuration parameters. type Config struct { Open bool // Enables open registration - Yaml string // Customize the Yaml configuration file name - Shasum string // Customize the Yaml checksum file name Secret string // Secret token used to authenticate agents Admins map[string]bool // Administrative users Orgs map[string]bool // Organization whitelist diff --git a/server/build.go b/server/build.go index 0028e95d0..9249d1b4f 100644 --- a/server/build.go +++ b/server/build.go @@ -188,8 +188,7 @@ func PostApproval(c *gin.Context) { // // fetch the build file from the database - cfg := ToConfig(c) - raw, err := remote_.File(user, repo, build, cfg.Yaml) + raw, err := remote_.File(user, repo, build, repo.Config) if err != nil { logrus.Errorf("failure to get build config for %s. %s", repo.FullName, err) c.AbortWithError(404, err) @@ -398,8 +397,7 @@ func PostBuild(c *gin.Context) { } // fetch the .drone.yml file from the database - cfg := ToConfig(c) - raw, err := remote_.File(user, repo, build, cfg.Yaml) + raw, err := remote_.File(user, repo, build, repo.Config) if err != nil { logrus.Errorf("failure to get build config for %s. %s", repo.FullName, err) c.AbortWithError(404, err) diff --git a/server/hook.go b/server/hook.go index 42f30f383..15f03c55c 100644 --- a/server/hook.go +++ b/server/hook.go @@ -132,8 +132,7 @@ func PostHook(c *gin.Context) { } // fetch the build file from the database - cfg := ToConfig(c) - raw, err := remote_.File(user, repo, build, cfg.Yaml) + raw, err := remote_.File(user, repo, build, repo.Config) if err != nil { logrus.Errorf("failure to get build config for %s. %s", repo.FullName, err) c.AbortWithError(404, err) @@ -177,7 +176,7 @@ func PostHook(c *gin.Context) { } if build.Event == model.EventPull && mustApprove { - old, ferr := remote_.FileRef(user, repo, build.Branch, cfg.Yaml) + old, ferr := remote_.FileRef(user, repo, build.Branch, repo.Config) if ferr != nil { build.Status = model.StatusBlocked logrus.Debugf("cannot fetch base yaml: status: blocked") diff --git a/server/repo.go b/server/repo.go index 2a089e0b2..14d693c5d 100644 --- a/server/repo.go +++ b/server/repo.go @@ -54,6 +54,7 @@ func PostRepo(c *gin.Context) { r.UserID = user.ID r.AllowPush = true r.AllowPull = true + r.Config = ".drone.yml" r.Timeout = 60 // 1 hour default build time r.Hash = base32.StdEncoding.EncodeToString( securecookie.GenerateRandomKey(32), diff --git a/store/datastore/ddl/mysql/12.sql b/store/datastore/ddl/mysql/12.sql index 39db95002..06a00e332 100644 --- a/store/datastore/ddl/mysql/12.sql +++ b/store/datastore/ddl/mysql/12.sql @@ -5,7 +5,7 @@ ALTER TABLE builds ADD COLUMN build_sender VARCHAR(255); ALTER TABLE builds ADD COLUMN build_reviewer VARCHAR(255); ALTER TABLE builds ADD COLUMN build_reviewed INTEGER; -UPDATE repos SET repo_config_path = ''; +UPDATE repos SET repo_config_path = '.drone.yml'; UPDATE builds SET build_reviewer = ''; UPDATE builds SET build_reviewed = 0; UPDATE builds SET build_sender = ''; diff --git a/store/datastore/ddl/postgres/12.sql b/store/datastore/ddl/postgres/12.sql index d55f2ae56..04b82a6df 100644 --- a/store/datastore/ddl/postgres/12.sql +++ b/store/datastore/ddl/postgres/12.sql @@ -5,7 +5,7 @@ ALTER TABLE builds ADD COLUMN build_reviewer VARCHAR(255); ALTER TABLE builds ADD COLUMN build_reviewed INTEGER; ALTER TABLE builds ADD COLUMN build_sender VARCHAR(255); -UPDATE repos SET repo_config_path = ''; +UPDATE repos SET repo_config_path = '.drone.yml'; UPDATE builds SET build_reviewer = ''; UPDATE builds SET build_reviewed = 0; UPDATE builds SET build_sender = ''; diff --git a/store/datastore/ddl/sqlite3/12.sql b/store/datastore/ddl/sqlite3/12.sql index 4392c850e..c641eec9d 100644 --- a/store/datastore/ddl/sqlite3/12.sql +++ b/store/datastore/ddl/sqlite3/12.sql @@ -5,7 +5,7 @@ ALTER TABLE builds ADD COLUMN build_reviewer TEXT; ALTER TABLE builds ADD COLUMN build_reviewed INTEGER; ALTER TABLE builds ADD COLUMN build_sender TEXT; -UPDATE repos SET repo_config_path = ''; +UPDATE repos SET repo_config_path = '.drone.yml'; UPDATE builds SET build_reviewer = ''; UPDATE builds SET build_reviewed = 0; UPDATE builds SET build_sender = ''; From b6321a41373e583ad48ceedcc960814c3c3c35a9 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sun, 19 Mar 2017 16:51:12 +0800 Subject: [PATCH 2/2] remove sha and yaml global variables --- model/repo.go | 2 +- router/middleware/config.go | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/model/repo.go b/model/repo.go index 7e881b96b..1b20eb705 100644 --- a/model/repo.go +++ b/model/repo.go @@ -29,6 +29,6 @@ type Repo struct { AllowPush bool `json:"allow_push" meddler:"repo_allow_push"` AllowDeploy bool `json:"allow_deploys" meddler:"repo_allow_deploys"` AllowTag bool `json:"allow_tags" meddler:"repo_allow_tags"` - Config string `json:"config_path" meddler:"repo_config_path"` + Config string `json:"config_file" meddler:"repo_config_path"` Hash string `json:"-" meddler:"repo_hash"` } diff --git a/router/middleware/config.go b/router/middleware/config.go index 54b1cbb0b..e38e79d7a 100644 --- a/router/middleware/config.go +++ b/router/middleware/config.go @@ -22,8 +22,6 @@ func Config(cli *cli.Context) gin.HandlerFunc { func setupConfig(c *cli.Context) *model.Config { return &model.Config{ Open: c.Bool("open"), - Yaml: c.String("yaml"), - Shasum: c.String("yaml") + ".sig", Secret: c.String("agent-secret"), Admins: sliceToMap(c.StringSlice("admin")), Orgs: sliceToMap(c.StringSlice("orgs")),