model

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2014 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusNone    = "None"
	StatusEnqueue = "Pending"
	StatusStarted = "Started"
	StatusSuccess = "Success"
	StatusFailure = "Failure"
	StatusError   = "Error"
)
View Source
const (
	// Owners can add / remove team members, create / delete projects,
	// and have rwx access to all projects owned by the team.
	RoleOwner = "Owner"

	// Admins can create / delete projects and have rwx acess
	// to all projects owned by the team.
	RoleAdmin = "Admin"

	// Write members have rwx access to all projects
	// owned by the team. They may not create new projects.
	RoleWrite = "Write"

	// Read members have readonly access to all projects
	// owned by the team.
	RoleRead = "Read"
)
View Source
const (
	ScmGit = "git"
	ScmHg  = "hg"
	ScmSvn = "svn"
)
View Source
const (
	HostBitbucket = "bitbucket.org"
	HostGoogle    = "code.google.com"
	HostCustom    = "custom"
)
View Source
const (
	DefaultBranchGit = "master"
	DefaultBranchHg  = "default"
	DefaultBranchSvn = "trunk"
)
View Source
const (
	RSA_BITS     = 2048 // Default number of bits in an RSA key
	RSA_BITS_MIN = 768  // Minimum number of bits in an RSA key
)

Variables

View Source
var (
	ErrInvalidGitHubTrailingSlash = errors.New("GitHub URL should not have a trailing slash")
	ErrInvalidSmtpAddress         = errors.New("SMTP From Address must be provided")
	ErrInvalidSmtpPort            = errors.New("SMTP Port must be provided")
)
View Source
var (
	ErrInvalidUserName = errors.New("Invalid User Name")
	ErrInvalidPassword = errors.New("Invalid Password")
	ErrInvalidEmail    = errors.New("Invalid Email Address")
)
View Source
var ErrInvalidTeamName = errors.New("Invalid Team Name")

ErrInvalidTeamName is returned by the Team validation function when a team name is invalid.

View Source
var GravatarPattern = "https://gravatar.com/avatar/%s?s=%v&d=identicon"

Gravatar URL pattern

View Source
var RegexpEmail = regexp.MustCompile(`^[^@]+@[^@.]+\.[^@.]+`)

Simple regular expression used to verify that an email address matches the expected standard format.

Functions

This section is empty.

Types

type Build

type Build struct {
	ID          int64     `meddler:"id,pk"            json:"id"`
	CommitID    int64     `meddler:"commit_id"        json:"-"`
	Slug        string    `meddler:"slug"             json:"slug"`
	Status      string    `meddler:"status"           json:"status"`
	Started     time.Time `meddler:"started,utctime"  json:"started"`
	Finished    time.Time `meddler:"finished,utctime" json:"finished"`
	Duration    int64     `meddler:"duration"         json:"duration"`
	Created     time.Time `meddler:"created,utctime"  json:"created"`
	Updated     time.Time `meddler:"updated,utctime"  json:"updated"`
	Stdout      string    `meddler:"stdout"           json:"-"`
	BuildScript string    `meddler:"buildscript"      json:"-"`
}

func (*Build) FinishedString

func (b *Build) FinishedString() string

Returns the Started Date as an ISO8601 formatted string.

func (*Build) HumanDuration

func (b *Build) HumanDuration() string

HumanDuration returns a human-readable approximation of a duration (eg. "About a minute", "4 hours ago", etc.)

func (*Build) IsRunning

func (b *Build) IsRunning() bool

Returns true if the Build statis is Started or Pending, indicating it is currently running.

func (*Build) StartedString

func (b *Build) StartedString() string

Returns the Started Date as an ISO8601 formatted string.

type Commit

