From 25fa7055119d5104d7d048c4adb9abc5fabda034 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 27 Oct 2015 13:03:37 -0700 Subject: [PATCH] added scm and deploy fields. plan to support hg, github deploys --- model/build.go | 1 + model/const.go | 7 +++++++ model/repo.go | 1 + remote/bitbucket/helper.go | 1 + remote/github/github.go | 4 ++++ remote/gogs/helper.go | 1 + store/migration/mysql/2.sql | 11 +++++++++++ store/migration/postgres/2.sql | 11 +++++++++++ store/migration/sqlite3/2.sql | 11 +++++++++++ 9 files changed, 48 insertions(+) create mode 100644 store/migration/mysql/2.sql create mode 100644 store/migration/postgres/2.sql create mode 100644 store/migration/sqlite3/2.sql diff --git a/model/build.go b/model/build.go index d72d0218d..fa794931b 100644 --- a/model/build.go +++ b/model/build.go @@ -10,6 +10,7 @@ type Build struct { Created int64 `json:"created_at" meddler:"build_created"` Started int64 `json:"started_at" meddler:"build_started"` Finished int64 `json:"finished_at" meddler:"build_finished"` + Deploy string `json:"deploy_to" meddler:"build_deploy"` Commit string `json:"commit" meddler:"build_commit"` Branch string `json:"branch" meddler:"build_branch"` Ref string `json:"ref" meddler:"build_ref"` diff --git a/model/const.go b/model/const.go index 8c5f48a6f..efac6b3bd 100644 --- a/model/const.go +++ b/model/const.go @@ -16,3 +16,10 @@ const ( StatusKilled = "killed" StatusError = "error" ) + +const ( + RepoGit = "git" + RepoHg = "hg" + RepoFossil = "fossil" + RepoPerforce = "perforce" +) diff --git a/model/repo.go b/model/repo.go index 923655f5e..e44af1a5d 100644 --- a/model/repo.go +++ b/model/repo.go @@ -15,6 +15,7 @@ type Repo struct { FullName string `json:"full_name" meddler:"repo_full_name"` Avatar string `json:"avatar_url" meddler:"repo_avatar"` Link string `json:"link_url" meddler:"repo_link"` + Kind string `json:"scm" meddler:"repo_scm"` Clone string `json:"clone_url" meddler:"repo_clone"` Branch string `json:"default_branch" meddler:"repo_branch"` Timeout int64 `json:"timeout" meddler:"repo_timeout"` diff --git a/remote/bitbucket/helper.go b/remote/bitbucket/helper.go index 6d44b8bbb..65605d8a4 100644 --- a/remote/bitbucket/helper.go +++ b/remote/bitbucket/helper.go @@ -17,6 +17,7 @@ func convertRepo(from *Repo) *model.Repo { Link: from.Links.Html.Href, IsPrivate: from.IsPrivate, Avatar: from.Owner.Links.Avatar.Href, + Kind: from.Scm, Branch: "master", } diff --git a/remote/github/github.go b/remote/github/github.go index b1e520dc6..bf9af9d7d 100644 --- a/remote/github/github.go +++ b/remote/github/github.go @@ -147,6 +147,7 @@ func (g *Github) Repo(u *model.User, owner, name string) (*model.Repo, error) { repo.Clone = *repo_.CloneURL repo.Branch = "master" repo.Avatar = *repo_.Owner.AvatarURL + repo.Kind = model.RepoGit if repo_.DefaultBranch != nil { repo.Branch = *repo_.DefaultBranch @@ -324,6 +325,7 @@ func (g *Github) push(r *http.Request) (*model.Repo, *model.Build, error) { repo.IsPrivate = hook.Repo.Private repo.Clone = hook.Repo.CloneURL repo.Branch = hook.Repo.DefaultBranch + repo.Kind = model.RepoGit build := &model.Build{} build.Event = model.EventPush @@ -384,6 +386,7 @@ func (g *Github) pullRequest(r *http.Request) (*model.Repo, *model.Build, error) repo.Link = *hook.Repo.HTMLURL repo.IsPrivate = *hook.Repo.Private repo.Clone = *hook.Repo.CloneURL + repo.Kind = model.RepoGit repo.Branch = "master" if hook.Repo.DefaultBranch != nil { repo.Branch = *hook.Repo.DefaultBranch @@ -425,6 +428,7 @@ func (g *Github) deployment(r *http.Request) (*model.Repo, *model.Build, error) repo.IsPrivate = hook.Repo.Private repo.Clone = hook.Repo.CloneURL repo.Branch = hook.Repo.DefaultBranch + repo.Kind = model.RepoGit // ref can be // branch, tag, or sha diff --git a/remote/gogs/helper.go b/remote/gogs/helper.go index f94f41f3f..4e06e70ce 100644 --- a/remote/gogs/helper.go +++ b/remote/gogs/helper.go @@ -37,6 +37,7 @@ func toRepo(from *gogs.Repository) *model.Repo { from.Owner.AvatarUrl, ) return &model.Repo{ + Kind: model.RepoGit, Name: name, Owner: from.Owner.UserName, FullName: from.FullName, diff --git a/store/migration/mysql/2.sql b/store/migration/mysql/2.sql new file mode 100644 index 000000000..0778e0062 --- /dev/null +++ b/store/migration/mysql/2.sql @@ -0,0 +1,11 @@ +-- +migrate Up + +ALTER TABLE repos ADD COLUMN repo_scm VARCHAR(25); +ALTER TABLE builds ADD COLUMN build_deploy VARCHAR(500); + +UPDATE repos SET repo_scm = 'git'; + +-- +migrate Down + +ALTER TABLE repos DROP COLUMN repo_scm; +ALTER TABLE builds DROP COLUMN build_deploy; diff --git a/store/migration/postgres/2.sql b/store/migration/postgres/2.sql new file mode 100644 index 000000000..0778e0062 --- /dev/null +++ b/store/migration/postgres/2.sql @@ -0,0 +1,11 @@ +-- +migrate Up + +ALTER TABLE repos ADD COLUMN repo_scm VARCHAR(25); +ALTER TABLE builds ADD COLUMN build_deploy VARCHAR(500); + +UPDATE repos SET repo_scm = 'git'; + +-- +migrate Down + +ALTER TABLE repos DROP COLUMN repo_scm; +ALTER TABLE builds DROP COLUMN build_deploy; diff --git a/store/migration/sqlite3/2.sql b/store/migration/sqlite3/2.sql new file mode 100644 index 000000000..49b4a4ecb --- /dev/null +++ b/store/migration/sqlite3/2.sql @@ -0,0 +1,11 @@ +-- +migrate Up + +ALTER TABLE repos ADD COLUMN repo_scm TEXT; +ALTER TABLE builds ADD COLUMN build_deploy TEXT; + +UPDATE repos SET repo_scm = 'git'; + +-- +migrate Down + +ALTER TABLE repos DROP COLUMN repo_scm; +ALTER TABLE builds DROP COLUMN build_deploy;