database

package
v0.0.0-...-a32039b Latest Latest
Warning

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

Go to latest
Published: May 22, 2016 License: MIT Imports: 17 Imported by: 6

Documentation

Overview

Package database provides a wrapper between the database and stucts

Package database provides a wrapper between the database and stucts

Package database provides a wrapper between the database and stucts

Package database provides a wrapper between the database and stucts

Package database provides a wrapper between the database and stucts

Package database provides a wrapper between the database and stucts

Package database provides a wrapper between the database and stucts

Package database provides a wrapper between the database and stucts

Index

Constants

View Source
const (
	// CommandKindTest is used when a command runs tests.
	CommandKindTest = "test"

	// CommandKindBuild is used when a command builds a package or project.
	CommandKindBuild = "build"

	// CommandKindDeploy is used when a command deploys a branch.
	CommandKindDeploy = "deploy"
)
View Source
const (
	JobStatusSuccess = "success"
	JobStatusError   = "error"
	JobStatusPending = "pending"
)

Define all statuses a job can have.

View Source
const (
	// NotificationServiceEmail type for email notifications.
	NotificationServiceEmail = "email"

	// NotificationServiceSlack type for slack notifications.
	NotificationServiceSlack = "slack"

	// NotificationServiceCampfire type for campfire notifications.
	NotificationServiceCampfire = "campfire"

	// NotificationServiceHipchat type for hipchat notifications.
	NotificationServiceHipchat = "hipchat"
)

Variables

View Source
var Configured bool

Configured indicates if there is a valid configuration.

Functions

func ComparePassword

func ComparePassword(password, hash string) bool

ComparePassword returns true if the password matches the hash.

func DeleteConfig

func DeleteConfig()

DeleteConfig delete the existing configuration.

func DeleteMailServer

func DeleteMailServer()

DeleteMailServer delete the existing mail server configuration.

func NewDatabase

func NewDatabase(driver, options string) error

NewDatabase established a database connection and stores it in `db`.

func NewInMemoryDatabase

func NewInMemoryDatabase()

NewInMemoryDatabase creates a new database using :memory:

func NumberOfJobs

func NumberOfJobs() int

NumberOfJobs returns the number of all existing jobs.

Types

type Command

type Command struct {
	ID      int64
	Name    string
	Kind    string
	Branch  string
	Execute string

	RepositoryID int64

	CreatedAt time.Time
	UpdatedAt time.Time
}

Command stores a short name and the path or command to execute when a users pushes to a repository.

func CreateCommand

func CreateCommand(repo *Repository, name, execute, branch, kind string) (*Command, error)

CreateCommand adds a new command to a repository.

func GetCommand

func GetCommand(id int64) (*Command, error)

GetCommand returns a command for a specific ID.

func (*Command) Delete

func (c *Command) Delete()

Delete deletes a command.

func (*Command) Update

func (c *Command) Update(name, kind, branch, execute string) error

Update a command.

type CommandLog

type CommandLog struct {
	ID     int64
	Name   string // we only keep the name, no reference to the command, in case it changes.
	Return string
	Output string `sql:"type:text"`

	JobID int64
}

CommandLog stored a finnished command and the output of the task.

func CreateCommandLog

func CreateCommandLog(command *Command, job *Job, ret, out string) *CommandLog

CreateCommandLog adds a new log.

func GetCommandLogsForJob

func GetCommandLogsForJob(id int64) []*CommandLog

GetCommandLogsForJob returns all logs for a job.

func (*CommandLog) Passed

func (t *CommandLog) Passed() bool

Passed returns true if the command completed successfully.

type Config

type Config struct {
	ID       int64
	Secret   string
	URL      string
	Cert     string
	Key      string
	Parallel int

	CreatedAt time.Time
	UpdatedAt time.Time
}

Config represents the complete configuration for the CI.

func AddConfig

func AddConfig(secret, url, cert, key string, parallel int) *Config

AddConfig adds a new configuration.

func GetConfig

func GetConfig() *Config

GetConfig returns the current configuration.

func UpdateConfig

func UpdateConfig(secret, url, cert, key string, parallel int) *Config

UpdateConfig updates the config.

func (*Config) Host

func (c *Config) Host() string

Host returns the host.

func (*Config) Scheme

func (c *Config) Scheme() string

Scheme returns the URL scheme used.

type Job

type Job struct {
	ID int64

	Cancelled      bool
	TasksStarted   time.Time
	TasksFinished  time.Time
	DeployFinished time.Time

	Repository   Repository
	RepositoryID int64

	Branch    string
	Commit    string `gorm:"column:commit_sha"`
	CommitURL string

	Name  string
	Email string

	CreatedAt time.Time
	UpdatedAt time.Time

	CommandLogs []CommandLog
}

Job stores all information about one commit and the executed tasks.

func CreateJob

func CreateJob(repo *Repository, branch, commit, commitURL, name, email string) *Job

CreateJob adds a new job to the database.

func GetJob

func GetJob(id int64) *Job

GetJob returns a job for a given ID.

func GetJobByCommit

func GetJobByCommit(commit string) *Job

GetJobByCommit returns with a specific commit ID or nil.

func GetJobs

func GetJobs(offset, limit int) []*Job

GetJobs returns a list of jobs for a given range.

func SearchJobs

func SearchJobs(query string) []*Job

SearchJobs returns all jobs where the branch or commit contains the query string.

func (*Job) Cancel

func (j *Job) Cancel()

Cancel cancels a job.

func (*Job) DeployDone

func (j *Job) DeployDone()

DeployDone sets DeployDone

func (*Job) Done

func (j *Job) Done() bool