type Commit struct {
	ID          int64     `meddler:"id,pk"            json:"id"`
	RepoID      int64     `meddler:"repo_id"          json:"-"`
	Status      string    `meddler:"status"           json:"status"`
	Started     time.Time `meddler:"started,utctime"  json:"started"`
	Finished    time.Time `meddler:"finished,utctime" json:"finished"`
	Duration    int64     `meddler:"duration"         json:"duration"`
	Hash        string    `meddler:"hash"             json:"hash"`
	Branch      string    `meddler:"branch"           json:"branch"`
	PullRequest string    `meddler:"pull_request"     json:"pull_request"`
	Author      string    `meddler:"author"           json:"author"`
	Gravatar    string    `meddler:"gravatar"         json:"gravatar"`
	Timestamp   string    `meddler:"timestamp"        json:"timestamp"`
	Message     string    `meddler:"message"          json:"message"`

	Created time.Time `meddler:"created,utctime"  json:"created"`
	Updated time.Time `meddler:"updated,utctime"  json:"updated"`
}

func (*Commit) CreatedString

func (c *Commit) CreatedString() string

Returns the Created Date as an ISO8601 formatted string.

func (*Commit) FinishedString

func (c *Commit) FinishedString() string

Returns the Started Date as an ISO8601 formatted string.

func (*Commit) HashShort

func (c *Commit) HashShort() string

Returns the Short (--short) Commit Hash.

func (*Commit) Image

func (c *Commit) Image() string

Returns the Gravatar Image URL.

func (*Commit) ImageLarge

func (c *Commit) ImageLarge() string

func (*Commit) ImageSmall

func (c *Commit) ImageSmall() string

func (*Commit) SetAuthor

func (c *Commit) SetAuthor(email string)

Set the Author's email address and calculate the Gravatar hash.

func (*Commit) StartedString

func (c *Commit) StartedString() string

Returns the Started Date as an ISO8601 formatted string.

type Member

type Member struct {
	ID       int64  `meddler:"user_id"`
	Name     string `meddler:"name"`
	Email    string `meddler:"email"`
	Gravatar string `meddler:"gravatar"`
	Role     string `meddler:"role"`
}

func (*Member) Image

func (m *Member) Image() string

Returns the Gravatar Image URL.

func (*Member) ImageLarge

func (m *Member) ImageLarge() string

func (*Member) ImageSmall

func (m *Member) ImageSmall() string

type Repo

type Repo struct {
	ID int64 `meddler:"id,pk" json:"id"`

	// the full, canonical name of the repository, for example:
	// github.com/bradrydzewski/go.stripe
	Slug string `meddler:"slug" json:"slug"`

	// the hosting service where the repository is stored,
	// such as github.com, bitbucket.org, etc
	Host string `meddler:"host" json:"host"`

	// the owner of the repository on the host system.
	// for example, the Github username.
	Owner string `meddler:"owner" json:"owner"`

	// URL-friendly version of a repository name on the
	// host system.
	Name string `meddler:"name" json:"name"`

	// A value of True indicates the repository is closed source,
	// while a value of False indicates the project is open source.
	Private bool `meddler:"private" json:"private"`

	// A value of True indicates the repository is disabled and
	// no builds should be executed
	Disabled bool `meddler:"disabled" json:"disabled"`

	// A value of True indicates that pull requests are disabled
	// for the repository and no builds will be executed
	DisabledPullRequest bool `meddler:"disabled_pr" json:"disabled_pr"`

	// indicates the type of repository, such as
	// Git, Mercurial, Subversion or Bazaar.
	SCM string `meddler:"scm" json:"scm"`

	// the repository URL, for example:
	// git://github.com/bradrydzewski/go.stripe.git
	URL string `meddler:"url" json:"url"`

	// username and password requires to authenticate
	// to the repository
	Username string `meddler:"username" json:"username"`
	Password string `meddler:"password" json:"password"`

	// RSA key pair that will injected into the virtual machine
	// .ssh/id_rsa and .ssh/id_rsa.pub files.
	PublicKey  string `meddler:"public_key"  json:"public_key"`
	PrivateKey string `meddler:"private_key" json:"public_key"`

	// Parameters stored external to the repository in YAML
	// format, injected into the Build YAML at runtime.
	Params map[string]string `meddler:"params,gob" json:"-"`

	// the amount of time, in seconds the build will execute
	// before exceeding its timelimit and being killed.
	Timeout int64 `meddler:"timeout" json:"timeout"`

	// Indicates the build should be executed in privileged
	// mode. This could, for example, be used to run Docker in Docker.
	Privileged bool `meddler:"privileged" json:"privileged"`

	// Foreign keys signify the User that created
	// the repository and team account linked to
	// the repository.
	UserID int64 `meddler:"user_id"  json:"user_id"`
	TeamID int64 `meddler:"team_id"  json:"team_id"`

	Created time.Time `meddler:"created,utctime" json:"created"`
	Updated time.Time `meddler:"updated,utctime" json:"updated"`
}

