model

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2021 License: MPL-2.0-no-copyleft-exception Imports: 20 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllCapabilities comprises the superuser account's list of capabilities.
	AllCapabilities = []Capability{CapabilityModifyCI, CapabilityModifyUser, CapabilitySubmit, CapabilityCancel}

	// TokenCryptKey is the standard token crypt key.
	// NOTE: the default is only used by tests; it is overwritten on service boot; see config/auth.go.
	TokenCryptKey = []byte{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8}
)
View Source
var OAuthExpiration = 10 * time.Minute

OAuthExpiration is a constant for the oauth state expiration time. It really should be in the configuration.

Functions

func MakeStatus

func MakeStatus(res, set bool) *bool

MakeStatus returns nil if set is false and the bool is false, indicating that it is not set.

func MakeTime

func MakeTime(ts *timestamp.Timestamp, nullable bool) *time.Time

MakeTime takes a protobuf timestamp and makes a time.Time out of it. If you pass true to the second argument, it will return nil if the argument is the zero value. Otherwise, it returns a time.Unix(0, 0).

func MakeTimestamp

func MakeTimestamp(t *time.Time) *timestamp.Timestamp

MakeTimestamp takes a time.Time and makes a protobuf timestamp out of it.

func MakeUserList

func MakeUserList(users []*User) []*types.User

MakeUserList returns the inverse of MakeUsers.

func MapError added in v0.3.0

func MapError(err error) error

MapError finds an error by string and returns an appropriate Error for it. The stack will NOT be preserved in the error and you will want to Wrap() it. If there is no potential mapping, a new Error is returned.

Types

type Capability

type Capability string

Capability is a type of access gating mechanism. If present on the user account access is granted, otherwise not.

const (
	// CapabilityModifyCI is required for modifying CI properties such as adding or removing a repo.
	CapabilityModifyCI Capability = "modify:ci"
	// CapabilityModifyUser allows you to modify users; including caps.
	CapabilityModifyUser Capability = "modify:user"
	// CapabilitySubmit allows manual submissions
	CapabilitySubmit Capability = "submit"
	// CapabilityCancel allows cancels
	CapabilityCancel Capability = "cancel"
)

type Model

type Model struct {
	*gorm.DB
}

Model is the outer layer of our internal database model, which will primarily be used by the data service.

func New

func New(sqlURL string) (*Model, error)

New returns the model structure after the db connection work has taken place.

func (*Model) AddCapabilityToUser

func (m *Model) AddCapabilityToUser(u *User, cap Capability) error

AddCapabilityToUser adds a capability to a user account.

func (*Model) AddSubscriptionsForUser

func (m *Model) AddSubscriptionsForUser(u *User, repos []*Repository) error

AddSubscriptionsForUser adds the repositories to the subscriptions table. Access is validated at the API level, not here.

func (*Model) AssignRepository

func (m *Model) AssignRepository(repo *Repository, owner *User) error

AssignRepository assigns the repository to the user explicitly.

func (*Model) CancelRefByName

func (m *Model) CancelRefByName(repoID int64, refName, baseURL string, gh github.Client) error

CancelRefByName is used in auto cancellation on new queue item arrivals. It finds all the runs associated with the ref and cancels them if they are in queue still. Do note that it does not match the SHA; more often than not this is caused by an --amend + force push which updates the SHA, or a new commit which also changes the SHA. The name is the only reliable data in this case.

func (*Model) CancelRun

func (m *Model) CancelRun(runID int64, baseURL string, gh github.Client) error

CancelRun is a thin facade for the CancelTask functionality, loading the record from the ID provided.

func (*Model) CancelSubmissionByID

func (m *Model) CancelSubmissionByID(id int64, baseURL string, client github.Client) error

CancelSubmissionByID cancels all related tasks (and thusly, runs) in a submission that are outstanding.

func (*Model) CancelTask

func (m *Model) CancelTask(task *Task, baseURL string, gh github.Client) error

CancelTask finds the queue items and runs for the task, removes them, cancels the associated runs for the task, and finally, saves the task itself. It will fail to do all of this if the task is already finished.

func (*Model) CancelTaskByID

