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
- Variables
- func ComparePassword(password, hash string) bool
- func DeleteConfig()
- func DeleteMailServer()
- func NewDatabase(driver, options string) error
- func NewInMemoryDatabase()
- func NumberOfJobs() int
- type Command
- type CommandLog
- type Config
- type Job
- func (j *Job) Cancel()
- func (j *Job) DeployDone()
- func (j *Job) Done() bool
- func (j *Job) IsRunning() bool
- func (j *Job) Passed() bool
- func (j *Job) ShouldBuild() bool
- func (j *Job) ShouldDeploy() bool
- func (j *Job) Started()
- func (j *Job) Status() string
- func (j *Job) TasksDone()
- func (j *Job) URL() string
- type MailServer
- type Notification
- type Repository
- type User
Constants ¶
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" )
const ( JobStatusSuccess = "success" JobStatusError = "error" JobStatusPending = "pending" )
Define all statuses a job can have.
const ( // NotificationServiceFile type for file notifications. NotificationServiceFile = "file" // 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 ¶
var Configured bool
Configured indicates if there is a valid configuration.
Functions ¶
func ComparePassword ¶
ComparePassword returns true if the password matches the hash.
func DeleteMailServer ¶
func DeleteMailServer()
DeleteMailServer delete the existing mail server configuration.
func NewDatabase ¶
NewDatabase established a database connection and stores it in `db`.
func NewInMemoryDatabase ¶
func NewInMemoryDatabase()
NewInMemoryDatabase creates a new database using :memory:
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 ¶
GetCommand returns a command for a specific ID.
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 UpdateConfig ¶
UpdateConfig updates the config.
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 GetJobByCommit ¶
GetJobByCommit returns with a specific commit ID or nil.
func SearchJobs ¶
SearchJobs returns all jobs where the branch or commit contains the query string.
func (*Job) ShouldBuild ¶
ShouldBuild returns true if there are build commands for this job.
func (*Job) ShouldDeploy ¶
ShouldDeploy returns true if there are deploy commands for this job.
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) 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) 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 ¶
CreateUser creates a new user.
func GetUserByAccessKey ¶
GetUserByAccessKey returns the user for a given access key.
func GetUserByID ¶
GetUserByID returns the user for a given ID.
func GetUserBySession ¶
GetUserBySession returns the user for a given session key.
func (*User) NewAccessKey ¶
NewAccessKey generates a access key and stores it.
func (*User) NewSession ¶
NewSession generates a session key and stores it.