func NewBitbucketRepo

func NewBitbucketRepo(owner, name string, private bool) (*Repo, error)

Creates a new Bitbucket repository

func NewGitHubRepo

func NewGitHubRepo(domain, owner, name string, private bool) (*Repo, error)

Creates a new GitHub repository

func NewRepo

func NewRepo(host, owner, name, scm, url string) (*Repo, error)

Creates a new repository

func (*Repo) DefaultBranch

func (r *Repo) DefaultBranch() string

type RepoCommit

type RepoCommit struct {
	// Repo Details
	Slug  string `meddler:"slug"  json:"slug"`
	Host  string `meddler:"host"  json:"host"`
	Owner string `meddler:"owner" json:"owner"`
	Name  string `meddler:"name"  json:"name"`

	// Commit Details
	Status      string    `meddler:"status"           json:"status"`
	Started     time.Time `meddler:"started,utctime"  json:"started"`
	Finished    time.Time `meddler:"finished,utctime" json:"finished"`
	Duration    int64     `meddler:"duration"         json:"duration"`
	Hash        string    `meddler:"hash"             json:"hash"`
	Branch      string    `meddler:"branch"           json:"branch"`
	PullRequest string    `meddler:"pull_request"     json:"pull_request"`
	Author      string    `meddler:"author"           json:"author"`
	Gravatar    string    `meddler:"gravatar"         json:"gravatar"`
	Timestamp   string    `meddler:"timestamp"        json:"timestamp"`
	Message     string    `meddler:"message"          json:"message"`
	Created     time.Time `meddler:"created,utctime"  json:"created"`
	Updated     time.Time `meddler:"updated,utctime"  json:"updated"`
}

Combined Repository and Commit details

func (*RepoCommit) CreatedString

func (c *RepoCommit) CreatedString() string

Returns the Created Date as an ISO8601 formatted string.

func (*RepoCommit) FinishedString

func (c *RepoCommit) FinishedString() string

Returns the Started Date as an ISO8601 formatted string.

func (*RepoCommit) HashShort

func (c *RepoCommit) HashShort() string

Returns the Short (--short) Commit Hash.

func (*RepoCommit) Image

func (c *RepoCommit) Image() string

Returns the Gravatar Image URL.

func (*RepoCommit) ImageLarge

func (c *RepoCommit) ImageLarge() string

func (*RepoCommit) ImageSmall

func (c *RepoCommit) ImageSmall() string

func (*RepoCommit) StartedString

func (c *RepoCommit) StartedString() string

Returns the Started Date as an ISO8601 formatted string.

type Role

type Role struct {
	ID     int64  `meddler:"id,pk"`
	TeamID int64  `meddler:"team_id"`
	UserID int64  `meddler:"user_id"`
	Role   string `meddler:"role"`
}

type Settings