func (m *Model) CancelTaskByID(id int64, baseURL string, gh github.Client) error

CancelTaskByID cancels a task by ID

func (*Model) CancelTasksForPR

func (m *Model) CancelTasksForPR(repository string, prID int64, baseURL string) error

CancelTasksForPR cancels all tasks for a PR.

func (*Model) CountRunsForTask

func (m *Model) CountRunsForTask(id int64) (int64, error)

CountRunsForTask retrieves the total count of runs for the given task.

func (*Model) CountTasks

func (m *Model) CountTasks(repository, sha string) (int64, error)

CountTasks counts all the tasks, optionally based on the repository and sha.

func (*Model) CreateUser

func (m *Model) CreateUser(username string, token *topTypes.OAuthToken) (*User, error)

CreateUser initializes a user struct and writes it to the db.

func (*Model) DeleteError

func (m *Model) DeleteError(u *User, id int64) error

DeleteError deletes a given error for a user.

func (*Model) DeleteToken

func (m *Model) DeleteToken(name string) error

DeleteToken removes the existing token.

func (*Model) DisableRepository

func (m *Model) DisableRepository(repo *Repository) error

DisableRepository removes it from CI.

func (*Model) EnableRepository

func (m *Model) EnableRepository(repo *Repository, owner *User) error

EnableRepository adds it to CI.

func (*Model) FindUserByID

func (m *Model) FindUserByID(id int64) (*User, error)

FindUserByID finds the user by integer ID.

func (*Model) FindUserByName

func (m *Model) FindUserByName(username string) (*User, error)

FindUserByName finds a user by unique key username.

func (*Model) FindUserByNameWithSubscriptions

func (m *Model) FindUserByNameWithSubscriptions(username, search string) (*User, error)

FindUserByNameWithSubscriptions finds a user by unique key username. It also fetches the subscriptions for the user.

func (*Model) GetAllPublicRepos

func (m *Model) GetAllPublicRepos(search string) (RepositoryList, error)

GetAllPublicRepos retrieves all repos that are not private

func (*Model) GetCancelForRun

func (m *Model) GetCancelForRun(runID int64) (bool, error)

GetCancelForRun satisfies the datasvc interface by finding the underlying task's canceled state.

func (*Model) GetCapabilities

func (m *Model) GetCapabilities(u *User, fixedCaps map[string][]string) ([]Capability, error)

GetCapabilities returns the capabilities the supplied user account has.

func (*Model) GetOwnedRepos

func (m *Model) GetOwnedRepos(u *User, search string) (RepositoryList, error)

GetOwnedRepos returns all repos the user owns.

func (*Model) GetPrivateReposForUser

func (m *Model) GetPrivateReposForUser(u *User, search string) (RepositoryList, error)

GetPrivateReposForUser retrieves all private repos that the user owns.

func (*Model) GetRefByNameAndSHA

func (m *Model) GetRefByNameAndSHA(repoName string, sha string) (*Ref, error)

GetRefByNameAndSHA returns the ref matching the name/sha combination.

func (*Model) GetRepositoryByName

func (m *Model) GetRepositoryByName(name string) (*Repository, error)

GetRepositoryByName retrieves the repository by its unique name.

func (*Model) GetRepositoryByNameForUser

func (m *Model) GetRepositoryByNameForUser(name string, u *User) (*Repository, error)

GetRepositoryByNameForUser retrieves the repository by name if the user can see it (aka, if it's not private or if it's owned by them)

func (*Model) GetRunsForTask

func (m *Model) GetRunsForTask(id, page, perPage int64) ([]*Run, error)

GetRunsForTask is just a join of all runs that belong to a task.

func (*Model) GetSubmissionByID

func (m *Model) GetSubmissionByID(id int64) (*Submission, error)

GetSubmissionByID returns a submission by internal identifier

func (*Model) GetToken

func (m *Model) GetToken(name string) (string, error)

GetToken retrieves a new token for logging in. If one exists, the DeleteToken method must be called first; otherwise this routine will throw an error.

func (*Model) GetVisibleReposForUser

func (m *Model) GetVisibleReposForUser(u *User, search string) (RepositoryList, error)

