Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: github app #360

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions database/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Repo struct {
PipelineType sql.NullString `sql:"pipeline_type"`
PreviousName sql.NullString `sql:"previous_name"`
ApproveBuild sql.NullString `sql:"approve_build"`
InstallID sql.NullInt64 `sql:"install_id"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe GithubInstallID? Or SCMMetadata with a JSON field?

}

// Decrypt will manipulate the existing repo hash by
Expand Down Expand Up @@ -210,6 +211,11 @@ func (r *Repo) Nullify() *Repo {
r.ApproveBuild.Valid = false
}

// check if the InstallID field should be false
if r.InstallID.Int64 == 0 {
r.InstallID.Valid = false
}

return r
}

Expand Down Expand Up @@ -244,6 +250,7 @@ func (r *Repo) ToLibrary() *library.Repo {
repo.SetPipelineType(r.PipelineType.String)
repo.SetPreviousName(r.PreviousName.String)
repo.SetApproveBuild(r.ApproveBuild.String)
repo.SetInstallID(r.InstallID.Int64)

return repo
}
Expand Down Expand Up @@ -341,6 +348,7 @@ func RepoFromLibrary(r *library.Repo) *Repo {
PipelineType: sql.NullString{String: r.GetPipelineType(), Valid: true},
PreviousName: sql.NullString{String: r.GetPreviousName(), Valid: true},
ApproveBuild: sql.NullString{String: r.GetApproveBuild(), Valid: true},
InstallID: sql.NullInt64{Int64: r.GetInstallID(), Valid: true},
}

return repo.Nullify()
Expand Down
8 changes: 8 additions & 0 deletions database/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Step struct {
Host sql.NullString `sql:"host"`
Runtime sql.NullString `sql:"runtime"`
Distribution sql.NullString `sql:"distribution"`
CheckID sql.NullInt64 `sql:"check_id"`
}

// Nullify ensures the valid flag for
Expand Down Expand Up @@ -142,6 +143,11 @@ func (s *Step) Nullify() *Step {
s.Distribution.Valid = false
}

// check if the CheckID field should be false
if s.CheckID.Int64 == 0 {
s.CheckID.Valid = false
}

return s
}

Expand All @@ -166,6 +172,7 @@ func (s *Step) ToLibrary() *library.Step {
step.SetHost(s.Host.String)
step.SetRuntime(s.Runtime.String)
step.SetDistribution(s.Distribution.String)
step.SetCheckID(s.CheckID.Int64)

return step
}
Expand Down Expand Up @@ -233,6 +240,7 @@ func StepFromLibrary(s *library.Step) *Step {
Host: sql.NullString{String: s.GetHost(), Valid: true},
Runtime: sql.NullString{String: s.GetRuntime(), Valid: true},
Distribution: sql.NullString{String: s.GetDistribution(), Valid: true},
CheckID: sql.NullInt64{Int64: s.GetCheckID(), Valid: true},
}

return step.Nullify()
Expand Down
30 changes: 30 additions & 0 deletions library/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
PipelineType *string `json:"pipeline_type,omitempty"`
PreviousName *string `json:"previous_name,omitempty"`
ApproveBuild *string `json:"approve_build,omitempty"`
InstallID *int64 `json:"install_id,omitempty"`
}

// Environment returns a list of environment variables
Expand Down Expand Up @@ -64,6 +65,7 @@
"VELA_REPO_VISIBILITY": ToString(r.GetVisibility()),
"VELA_REPO_PIPELINE_TYPE": ToString(r.GetPipelineType()),
"VELA_REPO_APPROVE_BUILD": ToString(r.GetApproveBuild()),
"VELA_REPO_INSTALL_ID": ToString(r.GetInstallID()),

// deprecated environment variables
"REPOSITORY_ACTIVE": ToString(r.GetActive()),
Expand Down Expand Up @@ -424,6 +426,19 @@
return *r.ApproveBuild
}

// GetInstallID returns the InstallID field.
//
// When the provided Repo type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (r *Repo) GetInstallID() int64 {
// return zero value if Repo type or InstallID field is nil
if r == nil || r.InstallID == nil {
return 0
}

return *r.InstallID
}

// SetID sets the ID field.
//
// When the provided Repo type is nil, it
Expand Down Expand Up @@ -762,9 +777,22 @@
r.ApproveBuild = &v
}

// SetInstallID sets the InstallID field.
//
// When the provided Repo type is nil, it
// will set nothing and immediately return.
func (r *Repo) SetInstallID(v int64) {
// return if Repo type is nil
if r == nil {
return
}

r.InstallID = &v
}

// String implements the Stringer interface for the Repo type.
//
//nolint:dupl // ignore duplicate with test func

Check failure on line 795 in library/repo.go

View workflow job for this annotation

GitHub Actions / full-review

directive `//nolint:dupl // ignore duplicate with test func` is unused for linter "dupl" (nolintlint)

Check failure on line 795 in library/repo.go

View workflow job for this annotation

GitHub Actions / diff-review

directive `//nolint:dupl // ignore duplicate with test func` is unused for linter "dupl" (nolintlint)

Check failure on line 795 in library/repo.go

View workflow job for this annotation

GitHub Actions / diff-review

directive `//nolint:dupl // ignore duplicate with test func` is unused for linter "dupl" (nolintlint)

Check failure on line 795 in library/repo.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] library/repo.go#L795

