2014-06-04 21:25:38 +00:00
|
|
|
package repo
|
|
|
|
|
2014-06-12 00:42:49 +00:00
|
|
|
import (
|
|
|
|
"gopkg.in/yaml.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
DefaultBranch = "master"
|
2014-06-04 21:25:38 +00:00
|
|
|
|
2014-06-12 00:42:49 +00:00
|
|
|
// default build timeout, in seconds
|
|
|
|
DefaultTimeout int64 = 7200
|
|
|
|
)
|
2014-06-04 21:25:38 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
HostGitlab = "gitlab.com"
|
|
|
|
HostGithub = "github.com"
|
|
|
|
HostGithubEnterprise = "enterprise.github.com"
|
|
|
|
HostBitbucket = "bitbucket.org"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Repo struct {
|
|
|
|
ID int64 `meddler:"repo_id,pk" json:"-"`
|
|
|
|
UserID int64 `meddler:"user_id" json:"-"`
|
|
|
|
Remote string `meddler:"repo_remote" json:"remote"`
|
2014-06-05 22:04:59 +00:00
|
|
|
Host string `meddler:"repo_host" json:"host"`
|
2014-06-04 21:25:38 +00:00
|
|
|
Owner string `meddler:"repo_owner" json:"owner"`
|
|
|
|
Name string `meddler:"repo_name" json:"name"`
|
|
|
|
|
2014-06-05 22:04:59 +00:00
|
|
|
URL string `meddler:"repo_url" json:"url"`
|
|
|
|
CloneURL string `meddler:"repo_clone_url" json:"clone_url"`
|
|
|
|
GitURL string `meddler:"repo_git_url" json:"git_url"`
|
|
|
|
SSHURL string `meddler:"repo_ssh_url" json:"ssh_url"`
|
2014-06-04 21:25:38 +00:00
|
|
|
|
|
|
|
Active bool `meddler:"repo_active" json:"active"`
|
|
|
|
Private bool `meddler:"repo_private" json:"private"`
|
|
|
|
Privileged bool `meddler:"repo_privileged" json:"privileged"`
|
|
|
|
PostCommit bool `meddler:"repo_post_commit" json:"post_commits"`
|
|
|
|
PullRequest bool `meddler:"repo_pull_request" json:"pull_requests"`
|
|
|
|
PublicKey string `meddler:"repo_public_key" json:"-"`
|
|
|
|
PrivateKey string `meddler:"repo_private_key" json:"-"`
|
|
|
|
Params string `meddler:"repo_params" json:"-"`
|
|
|
|
Timeout int64 `meddler:"repo_timeout" json:"timeout"`
|
|
|
|
Created int64 `meddler:"repo_created" json:"created_at"`
|
|
|
|
Updated int64 `meddler:"repo_updated" json:"updated_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGithub(owner, name string) (*Repo, error) {
|
|
|
|
return New(HostGithub, owner, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGithubEnterprise(owner, name string) (*Repo, error) {
|
|
|
|
return New(HostGithubEnterprise, owner, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGitlab(owner, name string) (*Repo, error) {
|
|
|
|
return New(HostGitlab, owner, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewBitbucket(owner, name string) (*Repo, error) {
|
|
|
|
return New(HostBitbucket, owner, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(remote, owner, name string) (*Repo, error) {
|
|
|
|
repo := Repo{}
|
|
|
|
repo.Remote = remote
|
|
|
|
repo.Owner = owner
|
|
|
|
repo.Name = name
|
|
|
|
repo.Active = false
|
|
|
|
repo.PostCommit = true
|
|
|
|
repo.PullRequest = true
|
|
|
|
repo.Timeout = DefaultTimeout
|
|
|
|
return &repo, nil
|
|
|
|
}
|
2014-06-12 00:42:49 +00:00
|
|
|
|
|
|
|
func (r *Repo) ParamMap() (map[string]string, error) {
|
|
|
|
out := map[string]string{}
|
|
|
|
err := yaml.Unmarshal([]byte(r.Params), out)
|
|
|
|
return out, err
|
|
|
|
}
|