GetVisibleReposForUser retrieves all repos the user can "see" in the database.

func (*Model) HasCapability

func (m *Model) HasCapability(u *User, cap Capability, fixedCaps map[string][]string) (bool, error)

HasCapability returns true if the user is capable of performing the operation.

func (*Model) ListSubscribedTasksForUser

func (m *Model) ListSubscribedTasksForUser(userID, page, perPage int64) ([]*Task, error)

ListSubscribedTasksForUser lists all tasks related to the subscribed repositories for the user.

func (*Model) ListTasks

func (m *Model) ListTasks(repository, sha string, page, perPage int64) ([]*Task, error)

ListTasks gathers all the tasks based on the page and perPage values. It can optionally filter by repository and SHA.

func (*Model) LoadSession

func (m *Model) LoadSession(id string) (*Session, error)

LoadSession loads a session based on the key and returns it to the client

func (*Model) NewSubmissionFromMessage

func (m *Model) NewSubmissionFromMessage(sub *types.Submission) (*Submission, error)

NewSubmissionFromMessage creates a blank record populated by the appropriate data reaped from the message type in types/submission.go.

func (*Model) NextQueueItem

func (m *Model) NextQueueItem(runningOn string, queueName string) (*QueueItem, error)

NextQueueItem returns the next item in the named queue. If for some reason the queueName is an empty string, the string `default` will be used instead.

func (*Model) OAuthRegisterState

func (m *Model) OAuthRegisterState(state string, scopes []string) error

OAuthRegisterState registers a state code in a uniqueness table that tracks it.

func (*Model) OAuthValidateState

func (m *Model) OAuthValidateState(state string) (*OAuth, error)

OAuthValidateState validates that the state we sent actually exists and is ready to be consumed. In the event it is not, it returns error.

func (*Model) PutRef

func (m *Model) PutRef(ref *Ref) error

PutRef adds the ref to the database.

func (*Model) QueueList

func (m *Model) QueueList(page, perPage int64) ([]*QueueItem, error)

QueueList returns a list of queue items with pagination.

func (*Model) QueueListForRepository

func (m *Model) QueueListForRepository(repo *Repository, page, perPage int64) ([]*QueueItem, error)

QueueListForRepository returns a list of queue items with pagination.

func (*Model) QueuePipelineAdd

func (m *Model) QueuePipelineAdd(qis []*QueueItem) ([]*QueueItem, error)

QueuePipelineAdd adds a group of queue items in a transaction.

func (*Model) QueueTotalCount

func (m *Model) QueueTotalCount() (int64, error)

QueueTotalCount returns the number of items in the queue

func (*Model) QueueTotalCountForRepository

func (m *Model) QueueTotalCountForRepository(repo *Repository) (int64, error)

QueueTotalCountForRepository returns the number of items in the queue where the parent fork matches the repository name given

func (*Model) RemoveCapabilityFromUser

func (m *Model) RemoveCapabilityFromUser(u *User, cap Capability) error

RemoveCapabilityFromUser removes a capability from a user account.

func (*Model) RemoveSubscriptionForUser

func (m *Model) RemoveSubscriptionForUser(u *User, repo *Repository) error

RemoveSubscriptionForUser removes an item from the subscriptions table.

func (*Model) RunList

func (m *Model) RunList(page, perPage int64, repository, sha string) ([]*Run, error)

RunList returns a list of runs with pagination.

func (*Model) RunListForRepository

func (m *Model) RunListForRepository(repo *Repository, ref *Ref, page, perPage int64) ([]*Run, error)

RunListForRepository returns a list of queue items with pagination. If ref is non-nil, it will isolate to the ref only.

func (*Model) RunTotalCount

func (m *Model) RunTotalCount() (int64, error)

RunTotalCount returns the number of items in the runs table

func (*Model) RunTotalCountForRepository

func (m *Model) RunTotalCountForRepository(repo *Repository) (int64, error)

RunTotalCountForRepository returns the number of items in the queue where the parent fork matches the repository name given

func (*Model) RunTotalCountForRepositoryAndSHA

func (m *Model) RunTotalCountForRepositoryAndSHA(repo *Repository, sha string) (int64, error)

