Documentation ¶
Index ¶
- Constants
- Variables
- func ConnectDatabase()
- type Database
- func (db *Database) CreateDiggerBatch(vcsType DiggerVCSType, githubInstallationId int64, repoOwner string, ...) (*DiggerBatch, error)
- func (db *Database) CreateDiggerJob(batchId uuid.UUID, serializedJob []byte, workflowFile string) (*DiggerJob, error)
- func (db *Database) CreateDiggerJobLink(diggerJobId string, repoFullName string) (*GithubDiggerJobLink, error)
- func (db *Database) CreateDiggerJobParentLink(parentJobId string, jobId string) error
- func (db *Database) CreateDiggerJobToken(organisationId uint) (*JobToken, error)
- func (db *Database) CreateDiggerLock(resource string, lockId int, orgId uint) (*DiggerLock, error)
- func (db *Database) CreateDiggerRun(Triggertype string, PrNumber int, Status DiggerRunStatus, CommitId string, ...) (*DiggerRun, error)
- func (db *Database) CreateDiggerRunQueueItem(diggeRrunId uint, projectId uint) (*DiggerRunQueueItem, error)
- func (db *Database) CreateDiggerRunStage(batchId string) (*DiggerRunStage, error)
- func (db *Database) CreateGithubAppConnection(name string, githubId int64, ClientID string, ClientSecretEncrypted string, ...) (*GithubAppConnection, error)
- func (db *Database) CreateGithubAppInstallation(installationId int64, githubAppId int64, login string, accountId int, ...) (*GithubAppInstallation, error)
- func (db *Database) CreateGithubInstallationLink(org *Organisation, installationId int64) (*GithubAppInstallationLink, error)
- func (db *Database) CreateOrganisation(name string, externalSource string, tenantId string) (*Organisation, error)
- func (db *Database) CreateProject(name string, org *Organisation, repo *Repo, isGenerated bool, ...) (*Project, error)
- func (db *Database) CreateRepo(name string, repoFullName string, repoOrganisation string, repoName string, ...) (*Repo, error)
- func (db *Database) DeleteJobTokenArtefacts(jobTokenId uint) error
- func (db *Database) DequeueRunItem(queueItem *DiggerRunQueueItem) error
- func (db *Database) GetDefaultRepo(c *gin.Context, orgIdKey string) (*Repo, bool)
- func (db *Database) GetDiggerBatch(batchId *uuid.UUID) (*DiggerBatch, error)
- func (db *Database) GetDiggerJob(jobId string) (*DiggerJob, error)
- func (db *Database) GetDiggerJobFromRunStage(stage DiggerRunStage) (*DiggerJob, error)
- func (db *Database) GetDiggerJobLink(diggerJobId string) (*GithubDiggerJobLink, error)
- func (db *Database) GetDiggerJobParentLinksByParentId(parentId *string) ([]DiggerJobParentLink, error)
- func (db *Database) GetDiggerJobParentLinksChildId(childId *string) ([]DiggerJobParentLink, error)
- func (db *Database) GetDiggerJobsForBatch(batchId uuid.UUID) ([]DiggerJob, error)
- func (db *Database) GetDiggerJobsForBatchWithStatus(batchId uuid.UUID, status []scheduler.DiggerJobStatus) ([]DiggerJob, error)
- func (db *Database) GetDiggerJobsWithStatus(status scheduler.DiggerJobStatus) ([]DiggerJob, error)
- func (db *Database) GetDiggerLock(resource string) (*DiggerLock, error)
- func (db *Database) GetDiggerRun(id uint) (*DiggerRun, error)
- func (db *Database) GetDiggerRunQueueItem(id uint) (*DiggerRunQueueItem, error)
- func (db *Database) GetFirstRunQueueForEveryProject() ([]DiggerRunQueueItem, error)
- func (db *Database) GetGithubAppConnection(gitHubAppId any) (*GithubAppConnection, error)
- func (db *Database) GetGithubAppConnectionById(id string) (*GithubAppConnection, error)
- func (db *Database) GetGithubAppInstallationByIdAndRepo(installationId int64, repoFullName string) (*GithubAppInstallation, error)
- func (db *Database) GetGithubAppInstallationByOrgAndRepo(orgId any, repo string, status GithubAppInstallStatus) (*GithubAppInstallation, error)
- func (db *Database) GetGithubAppInstallationLink(installationId int64) (*GithubAppInstallationLink, error)
- func (db *Database) GetGithubAppInstallations(installationId int64) ([]GithubAppInstallation, error)
- func (db *Database) GetGithubInstallationLinkForInstallationId(installationId any) (*GithubAppInstallationLink, error)
- func (db *Database) GetGithubInstallationLinkForOrg(orgId any) (*GithubAppInstallationLink, error)
- func (db *Database) GetJobArtefact(jobTokenId uint) (*JobArtefact, error)
- func (db *Database) GetJobToken(tenantId any) (*JobToken, error)
- func (db *Database) GetLastDiggerRunForProject(projectName string) (*DiggerRun, error)
- func (db *Database) GetOrganisation(tenantId any) (*Organisation, error)
- func (db *Database) GetOrganisationById(orgId any) (*Organisation, error)
- func (db *Database) GetPendingParentDiggerJobs(batchId *uuid.UUID) ([]DiggerJob, error)
- func (db *Database) GetPoliciesFromContext(c *gin.Context, orgIdKey string) ([]Policy, bool)
- func (db *Database) GetPolicyByPolicyId(c *gin.Context, policyId uint, orgIdKey string) (*Policy, bool)
- func (db *Database) GetProject(projectId uint) (*Project, error)
- func (db *Database) GetProjectByName(orgId any, repo *Repo, name string) (*Project, error)
- func (db *Database) GetProjectByProjectId(c *gin.Context, projectId uint, orgIdKey string) (*Project, bool)
- func (db *Database) GetProjectByRepo(orgId any, repo *Repo) ([]Project, error)
- func (db *Database) GetProjectByRunId(c *gin.Context, runId uint, orgIdKey string) (*ProjectRun, bool)
- func (db *Database) GetProjectRunsForOrg(orgId int) ([]ProjectRun, error)
- func (db *Database) GetProjectRunsFromContext(c *gin.Context, orgIdKey string) ([]ProjectRun, bool)
- func (db *Database) GetProjectsFromContext(c *gin.Context, orgIdKey string) ([]Project, bool)
- func (db *Database) GetRepo(orgIdKey any, repoName string) (*Repo, error)
- func (db *Database) GetRepoById(orgIdKey any, repoId any) (*Repo, error)
- func (db *Database) GetRepoCache(orgId uint, repoFullName string) (*RepoCache, error)
- func (db *Database) GetReposFromContext(c *gin.Context, orgIdKey string) ([]Repo, bool)
- func (db *Database) GetToken(tenantId any) (*Token, error)
- func (db *Database) GithubRepoAdded(installationId int64, appId int64, login string, accountId int64, ...) (*GithubAppInstallation, error)
- func (db *Database) GithubRepoRemoved(installationId int64, appId int64, repoFullName string) (*GithubAppInstallation, error)
- func (db *Database) ListDiggerRunsForProject(projectName string, repoId uint) ([]DiggerRun, error)
- func (db *Database) MakeGithubAppInstallationLinkInactive(link *GithubAppInstallationLink) (*GithubAppInstallationLink, error)
- func (db *Database) UpdateBatchStatus(batch *DiggerBatch) error
- func (db *Database) UpdateDiggerBatch(batch *DiggerBatch) error
- func (db *Database) UpdateDiggerJob(job *DiggerJob) error
- func (db *Database) UpdateDiggerJobLink(diggerJobId string, repoFullName string, githubJobId int64) (*GithubDiggerJobLink, error)
- func (db *Database) UpdateDiggerJobSummary(diggerJobId string, resourcesCreated uint, resourcesUpdated uint, ...) (*DiggerJob, error)
- func (db *Database) UpdateDiggerRun(diggerRun *DiggerRun) error
- func (db *Database) UpdateProject(project *Project) error
- func (db *Database) UpdateRepoDiggerConfig(orgId any, config configuration.DiggerConfigYaml, repo *Repo, ...) error
- func (db *Database) UpsertRepoCache(orgId uint, repoFullName string, diggerYmlStr string, ...) (*RepoCache, error)
- type DiggerBatch
- type DiggerJob
- type DiggerJobLinkStatus
- type DiggerJobParentLink
- type DiggerJobSummary
- type DiggerLock
- type DiggerRun
- type DiggerRunQueueItem
- type DiggerRunStage
- type DiggerRunStatus
- type DiggerVCSType
- type GithubAppConnection
- type GithubAppInstallStatus
- type GithubAppInstallation
- type GithubAppInstallationLink
- type GithubAppInstallationLinkStatus
- type GithubDiggerJobLink
- type JobArtefact
- type JobToken
- type Organisation
- type Policy
- type Project
- type ProjectRun
- type ProjectStatus
- type Repo
- type RepoCache
- type RunType
- type SerializedRunStage
- type Token
- type User
Constants ¶
const ( AccessPolicyType = "access" AdminPolicyType = "admin" CliJobAccessType = "cli_access" )
const ( POLICY_TYPE_ACCESS = "access" POLICY_TYPE_PLAN = "plan" POLICY_TYPE_DRIFT = "drift" )
Variables ¶
var DEFAULT_ORG_NAME = "digger"
Functions ¶
func ConnectDatabase ¶
func ConnectDatabase()
Types ¶
type Database ¶
var DB *Database
var DB *gorm.DB
func (*Database) CreateDiggerBatch ¶
func (db *Database) CreateDiggerBatch(vcsType DiggerVCSType, githubInstallationId int64, repoOwner string, repoName string, repoFullname string, PRNumber int, diggerConfig string, branchName string, batchType scheduler.DiggerCommand, commentId *int64, gitlabProjectId int, aiSummaryCommentId string, reportTerraformOutputs bool) (*DiggerBatch, error)
func (*Database) CreateDiggerJob ¶
func (*Database) CreateDiggerJobLink ¶
func (db *Database) CreateDiggerJobLink(diggerJobId string, repoFullName string) (*GithubDiggerJobLink, error)
func (*Database) CreateDiggerJobParentLink ¶
func (*Database) CreateDiggerJobToken ¶
func (*Database) CreateDiggerLock ¶
func (*Database) CreateDiggerRun ¶
func (*Database) CreateDiggerRunQueueItem ¶
func (db *Database) CreateDiggerRunQueueItem(diggeRrunId uint, projectId uint) (*DiggerRunQueueItem, error)
func (*Database) CreateDiggerRunStage ¶
func (db *Database) CreateDiggerRunStage(batchId string) (*DiggerRunStage, error)
func (*Database) CreateGithubAppConnection ¶
func (*Database) CreateGithubAppInstallation ¶
func (*Database) CreateGithubInstallationLink ¶
func (db *Database) CreateGithubInstallationLink(org *Organisation, installationId int64) (*GithubAppInstallationLink, error)
func (*Database) CreateOrganisation ¶
func (*Database) CreateProject ¶
func (*Database) CreateRepo ¶
func (*Database) DeleteJobTokenArtefacts ¶
func (*Database) DequeueRunItem ¶
func (db *Database) DequeueRunItem(queueItem *DiggerRunQueueItem) error
func (*Database) GetDefaultRepo ¶
func (*Database) GetDiggerBatch ¶
func (db *Database) GetDiggerBatch(batchId *uuid.UUID) (*DiggerBatch, error)
func (*Database) GetDiggerJobFromRunStage ¶
func (db *Database) GetDiggerJobFromRunStage(stage DiggerRunStage) (*DiggerJob, error)
func (*Database) GetDiggerJobLink ¶
func (db *Database) GetDiggerJobLink(diggerJobId string) (*GithubDiggerJobLink, error)
func (*Database) GetDiggerJobParentLinksByParentId ¶
func (db *Database) GetDiggerJobParentLinksByParentId(parentId *string) ([]DiggerJobParentLink, error)
func (*Database) GetDiggerJobParentLinksChildId ¶
func (db *Database) GetDiggerJobParentLinksChildId(childId *string) ([]DiggerJobParentLink, error)
func (*Database) GetDiggerJobsForBatch ¶
func (*Database) GetDiggerJobsForBatchWithStatus ¶
func (*Database) GetDiggerJobsWithStatus ¶
func (db *Database) GetDiggerJobsWithStatus(status scheduler.DiggerJobStatus) ([]DiggerJob, error)
func (*Database) GetDiggerLock ¶
func (db *Database) GetDiggerLock(resource string) (*DiggerLock, error)
func (*Database) GetDiggerRunQueueItem ¶
func (db *Database) GetDiggerRunQueueItem(id uint) (*DiggerRunQueueItem, error)
func (*Database) GetFirstRunQueueForEveryProject ¶
func (db *Database) GetFirstRunQueueForEveryProject() ([]DiggerRunQueueItem, error)
func (*Database) GetGithubAppConnection ¶
func (db *Database) GetGithubAppConnection(gitHubAppId any) (*GithubAppConnection, error)
GetGithubApp return GithubApp by Id
func (*Database) GetGithubAppConnectionById ¶
func (db *Database) GetGithubAppConnectionById(id string) (*GithubAppConnection, error)
func (*Database) GetGithubAppInstallationByIdAndRepo ¶
func (db *Database) GetGithubAppInstallationByIdAndRepo(installationId int64, repoFullName string) (*GithubAppInstallation, error)
GetGithubAppInstallationByIdAndRepo repoFullName should be in the following format: org/repo_name, for example "diggerhq/github-job-scheduler"
func (*Database) GetGithubAppInstallationByOrgAndRepo ¶
func (db *Database) GetGithubAppInstallationByOrgAndRepo(orgId any, repo string, status GithubAppInstallStatus) (*GithubAppInstallation, error)
func (*Database) GetGithubAppInstallationLink ¶
func (db *Database) GetGithubAppInstallationLink(installationId int64) (*GithubAppInstallationLink, error)
GetGithubAppInstallationLink repoFullName should be in the following format: org/repo_name, for example "diggerhq/github-job-scheduler"
func (*Database) GetGithubAppInstallations ¶
func (db *Database) GetGithubAppInstallations(installationId int64) ([]GithubAppInstallation, error)
func (*Database) GetGithubInstallationLinkForInstallationId ¶
func (db *Database) GetGithubInstallationLinkForInstallationId(installationId any) (*GithubAppInstallationLink, error)
func (*Database) GetGithubInstallationLinkForOrg ¶
func (db *Database) GetGithubInstallationLinkForOrg(orgId any) (*GithubAppInstallationLink, error)
func (*Database) GetJobArtefact ¶
func (db *Database) GetJobArtefact(jobTokenId uint) (*JobArtefact, error)
func (*Database) GetLastDiggerRunForProject ¶
func (*Database) GetOrganisation ¶
func (db *Database) GetOrganisation(tenantId any) (*Organisation, error)
func (*Database) GetOrganisationById ¶
func (db *Database) GetOrganisationById(orgId any) (*Organisation, error)
func (*Database) GetPendingParentDiggerJobs ¶
func (*Database) GetPoliciesFromContext ¶
func (*Database) GetPolicyByPolicyId ¶
func (*Database) GetProjectByName ¶
GetProjectByName return project for specified org and repo if record doesn't exist return nil
func (*Database) GetProjectByProjectId ¶
func (*Database) GetProjectByRepo ¶
GetProjectByRepo return projects for specified org and repo
func (*Database) GetProjectByRunId ¶
func (*Database) GetProjectRunsForOrg ¶
func (db *Database) GetProjectRunsForOrg(orgId int) ([]ProjectRun, error)
func (*Database) GetProjectRunsFromContext ¶
func (*Database) GetProjectsFromContext ¶
func (*Database) GetRepo ¶
GetRepo returns digger repo by organisationId and repo name (diggerhq-digger) it will return an empty object if record doesn't exist in database
func (*Database) GetRepoById ¶
GetRepoById returns digger repo by organisationId and repo name (diggerhq-digger)
func (*Database) GetRepoCache ¶
func (*Database) GetReposFromContext ¶
func (*Database) GithubRepoAdded ¶
func (db *Database) GithubRepoAdded(installationId int64, appId int64, login string, accountId int64, repoFullName string) (*GithubAppInstallation, error)
GithubRepoAdded handles github drift that github repo has been added to the app installation
func (*Database) GithubRepoRemoved ¶
func (*Database) ListDiggerRunsForProject ¶
func (*Database) MakeGithubAppInstallationLinkInactive ¶
func (db *Database) MakeGithubAppInstallationLinkInactive(link *GithubAppInstallationLink) (*GithubAppInstallationLink, error)
func (*Database) UpdateBatchStatus ¶
func (db *Database) UpdateBatchStatus(batch *DiggerBatch) error
func (*Database) UpdateDiggerBatch ¶
func (db *Database) UpdateDiggerBatch(batch *DiggerBatch) error
func (*Database) UpdateDiggerJob ¶
func (*Database) UpdateDiggerJobLink ¶
func (*Database) UpdateDiggerJobSummary ¶
func (*Database) UpdateDiggerRun ¶
func (*Database) UpdateProject ¶
func (*Database) UpdateRepoDiggerConfig ¶
func (db *Database) UpdateRepoDiggerConfig(orgId any, config configuration.DiggerConfigYaml, repo *Repo, isMainBranch bool) error
func (*Database) UpsertRepoCache ¶
func (db *Database) UpsertRepoCache(orgId uint, repoFullName string, diggerYmlStr string, diggerConfig configuration.DiggerConfig) (*RepoCache, error)
type DiggerBatch ¶
type DiggerBatch struct { ID uuid.UUID `gorm:"primary_key"` VCS DiggerVCSType PrNumber int CommentId *int64 AiSummaryCommentId string Status orchestrator_scheduler.DiggerBatchStatus BranchName string DiggerConfig string GithubInstallationId int64 GitlabProjectId int RepoFullName string RepoOwner string RepoName string BatchType orchestrator_scheduler.DiggerCommand ReportTerraformOutputs bool // used for module source grouping comments SourceDetails []byte }
func (*DiggerBatch) MapToJsonStruct ¶
func (b *DiggerBatch) MapToJsonStruct() (orchestrator_scheduler.SerializedBatch, error)
type DiggerJob ¶
type DiggerJob struct { gorm.Model DiggerJobID string `gorm:"size:50,index:idx_digger_job_id"` Status orchestrator_scheduler.DiggerJobStatus Batch *DiggerBatch BatchID *string `gorm:"index:idx_digger_job_id"` PRCommentUrl string DiggerJobSummary DiggerJobSummary DiggerJobSummaryID uint SerializedJobSpec []byte TerraformOutput string // represents a footprint of terraform plan json for similarity checks PlanFootprint []byte WorkflowFile string WorkflowRunUrl *string StatusUpdatedAt time.Time }
func (*DiggerJob) MapToJsonStruct ¶
func (j *DiggerJob) MapToJsonStruct() (orchestrator_scheduler.SerializedJob, error)
type DiggerJobLinkStatus ¶
type DiggerJobLinkStatus int8
const ( DiggerJobLinkCreated DiggerJobLinkStatus = 1 DiggerJobLinkSucceeded DiggerJobLinkStatus = 2 )
type DiggerJobParentLink ¶
type DiggerJobSummary ¶
type DiggerLock ¶
type DiggerRun ¶
type DiggerRun struct { gorm.Model Triggertype string // pr_merge, manual_invocation, push_to_trunk PrNumber *int Status DiggerRunStatus CommitId string DiggerConfig string GithubInstallationId int64 RepoId uint Repo *Repo ProjectName string RunType RunType PlanStage DiggerRunStage PlanStageId *uint ApplyStage DiggerRunStage ApplyStageId *uint IsApproved bool ApprovalAuthor string ApprovalDate time.Time }
func (*DiggerRun) MapToJsonStruct ¶
type DiggerRunQueueItem ¶
type DiggerRunStage ¶
type DiggerRunStage struct { gorm.Model Batch *DiggerBatch BatchID *string `gorm:"index:idx_digger_run_batch_id"` }
func (DiggerRunStage) MapToJsonStruct ¶
func (r DiggerRunStage) MapToJsonStruct() (*SerializedRunStage, error)
type DiggerRunStatus ¶
type DiggerRunStatus string
const ( RunQueued DiggerRunStatus = "Queued" RunPendingPlan DiggerRunStatus = "Pending Plan" RunPlanning DiggerRunStatus = "Running Plan" RunPendingApproval DiggerRunStatus = "Pending Approval" RunApproved DiggerRunStatus = "Approved" RunPendingApply DiggerRunStatus = "Pending Apply" RunApplying DiggerRunStatus = "Running Apply" RunSucceeded DiggerRunStatus = "Succeeded" RunFailed DiggerRunStatus = "Failed" )
type DiggerVCSType ¶
type DiggerVCSType string
const DiggerVCSGithub DiggerVCSType = "github"
const DiggerVCSGitlab DiggerVCSType = "gitlab"
type GithubAppConnection ¶
type GithubAppInstallStatus ¶
type GithubAppInstallStatus int
const ( GithubAppInstallActive GithubAppInstallStatus = 1 GithubAppInstallDeleted GithubAppInstallStatus = 2 )
type GithubAppInstallation ¶
type GithubAppInstallationLink ¶
type GithubAppInstallationLink struct { gorm.Model GithubInstallationId int64 `gorm:"index:idx_github_installation_org"` OrganisationId uint `gorm:"index:idx_github_installation_org"` Organisation *Organisation Status GithubAppInstallationLinkStatus }
GithubAppInstallationLink links GitHub App installation Id to Digger's organisation Id
type GithubAppInstallationLinkStatus ¶
type GithubAppInstallationLinkStatus int8
const ( GithubAppInstallationLinkActive GithubAppInstallationLinkStatus = 1 GithubAppInstallationLinkInactive GithubAppInstallationLinkStatus = 2 )
type GithubDiggerJobLink ¶
type GithubDiggerJobLink struct { gorm.Model DiggerJobId string `gorm:"size:50,index:idx_digger_job_id"` RepoFullName string GithubJobId int64 `gorm:"index:idx_github_job_id"` GithubWorkflowRunId int64 Status DiggerJobLinkStatus }
GithubDiggerJobLink links GitHub Workflow Job id to Digger's Job Id
type JobArtefact ¶
type JobToken ¶
type JobToken struct { gorm.Model Value string `gorm:"uniqueJobTokenIndex:idx_token"` Expiry time.Time OrganisationID uint Organisation Organisation Type string // AccessTokenType starts with j: }
These tokens will be pre
type Organisation ¶
type Project ¶
type Project struct { gorm.Model Name string `gorm:"uniqueIndex:idx_project"` OrganisationID uint `gorm:"uniqueIndex:idx_project"` Organisation *Organisation RepoID uint `gorm:"uniqueIndex:idx_project"` Repo *Repo ConfigurationYaml string // TODO: probably needs to be deleted Status ProjectStatus IsGenerated bool IsInMainBranch bool }
func (*Project) MapToJsonStruct ¶
func (p *Project) MapToJsonStruct() interface{}
type ProjectRun ¶
type ProjectRun struct { gorm.Model ProjectID uint Project *Project StartedAt int64 EndedAt int64 Status string Command string Output string ActorUsername string }
func (*ProjectRun) MapToJsonStruct ¶
func (p *ProjectRun) MapToJsonStruct() interface{}
type ProjectStatus ¶
type ProjectStatus int
const ( ProjectActive ProjectStatus = 1 ProjectInactive ProjectStatus = 2 )
type RepoCache ¶
type RepoCache struct { gorm.Model OrgId uint RepoFullName string DiggerYmlStr string DiggerConfig []byte `gorm:"type:bytea"` }
storing repo cache such as digger.yml configuration
type SerializedRunStage ¶
type SerializedRunStage struct { //DiggerRunId uint `json:"digger_run_id"` DiggerJobId string `json:"digger_job_id"` Status orchestrator_scheduler.DiggerJobStatus `json:"status"` ProjectName string `json:"project_name"` WorkflowRunUrl *string `json:"workflow_run_url"` ResourcesCreated uint `json:"resources_created"` ResourcesDeleted uint `json:"resources_deleted"` ResourcesUpdated uint `json:"resources_updated"` LastActivityTimeStamp string `json:"last_activity_timestamp"` }