directive `//nolint:dupl // ignore duplicate with test func` is unused for linter "dupl" (nolintlint)
Raw output
library/repo.go:795:1: directive `//nolint:dupl // ignore duplicate with test func` is unused for linter "dupl" (nolintlint)
//nolint:dupl // ignore duplicate with test func
^

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
directive //nolint:dupl // ignore duplicate with test func is unused for linter "dupl" (nolintlint)

func (r *Repo) String() string {
return fmt.Sprintf(`{
Active: %t,
Expand All @@ -781,6 +809,7 @@
Counter: %d,
FullName: %s,
ID: %d,
InstallID: %d,
Link: %s,
Name: %s,
Org: %s,
Expand All @@ -807,6 +836,7 @@
r.GetCounter(),
r.GetFullName(),
r.GetID(),
r.GetInstallID(),
r.GetLink(),
r.GetName(),
r.GetOrg(),
Expand Down
30 changes: 30 additions & 0 deletions library/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Step struct {
Host *string `json:"host,omitempty"`
Runtime *string `json:"runtime,omitempty"`
Distribution *string `json:"distribution,omitempty"`
CheckID *int64 `json:"check_id,omitempty"`
}

// Duration calculates and returns the total amount of
Expand Down Expand Up @@ -78,6 +79,7 @@ func (s *Step) Environment() map[string]string {
"VELA_STEP_STAGE": ToString(s.GetStage()),
"VELA_STEP_STARTED": ToString(s.GetStarted()),
"VELA_STEP_STATUS": ToString(s.GetStatus()),
"VELA_STEP_CHECK_ID": ToString(s.GetCheckID()),
}
}

Expand Down Expand Up @@ -289,6 +291,19 @@ func (s *Step) GetDistribution() string {
return *s.Distribution
}

// GetCheckID returns the CheckID field.
//
// When the provided Step type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (s *Step) GetCheckID() int64 {
// return zero value if Step type or CheckID field is nil
if s == nil || s.CheckID == nil {
return 0
}

return *s.CheckID
}

// SetID sets the ID field.
//
// When the provided Step type is nil, it
Expand Down Expand Up @@ -497,6 +512,19 @@ func (s *Step) SetDistribution(v string) {
s.Distribution = &v
}

// SetCheckID sets the CheckID field.
//
// When the provided Step type is nil, it
// will set nothing and immediately return.
func (s *Step) SetCheckID(v int64) {
// return if Step type is nil
if s == nil {
return
}

s.CheckID = &v
}

// String implements the Stringer interface for the Step type.
func (s *Step) String() string {
return fmt.Sprintf(`{
Expand All @@ -512,6 +540,7 @@ func (s *Step) String() string {
Name: %s,
Number: %d,
RepoID: %d,
CheckID: %d,
Runtime: %s,
Stage: %s,
Started: %d,
Expand All @@ -529,6 +558,7 @@ func (s *Step) String() string {
s.GetName(),
s.GetNumber(),
s.GetRepoID(),
s.GetCheckID(),
s.GetRuntime(),
s.GetStage(),
s.GetStarted(),
Expand Down
41 changes: 21 additions & 20 deletions pipeline/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,27 @@ type (
//
// swagger:model PipelineContainer
Container struct {
ID string `json:"id,omitempty" yaml:"id,omitempty"`
Commands []string `json:"commands,omitempty" yaml:"commands,omitempty"`
Detach bool `json:"detach,omitempty" yaml:"detach,omitempty"`
Directory string `json:"directory,omitempty" yaml:"directory,omitempty"`
Entrypoint []string `json:"entrypoint,omitempty" yaml:"entrypoint,omitempty"`
Environment map[string]string `json:"environment,omitempty" yaml:"environment,omitempty"`
ExitCode int `json:"exit_code,omitempty" yaml:"exit_code,omitempty"`
Image string `json:"image,omitempty" yaml:"image,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Needs []string `json:"needs,omitempty" yaml:"needs,omitempty"`
Networks []string `json:"networks,omitempty" yaml:"networks,omitempty"`
Number int `json:"number,omitempty" yaml:"number,omitempty"`
Ports []string `json:"ports,omitempty" yaml:"ports,omitempty"`
Privileged bool `json:"privileged,omitempty" yaml:"privileged,omitempty"`
Pull string `json:"pull,omitempty" yaml:"pull,omitempty"`
Ruleset Ruleset `json:"ruleset,omitempty" yaml:"ruleset,omitempty"`
Secrets StepSecretSlice `json:"secrets,omitempty" yaml:"secrets,omitempty"`
Ulimits UlimitSlice `json:"ulimits,omitempty" yaml:"ulimits,omitempty"`
Volumes VolumeSlice `json:"volumes,omitempty" yaml:"volumes,omitempty"`
User string `json:"user,omitempty" yaml:"user,omitempty"`
ID string `json:"id,omitempty" yaml:"id,omitempty"`
Commands []string `json:"commands,omitempty" yaml:"commands,omitempty"`
Detach bool `json:"detach,omitempty" yaml:"detach,omitempty"`
Directory string `json:"directory,omitempty" yaml:"directory,omitempty"`
Entrypoint []string `json:"entrypoint,omitempty" yaml:"entrypoint,omitempty"`
Environment map[string]string `json:"environment,omitempty" yaml:"environment,omitempty"`
ExitCode int `json:"exit_code,omitempty" yaml:"exit_code,omitempty"`
Image string `json:"image,omitempty" yaml:"image,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Needs []string `json:"needs,omitempty" yaml:"needs,omitempty"`
Networks []string `json:"networks,omitempty" yaml:"networks,omitempty"`
Number int `json:"number,omitempty" yaml:"number,omitempty"`
Ports []string `json:"ports,omitempty" yaml:"ports,omitempty"`
Privileged bool `json:"privileged,omitempty" yaml:"privileged,omitempty"`
Pull string `json:"pull,omitempty" yaml:"pull,omitempty"`
Ruleset Ruleset `json:"ruleset,omitempty" yaml:"ruleset,omitempty"`
Secrets StepSecretSlice `json:"secrets,omitempty" yaml:"secrets,omitempty"`
Ulimits UlimitSlice `json:"ulimits,omitempty" yaml:"ulimits,omitempty"`
Volumes VolumeSlice `json:"volumes,omitempty" yaml:"volumes,omitempty"`
User string `json:"user,omitempty" yaml:"user,omitempty"`
ReportStatus bool `json:"report_status,omitempty" yaml:"report_status,omitempty"`
}
)

Expand Down
58 changes: 30 additions & 28 deletions yaml/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ type (
// Step is the yaml representation of a step
// from the steps block for a pipeline.
Step struct {
Ruleset Ruleset `yaml:"ruleset,omitempty" json:"ruleset,omitempty" jsonschema:"description=Conditions to limit the execution of the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-ruleset-tag"`
Commands raw.StringSlice `yaml:"commands,omitempty" json:"commands,omitempty" jsonschema:"description=Execution instructions to run inside the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-commands-tag"`
Entrypoint raw.StringSlice `yaml:"entrypoint,omitempty" json:"entrypoint,omitempty" jsonschema:"description=Command to execute inside the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-entrypoint-tag"`
Secrets StepSecretSlice `yaml:"secrets,omitempty" json:"secrets,omitempty" jsonschema:"description=Sensitive variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-secrets-tag"`
Template StepTemplate `yaml:"template,omitempty" json:"template,omitempty" jsonschema:"oneof_required=template,description=Name of template to expand in the pipeline.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-template-tag"`
Ulimits UlimitSlice `yaml:"ulimits,omitempty" json:"ulimits,omitempty" jsonschema:"description=Set the user limits for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-ulimits-tag"`
Volumes VolumeSlice `yaml:"volumes,omitempty" json:"volumes,omitempty" jsonschema:"description=Mount volumes for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-volume-tag"`
Image string `yaml:"image,omitempty" json:"image,omitempty" jsonschema:"oneof_required=image,minLength=1,description=Docker image to use to create the ephemeral container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-image-tag"`
Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"required,minLength=1,description=Unique name for the step.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-name-tag"`
Pull string `yaml:"pull,omitempty" json:"pull,omitempty" jsonschema:"enum=always,enum=not_present,enum=on_start,enum=never,default=not_present,description=Declaration to configure if and when the Docker image is pulled.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-pull-tag"`
Environment raw.StringSliceMap `yaml:"environment,omitempty" json:"environment,omitempty" jsonschema:"description=Provide environment variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-environment-tag"`
Parameters map[string]interface{} `yaml:"parameters,omitempty" json:"parameters,omitempty" jsonschema:"description=Extra configuration variables for a plugin.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-parameters-tag"`
Detach bool `yaml:"detach,omitempty" json:"detach,omitempty" jsonschema:"description=Run the container in a detached (headless) state.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-detach-tag"`
Privileged bool `yaml:"privileged,omitempty" json:"privileged,omitempty" jsonschema:"description=Run the container with extra privileges.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-privileged-tag"`
User string `yaml:"user,omitempty" json:"user,omitempty" jsonschema:"description=Set the user for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-user-tag"`
Ruleset Ruleset `yaml:"ruleset,omitempty" json:"ruleset,omitempty" jsonschema:"description=Conditions to limit the execution of the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-ruleset-tag"`
Commands raw.StringSlice `yaml:"commands,omitempty" json:"commands,omitempty" jsonschema:"description=Execution instructions to run inside the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-commands-tag"`
Entrypoint raw.StringSlice `yaml:"entrypoint,omitempty" json:"entrypoint,omitempty" jsonschema:"description=Command to execute inside the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-entrypoint-tag"`
Secrets StepSecretSlice `yaml:"secrets,omitempty" json:"secrets,omitempty" jsonschema:"description=Sensitive variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-secrets-tag"`
Template StepTemplate `yaml:"template,omitempty" json:"template,omitempty" jsonschema:"oneof_required=template,description=Name of template to expand in the pipeline.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-template-tag"`
Ulimits UlimitSlice `yaml:"ulimits,omitempty" json:"ulimits,omitempty" jsonschema:"description=Set the user limits for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-ulimits-tag"`
Volumes VolumeSlice `yaml:"volumes,omitempty" json:"volumes,omitempty" jsonschema:"description=Mount volumes for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-volume-tag"`
Image string `yaml:"image,omitempty" json:"image,omitempty" jsonschema:"oneof_required=image,minLength=1,description=Docker image to use to create the ephemeral container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-image-tag"`
Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"required,minLength=1,description=Unique name for the step.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-name-tag"`
Pull string `yaml:"pull,omitempty" json:"pull,omitempty" jsonschema:"enum=always,enum=not_present,enum=on_start,enum=never,default=not_present,description=Declaration to configure if and when the Docker image is pulled.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-pull-tag"`
Environment raw.StringSliceMap `yaml:"environment,omitempty" json:"environment,omitempty" jsonschema:"description=Provide environment variables injected into the container environment.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-environment-tag"`
Parameters map[string]interface{} `yaml:"parameters,omitempty" json:"parameters,omitempty" jsonschema:"description=Extra configuration variables for a plugin.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-parameters-tag"`
Detach bool `yaml:"detach,omitempty" json:"detach,omitempty" jsonschema:"description=Run the container in a detached (headless) state.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-detach-tag"`
Privileged bool `yaml:"privileged,omitempty" json:"privileged,omitempty" jsonschema:"description=Run the container with extra privileges.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-privileged-tag"`
User string `yaml:"user,omitempty" json:"user,omitempty" jsonschema:"description=Set the user for the container.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-user-tag"`
ReportStatus bool `yaml:"report_status,omitempty" json:"report_status,omitempty" jsonschema:"description=Report the status of the container to the SCM.\nReference: https://go-vela.github.io/docs/reference/yaml/steps/#the-report_status-tag"`
}
)

Expand All @@ -47,19 +48,20 @@ func (s *StepSlice) ToPipeline() *pipeline.ContainerSlice {
for _, step := range *s {
// append the element to the pipeline container slice
*stepSlice = append(*stepSlice, &pipeline.Container{
Commands: step.Commands,
Detach: step.Detach,
Entrypoint: step.Entrypoint,
Environment: step.Environment,
Image: step.Image,
Name: step.Name,
Privileged: step.Privileged,
Pull: step.Pull,
Ruleset: *step.Ruleset.ToPipeline(),
Secrets: *step.Secrets.ToPipeline(),
Ulimits: *step.Ulimits.ToPipeline(),
Volumes: *step.Volumes.ToPipeline(),
User: step.User,
Commands: step.Commands,
Detach: step.Detach,
Entrypoint: step.Entrypoint,
Environment: step.Environment,
Image: step.Image,
Name: step.Name,
Privileged: step.Privileged,
Pull: step.Pull,
Ruleset: *step.Ruleset.ToPipeline(),
Secrets: *step.Secrets.ToPipeline(),
Ulimits: *step.Ulimits.ToPipeline(),
Volumes: *step.Volumes.ToPipeline(),
User: step.User,
ReportStatus: step.ReportStatus,
})
}

Expand Down
Loading