RunTotalCountForRepositoryAndSHA returns the number of items in the queue where the parent fork matches the repository name given

func (*Model) RunsForSubmission

func (m *Model) RunsForSubmission(sub *Submission, page, perPage int64) ([]*Run, error)

RunsForSubmission returns all the runs that are associated with the given submission.

func (*Model) RunsForTicket

func (m *Model) RunsForTicket(repoName string, ticketID int) ([]*Run, error)

RunsForTicket all the runs that belong to a repository's PR.

func (*Model) SaveRepositories

func (m *Model) SaveRepositories(repos []*gh.Repository, username string, autoCreated bool) error

SaveRepositories saves github repositories; it sets the *User provided to the owner of it.

func (*Model) SaveSession

func (m *Model) SaveSession(session *Session) error

SaveSession does the opposite of LoadSession

func (*Model) SetRunStatus

func (m *Model) SetRunStatus(runID int64, gh github.Client, status, canceled bool, url, addlMessage string) error

SetRunStatus sets the status for the run; fails if it is already set.

func (*Model) SubmissionCount

func (m *Model) SubmissionCount(repository, sha string) (int64, error)

SubmissionCount counts the number of submissions with an optional repo/sha filter

func (*Model) SubmissionList

func (m *Model) SubmissionList(page, perPage int64, repository, sha string) ([]*Submission, error)

SubmissionList returns a list of submissions with pagination and repo/sha filtering.

func (*Model) SubmissionListForRepository

func (m *Model) SubmissionListForRepository(repo, sha string, page, perPage int64) ([]*Submission, error)

SubmissionListForRepository returns a list of submissions with pagination. If ref is non-nil, it will isolate to the ref only and ignore the repo.

func (*Model) TasksForSubmission

func (m *Model) TasksForSubmission(sub *Submission, page, perPage int64) ([]*Task, error)

TasksForSubmission returns all the tasks for a given submission.

func (*Model) UpdateTaskStatus

func (m *Model) UpdateTaskStatus(task *Task) error

UpdateTaskStatus is triggered when a run state change happens that is *not* a cancellation.

func (*Model) ValidateToken

func (m *Model) ValidateToken(token string) (*User, error)

ValidateToken checks that a token is valid for a given user.

func (*Model) WrapError

func (m *Model) WrapError(call *gorm.DB, msg string) error

WrapError is a tail call for db transactions; it will return a wrapped and stack-annotated error with the msg if there is one; otherwise it will return nil. It also uses the errors package to normalize common errors returned from the DB.

type OAuth

type OAuth struct {
	State     string    `gorm:"primary key" json:"state"`
	Scopes    string    `json:"scopes"`
	ExpiresOn time.Time `json:"expires_on"`
}

OAuth schema is for checking state return values from github.

func (*OAuth) GetScopes

func (o *OAuth) GetScopes() map[string]struct{}

GetScopes returns the split list of scopes, mapped for easy comparison.

func (*OAuth) GetScopesList

func (o *OAuth) GetScopesList() []string

GetScopesList returns the split list of scopes

func (*OAuth) SetScopes

func (o *OAuth) SetScopes(scopes []string)

SetScopes takes a []string of scope names, and marshals them to the struct field.

func (*OAuth) ToProto

func (o *OAuth) ToProto() *data.OAuthState

ToProto returns a protobuf representation of the model oauth request

type QueueItem

type QueueItem struct {
	ID int64 `gorm:"primary_key" json:"id"`

	Run       *Run       `json:"run"`
	RunID     int64      `json:"-"`
	Running   bool       `json:"running"`
	RunningOn *string    `json:"running_on,omitempty"`
	StartedAt *time.Time `json:"started_at,omitempty"`
	QueueName string     `json:"queue_name"`
}

QueueItem represents an item in the queue table in the database.

func NewQueueItemFromProto

func NewQueueItemFromProto(tqi *types.QueueItem) (*QueueItem, error)

NewQueueItemFromProto converts in the opposite direction of ToProto.

func (*QueueItem) AfterFind

func (qi *QueueItem) AfterFind(tx *gorm.DB) error

AfterFind validates the output from the database before releasing it to the hook chain

func (*QueueItem) BeforeCreate

func (qi *QueueItem) BeforeCreate(tx *gorm.DB) error

BeforeCreate just calls BeforeSave.

func (*QueueItem) BeforeSave

func (qi *QueueItem) BeforeSave(tx *gorm.DB) error

BeforeSave is a gorm hook to marshal the token JSON before saving the record

func (*QueueItem) ToProto

func (qi *QueueItem) ToProto() *types.QueueItem

ToProto converts the queueitem to the protobuf version

func (*QueueItem) Validate

func (qi *QueueItem) Validate() error

Validate the item. if passed true, will validate for creation scenarios

type Ref

type Ref struct {
	ID           int64       `gorm:"primary_key" json:"id"`
	Repository   *Repository `json:"repository" gorm:"unique;association_autoupdate:false"`
	RepositoryID int64       `json:"-"`
	RefName      string      `gorm:"column:ref" json:"ref_name"`
	SHA          string      `json:"sha"`
}

Ref encapsulates git ref -- sha or branch name -- which is tied to a task (and multiple runs, potentially)

func NewRefFromProto

func NewRefFromProto(r *types.Ref) (*Ref, error)

NewRefFromProto converts a proto ref to a real ref.

func (*Ref) AfterFind

func (r *Ref) AfterFind(tx *gorm.DB) error

AfterFind validates the output from the database before releasing it to the hook chain

func (*Ref) BeforeCreate

func (r *Ref) BeforeCreate(tx *gorm.DB) error

BeforeCreate just calls BeforeSave.

func (*Ref) BeforeSave

func (r *Ref) BeforeSave(tx *gorm.DB) error

BeforeSave is a gorm hook to marshal the token JSON before saving the record

func (*Ref) ToProto

func (r *Ref) ToProto() *types.Ref

ToProto returns a ref in the protobuf representation

func (*Ref) Validate

func (r *Ref) Validate() error

Validate validates the ref before saving it and after fetching it.

type Repository

type Repository struct {
	ID          int64  `gorm:"primary_key" json:"id"`
	Name        string `gorm:"unique" json:"name"`
	Private     bool   `json:"private"`
	Disabled    bool   `json:"disabled"`
	GithubJSON  []byte `gorm:"column:github" json:"-"`
	OwnerID     int64  `json:"-"`
	Owner       *User  `gorm:"association_autoupdate:false" json:"-"`
	AutoCreated bool   `json:"auto_created"`
	HookSecret  string `json:"-"`

	Github *gh.Repository `json:"github"`
}

Repository is the encapsulation of a git repository.

func NewRepositoryFromProto

func NewRepositoryFromProto(r *types.Repository) (*Repository, error)

NewRepositoryFromProto converts a proto repository to a model repository.

func (*Repository) AfterFind

func (r *Repository) AfterFind(tx *gorm.DB) error

AfterFind validates the output from the database before releasing it to the hook chain

func (*Repository) BeforeCreate

func (r *Repository) BeforeCreate(tx *gorm.DB) error

BeforeCreate just calls BeforeSave.

func (*Repository) BeforeSave

func (r *Repository) BeforeSave(tx *gorm.DB) error

BeforeSave is a gorm hook to marshal the token JSON before saving the record

func (*Repository) Enabled

func (r *Repository) Enabled() bool

Enabled is merely a predicate to determine if the repo can be used or not

func (*Repository) OwnerRepo

func (r *Repository) OwnerRepo() (string, string, error)

OwnerRepo validates the owner/repo github path then returns each part.

func (*Repository) ToProto

func (r *Repository) ToProto() *types.Repository

ToProto returns the protobuf representation of the repository

func (*Repository) Validate

func (r *Repository) Validate(validOwner bool) error

Validate validates the repository object

type RepositoryList

type RepositoryList []*Repository

RepositoryList conforms to the sort.Interface interface

func (RepositoryList) Len

func (rl RepositoryList) Len() int

Len computes the length of the list

func (RepositoryList) Less

func (rl RepositoryList) Less(i, j int) bool

Less determines the order of the list

func (RepositoryList) Swap

func (rl RepositoryList) Swap(i, j int)

func (RepositoryList) ToProto

func (rl RepositoryList) ToProto() *types.RepositoryList

ToProto converts the repository list to a protobuf representation

type Run

type Run struct {
	ID int64 `gorm:"primary_key" json:"id"`

	RunSettingsJSON []byte `gorm:"column:run_settings" json:"-"`

	Name       string     `json:"name"`
	CreatedAt  time.Time  `json:"created_at"`
	StartedAt  *time.Time `json:"started_at,omitempty"`
	FinishedAt *time.Time `json:"finished_at,omitempty"`
	Status     *bool      `json:"status,omitempty"`
	Task       *Task      `gorm:"association_autoupdate:false" json:"task"`
	TaskID     int64      `json:"-"`
	RanOn      *string    `json:"ran_on"`

	RunSettings *types.RunSettings `json:"settings"`
}

Run is the individual parallel run. Runs are organized into the queue service for handing out to runners in order. Multiple runs are make up a task.

func NewRunFromProto

func NewRunFromProto(r *gtypes.Run) (*Run, error)

NewRunFromProto yields a new run from a protobuf message.

func (*Run) AfterFind

func (r *Run) AfterFind(tx *gorm.DB) error

AfterFind validates the output from the database before releasing it to the hook chain

func (*Run) BeforeCreate

func (r *Run) BeforeCreate(tx *gorm.DB) error

BeforeCreate just calls BeforeSave.

func (*Run) BeforeSave

func (r *Run) BeforeSave(tx *gorm.DB) error

BeforeSave is a gorm hook to marshal the token JSON before saving the record

func (*Run) ToProto

func (r *Run) ToProto() *gtypes.Run

ToProto converts the run to its protobuf representation

func (*Run) Validate

func (r *Run) Validate() error

Validate validates the run record, accounting for creation or modification. Returns error on any found.

type Session

type Session struct {
	Key       string    `gorm:"primary_key" json:"key"`
	Values    string    `json:"values"`
	ExpiresOn time.Time `json:"expires_on"`
}

Session corresponds to the `sessions` table and encapsulates a web session.

func NewSessionFromProto

func NewSessionFromProto(s *types.Session) *Session

NewSessionFromProto returns a session from a protobuf representation.

func (*Session) ToProto

func (s *Session) ToProto() *types.Session

ToProto converts the session to protobuf representation.

type Submission

type Submission struct {
	ID int64 `gorm:"priamry_key" json:"id"`

	User   *User `gorm:"association_autoupdate:false,nullable:true" json:"user"`
	UserID int64 `json:"-"`

	HeadRef   *Ref  `gorm:"association_autoupdate:false,column:head_ref_id,nullable:true" json:"head_ref"`
	HeadRefID int64 `json:"-"`

	BaseRef   *Ref  `gorm:"association_autoupdate:false,column:base_ref_id" json:"base_ref"`
	BaseRefID int64 `json:"-"`

	TasksCount int64 `json:"tasks_count" gorm:"-"`
	RunsCount  int64 `json:"runs_count" gorm:"-"`

	Status *bool `json:"status" gorm:"-"`

	CreatedAt  time.Time  `json:"created_at"`
	StartedAt  *time.Time `json:"started_at" gorm:"-"`
	FinishedAt *time.Time `json:"finished_at" gorm:"-"`

	Canceled bool `json:"canceled" gorm:"-"`

	TicketID int64 `json:"ticket_id"`
}

Submission is the concrete type for a test submission, unlike types/submission.go which is the ephemeral type for messages and so on. Each submission has it own ID and list of tasks so that we can further give the user the opportunity to aggregate their tasks into a single unit.

func NewSubmissionFromProto

func NewSubmissionFromProto(gt *gtypes.Submission) (*Submission, error)

NewSubmissionFromProto converts the proto representation to the task type.

func (*Submission) ToProto

func (s *Submission) ToProto() *gtypes.Submission

ToProto converts the submissions to the protobuf version

type Task

type Task struct {
	ID int64 `gorm:"primary_key" json:"id"`

	Path string `json:"path"`

	TaskSettingsJSON []byte `gorm:"column:task_settings" json:"-"`

	Canceled   bool       `json:"canceled"`
	FinishedAt *time.Time `json:"finished_at,omitempty"`
	StartedAt  *time.Time `json:"started_at,omitempty"`
	CreatedAt  time.Time  `json:"created_at"`
	Status     *bool      `json:"status,omitempty"`

	TaskSettings *types.TaskSettings `json:"settings"`

	Runs int64 `json:"runs" gorm:"-"`

	Submission   *Submission `gorm:"association_autoupdate:false" json:"submission"`
	SubmissionID int64       `json:"-"`
}

Task is the organizational unit of a single source-controlled directory. It contains many runs; it the settings are kept in a file named `task.yml` and lives in the directory it is testing.

func NewTaskFromProto

func NewTaskFromProto(gt *gtypes.Task) (*Task, error)

NewTaskFromProto converts the proto representation to the task type.

func (*Task) AfterFind

func (t *Task) AfterFind(tx *gorm.DB) error

AfterFind validates the output from the database before releasing it to the hook chain

func (*Task) BeforeCreate

func (t *Task) BeforeCreate(tx *gorm.DB) error

BeforeCreate just calls BeforeSave.

func (*Task) BeforeSave

func (t *Task) BeforeSave(tx *gorm.DB) error

BeforeSave is a gorm hook to marshal the token JSON before saving the record

func (*Task) ToProto

func (t *Task) ToProto() *gtypes.Task

ToProto converts the task to a protobuf representation

func (*Task) Validate

func (t *Task) Validate() error

Validate ensures all parameters are set properly.

type User

type User struct {
	ID               int64         `gorm:"primary_key" json:"id"`
	Username         string        `gorm:"unique" json:"username"`
	LastScannedRepos *time.Time    `json:"last_scanned_repos,omitempty"`
	Errors           []UserError   `json:"errors,omitempty"`
	Subscribed       []*Repository `gorm:"many2many:subscriptions;preload:false" json:"subscribed,omitempty"`
	LoginToken       []byte        `json:"-"`

	TokenJSON []byte               `gorm:"column:token;not null" json:"-"`
	Token     *topTypes.OAuthToken `json:"-"`
}

User is a user record.

func MakeUsers

func MakeUsers(users []*types.User) ([]*User, error)

MakeUsers converts a proto userlist to a model one.

func NewUserFromProto

func NewUserFromProto(u *types.User) (*User, error)

NewUserFromProto converts a proto user to a real user.

func (*User) AddError

func (u *User) AddError(err error)

AddError adds an error to the error list.

func (*User) AfterFind

func (u *User) AfterFind(tx *gorm.DB) error

AfterFind is a gorm hook to unmarshal the Token JSON after finding the record.

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) error

BeforeCreate just calls BeforeSave.

func (*User) BeforeSave

func (u *User) BeforeSave(tx *gorm.DB) error

BeforeSave is a gorm hook to marshal the Token JSON before saving the record

func (*User) FetchToken

func (u *User) FetchToken() error

FetchToken retrieves the token from the db, decrypting it if necessary.

func (*User) SetToken

func (u *User) SetToken() error

SetToken sets the token's byte stream, and encrypts it.

func (*User) ToProto

func (u *User) ToProto() *types.User

ToProto converts the user struct to a protobuf capable one

func (*User) Validate

func (u *User) Validate() error

Validate validates the user record to ensure it can be written.

func (*User) ValidateWrite

func (u *User) ValidateWrite() error

ValidateWrite is for write-only validations.

type UserError

type UserError struct {
	ID     int64  `gorm:"primary key" json:"id"`
	UserID int64  `json:"-"`
	Error  string `json:"error"`
}

UserError is the encapsulation of many errors that need to be presented to the user.

func NewUserErrorFromProto

func NewUserErrorFromProto(ue *types.UserError) *UserError

NewUserErrorFromProto converts a user error from proto to canonical representation

func (UserError) ToProto

func (ue UserError) ToProto() *types.UserError

ToProto converts the usererror to its protocol buffer representation.

Jump to

Keyboard shortcuts

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