Done returns true if all commands finished executing.

func (*Job) IsRunning

func (j *Job) IsRunning() bool

IsRunning returns true if this job is not finished with all its tasks.

func (*Job) Passed

func (j *Job) Passed() bool

Passed returns true if all commands succeeded.

func (*Job) ShouldBuild

func (j *Job) ShouldBuild() bool

ShouldBuild returns true if there are build commands for this job.

func (*Job) ShouldDeploy

func (j *Job) ShouldDeploy() bool

ShouldDeploy returns true if there are deploy commands for this job.

func (*Job) Started

func (j *Job) Started()

Started sets the started time to now indicating that this job started running.

func (*Job) Status

func (j *Job) Status() string

Status returns the current status fo the job.

func (*Job) TasksDone

func (j *Job) TasksDone()

TasksDone sets TasksDone

func (*Job) URL

func (j *Job) URL() string

URL returns the URL for this job, including the configured server URL.

type MailServer

type MailServer struct {
	ID       int64
	Host     string
	Sender   string
	Port     int
	User     string
	Password string

	CreatedAt time.Time
	UpdatedAt time.Time
}

MailServer stores a mailserver configuration.

func AddMailServer

func AddMailServer(host, sender, user, password string, port int) *MailServer

AddMailServer adds a new mail server.

func GetMailServer

func GetMailServer() *MailServer

GetMailServer returns a mail server configuration based on the current configuration.

func UpdateMailServer

func UpdateMailServer(host, sender, user, password string, port int) *MailServer

UpdateMailServer updates the existing mail server configuration.

func (*MailServer) Auth

func (m *MailServer) Auth() smtp.Auth

Auth returns net/smtp.Auth for this mail server.

func (*MailServer) From

func (m *MailServer) From() mail.Address

From returns net/mail.Address with sender information for the mail server.

func (*MailServer) Server

func (m *MailServer) Server() string

Server returns the host name and port for a mailserver.

type Notification

type Notification struct {
	ID        int64
	Service   string
	Arguments string

	Repository   Repository
	RepositoryID int64 `sql:"index"`
}

Notification stores the configuration needed for a notification plugin to work. All optiones required by the services are stored as map - it is the job of the notification plugin to access them correctly and handle missing ones.

func CreateNotification

func CreateNotification(service, arguments string, repo *Repository) (*Notification, error)

CreateNotification create a new notification for a repository.

func GetNotification

func GetNotification(id int64) (*Notification, error)

GetNotification returns a notification.

func GetNotificationForRepoAndType

func GetNotificationForRepoAndType(repo *Repository, service string) (*Notification, error)

GetNotificationForRepoAndType returns a specific notification for a repository.

func (*Notification) Delete

func (n *Notification) Delete()

Delete this notification.

func (*Notification) GetConfigValue

func (n *Notification) GetConfigValue(key string) (string, error)

GetConfigValue returns a configuration value for a given key that is stored in Arguments.

func (*Notification) Update

func (n *Notification) Update(service, arguments string) error

Update this notification.

type Repository

type Repository struct {
	ID   int64
	Name string
	URL  string

	ClosePR   bool
	StatusPR  bool
	AccessKey string

	CreatedAt time.Time
	UpdatedAt time.Time

	Notifications []Notification
	Commands      []Command
}

Repository holds all information needed to identify a repository and run tests and builds.

func CreateRepository

func CreateRepository(name, url, accessKey string, closePR, statusPR bool) (*Repository, error)

CreateRepository adds a new repository.

func GetRepository

func GetRepository(url string) *Repository

GetRepository returns the repository based on the URL that pushed changes.

func GetRepositoryByID

func GetRepositoryByID(id int64) (*Repository, error)

GetRepositoryByID returns the repository based on the ID.

func ListRepositories

func ListRepositories() []*Repository

ListRepositories returns all repositories.

func (*Repository) Delete

func (r *Repository) Delete() error

Delete this repository.

func (*Repository) GetCommands

func (r *Repository) GetCommands(branch, kind string) []Command

GetCommands returns all commands for a repository, branch and kind

func (*Repository) Jobs

func (r *Repository) Jobs() []Job

Jobs returns all jobs for this repository.

func (*Repository) Update

func (r *Repository) Update(name, url, accessKey string, closePR, statusPR bool) (*Repository, error)

Update this repository.

type User

type User struct {
	ID        int64
	Email     string
	FirstName string
	LastName  string
	Password  string
	Admin     bool
	Session   string
	AccessKey string
}

User stores a user account including the password using bcrypt.

func CreateUser

func CreateUser(email, firstName, lastName, password string, admin bool) (*User, error)

CreateUser creates a new user.

func GetUser

func GetUser(email string) (*User, error)

GetUser returns the user for a given email address.

func GetUserByAccessKey

func GetUserByAccessKey(key string) (*User, error)

GetUserByAccessKey returns the user for a given access key.

func GetUserByID

func GetUserByID(id int64) (*User, error)

GetUserByID returns the user for a given ID.

func GetUserBySession

func GetUserBySession(key string) (*User, error)

GetUserBySession returns the user for a given session key.

func ListUsers

func ListUsers() []*User

ListUsers returns a list of all users.

func (*User) Delete

func (u *User) Delete() error

Delete this user.

func (*User) NewAccessKey

func (u *User) NewAccessKey() string

NewAccessKey generates a access key and stores it.

func (*User) NewSession

func (u *User) NewSession() string

NewSession generates a session key and stores it.

func (*User) Update

func (u *User) Update(email, firstName, lastName, password string, admin bool) (*User, error)

Update updates an existing user.

Jump to

Keyboard shortcuts

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