type Settings struct {
	ID int64 `meddler:"id,pk"`

	// SMTP settings.
	SmtpServer   string `meddler:"smtp_server"`
	SmtpPort     string `meddler:"smtp_port"`
	SmtpAddress  string `meddler:"smtp_address"`
	SmtpUsername string `meddler:"smtp_username"`
	SmtpPassword string `meddler:"smtp_password"`

	// GitHub Consumer key and secret.
	GitHubKey    string `meddler:"github_key"`
	GitHubSecret string `meddler:"github_secret"`
	GitHubDomain string `meddler:"github_domain"`
	GitHubApiUrl string `meddler:"github_apiurl"`

	// Bitbucket Consumer Key and secret.
	BitbucketKey    string `meddler:"bitbucket_key"`
	BitbucketSecret string `meddler:"bitbucket_secret"`

	// GitLab Domain
	GitlabDomain string `meddler:"gitlab_domain"`
	GitlabApiUrl string `meddler:"gitlab_apiurl"`

	// Domain of the server, eg drone.io
	Domain string `meddler:"hostname"`

	// Scheme of the server, eg https
	Scheme string `meddler:"scheme"`

	OpenInvitations bool `meddler:"open_invitations"`
}

func (*Settings) URL

func (s *Settings) URL() *url.URL

func (*Settings) Validate

func (s *Settings) Validate() error

Validate verifies all required fields are correctly populated.

type Team

type Team struct {
	ID       int64     `meddler:"id,pk"           json:"id"`
	Slug     string    `meddler:"slug"            json:"slug"`
	Name     string    `meddler:"name"            json:"name"`
	Email    string    `meddler:"email"           json:"email"`
	Gravatar string    `meddler:"gravatar"        json:"gravatar"`
	Created  time.Time `meddler:"created,utctime" json:"created"`
	Updated  time.Time `meddler:"updated,utctime" json:"updated"`
}

func NewTeam

func NewTeam(name, email string) *Team

Creates a new team with the specified email address, and team name.

func (*Team) Image

func (t *Team) Image() string

Returns the Gravatar Image URL.

func (*Team) ImageLarge

func (t *Team) ImageLarge() string

func (*Team) ImageSmall

func (t *Team) ImageSmall() string

func (*Team) SetEmail

func (t *Team) SetEmail(email string)

Set the email address and calculate the Gravatar hash.

func (*Team) SetName

func (t *Team) SetName(name string)

Set the name and calculate the slug value.

func (*Team) Validate

func (t *Team) Validate() error

ValidatePassword will compares the supplied password to the user password stored in the database.

type User

type User struct {
	ID       int64     `meddler:"id,pk"            json:"id"`
	Email    string    `meddler:"email"            json:"email"`
	Password string    `meddler:"password"         json:"-"`
	Token    string    `meddler:"token"            json:"-"`
	Name     string    `meddler:"name"             json:"name"`
	Gravatar string    `meddler:"gravatar"         json:"gravatar"`
	Created  time.Time `meddler:"created,utctime"  json:"created"`
	Updated  time.Time `meddler:"updated,utctime"  json:"updated"`
	Admin    bool      `meddler:"admin"            json:"-"`

	// GitHub OAuth2 token for accessing public repositories.
	GithubLogin string `meddler:"github_login" json:"-"`
	GithubToken string `meddler:"github_token" json:"-"`

	// Bitbucket OAuth1.0a token and token secret.
	BitbucketLogin  string `meddler:"bitbucket_login"  json:"-"`
	BitbucketToken  string `meddler:"bitbucket_token"  json:"-"`
	BitbucketSecret string `meddler:"bitbucket_secret" json:"-"`

	GitlabToken string `meddler:"gitlab_token" json:"-"`
}

func NewUser

func NewUser(name, email string) *User

Creates a new User from the given Name and Email.

func (*User) ComparePassword

func (u *User) ComparePassword(password string) error

ComparePassword compares the supplied password to the user password stored in the database.

func (*User) Image

func (u *User) Image() string

Returns the Gravatar Image URL.

func (*User) ImageLarge

func (u *User) ImageLarge() string

func (*User) ImageSmall

func (u *User) ImageSmall() string

func (*User) SetEmail

func (u *User) SetEmail(email string)

Set the email address and calculate the Gravatar hash.

func (*User) SetPassword

func (u *User) SetPassword(password string) error

Set the password and hash with bcrypt

func (*User) Validate

func (u *User) Validate() error

Validate verifies all required fields are correctly populated.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL