Skip to content

Commit

Permalink
Merge branch 'main' into feat/dashboard/library-db-types
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper authored Apr 2, 2024
2 parents 273daf6 + f16c3e4 commit 4e6f169
Show file tree
Hide file tree
Showing 42 changed files with 867 additions and 631 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
uses: github/codeql-action/init@05963f47d870e2cb19a537396c1f668a348c7d8f # v3.24.8
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -58,7 +58,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
uses: github/codeql-action/autobuild@05963f47d870e2cb19a537396c1f668a348c7d8f # v3.24.8

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -72,4 +72,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@47b3d888fe66b639e431abf22ebca059152f1eea # v3.24.5
uses: github/codeql-action/analyze@05963f47d870e2cb19a537396c1f668a348c7d8f # v3.24.8
4 changes: 2 additions & 2 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
check-latest: true

- name: golangci-lint
uses: reviewdog/action-golangci-lint@8e1117c7d327bbfb1eb7ec8dc2d895d13e6e17c3 # v2.6.0
uses: reviewdog/action-golangci-lint@00311c26a97213f93f2fd3a3524d66762e956ae0 # v2.6.1
with:
github_token: ${{ secrets.github_token }}
golangci_lint_flags: "--config=.golangci.yml"
Expand All @@ -47,7 +47,7 @@ jobs:
check-latest: true

- name: golangci-lint
uses: reviewdog/action-golangci-lint@8e1117c7d327bbfb1eb7ec8dc2d895d13e6e17c3 # v2.6.0
uses: reviewdog/action-golangci-lint@00311c26a97213f93f2fd3a3524d66762e956ae0 # v2.6.1
with:
github_token: ${{ secrets.github_token }}
golangci_lint_flags: "--config=.golangci.yml"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
go test -race -covermode=atomic -coverprofile=coverage.out ./...
- name: coverage
uses: codecov/codecov-action@e0b68c6749509c5f83f984dd99a76a1c1a231044 # v4.0.1
uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4.1.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.out
9 changes: 9 additions & 0 deletions constants/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const (
// ActionSynchronize defines the action for the synchronizing of pull requests.
ActionSynchronize = "synchronize"

// ActionLabeled defines the action for the labeling of pull requests.
ActionLabeled = "labeled"

// ActionUnlabeled defines the action for the unlabeling of pull requests.
ActionUnlabeled = "unlabeled"

// ActionTransferred defines the action for transferring repository ownership.
ActionTransferred = "transferred"

Expand All @@ -30,4 +36,7 @@ const (

// ActionTag defines the action for deleting a tag.
ActionTag = "tag"

// ActionRun defines the action for running a schedule.
ActionRun = "run"
)
3 changes: 2 additions & 1 deletion constants/allow_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (
AllowPullSync
_ // AllowPullAssigned - Not Implemented
_ // AllowPullMilestoned - Not Implemented
_ // AllowPullLabel - Not Implemented
AllowPullLabel
_ // AllowPullLocked - Not Implemented
_ // AllowPullReady - Not Implemented
AllowPullReopen
Expand All @@ -23,4 +23,5 @@ const (
AllowSchedule
AllowPushDeleteBranch
AllowPushDeleteTag
AllowPullUnlabel
)
8 changes: 8 additions & 0 deletions constants/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ const (

// EventTag defines the event type for build and repo tag events.
EventTag = "tag"

// Alternates for common user inputs that do not match our set constants.

// EventPullAlternate defines the alternate event type for build and repo pull_request events.
EventPullAlternate = "pull"

// EventDeployAlternate defines the alternate event type for build and repo deployment events.
EventDeployAlternate = "deploy"
)
3 changes: 3 additions & 0 deletions constants/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ const (

// DeployBuildsMaxSize defines the maximum size in characters for deployment builds.
DeployBuildsMaxSize = 500

// ReportStepStatusLimit defines the maximum number of steps in a pipeline that may report their status to the SCM.
ReportStepStatusLimit = 10
)
15 changes: 0 additions & 15 deletions database/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ type Repo struct {
Private sql.NullBool `sql:"private"`
Trusted sql.NullBool `sql:"trusted"`
Active sql.NullBool `sql:"active"`
AllowPull sql.NullBool `sql:"allow_pull"`
AllowPush sql.NullBool `sql:"allow_push"`
AllowDeploy sql.NullBool `sql:"allow_deploy"`
AllowTag sql.NullBool `sql:"allow_tag"`
AllowComment sql.NullBool `sql:"allow_comment"`
AllowEvents sql.NullInt64 `sql:"allow_events"`
PipelineType sql.NullString `sql:"pipeline_type"`
PreviousName sql.NullString `sql:"previous_name"`
Expand Down Expand Up @@ -235,11 +230,6 @@ func (r *Repo) ToLibrary() *library.Repo {
repo.SetPrivate(r.Private.Bool)
repo.SetTrusted(r.Trusted.Bool)
repo.SetActive(r.Active.Bool)
repo.SetAllowPull(r.AllowPull.Bool)
repo.SetAllowPush(r.AllowPush.Bool)
repo.SetAllowDeploy(r.AllowDeploy.Bool)
repo.SetAllowTag(r.AllowTag.Bool)
repo.SetAllowComment(r.AllowComment.Bool)
repo.SetAllowEvents(library.NewEventsFromMask(r.AllowEvents.Int64))
repo.SetPipelineType(r.PipelineType.String)
repo.SetPreviousName(r.PreviousName.String)
Expand Down Expand Up @@ -332,11 +322,6 @@ func RepoFromLibrary(r *library.Repo) *Repo {
Private: sql.NullBool{Bool: r.GetPrivate(), Valid: true},
Trusted: sql.NullBool{Bool: r.GetTrusted(), Valid: true},
Active: sql.NullBool{Bool: r.GetActive(), Valid: true},
AllowPull: sql.NullBool{Bool: r.GetAllowPull(), Valid: true},
AllowPush: sql.NullBool{Bool: r.GetAllowPush(), Valid: true},
AllowDeploy: sql.NullBool{Bool: r.GetAllowDeploy(), Valid: true},
AllowTag: sql.NullBool{Bool: r.GetAllowTag(), Valid: true},
AllowComment: sql.NullBool{Bool: r.GetAllowComment(), Valid: true},
AllowEvents: sql.NullInt64{Int64: r.GetAllowEvents().ToDatabase(), Valid: true},
PipelineType: sql.NullString{String: r.GetPipelineType(), Valid: true},
PreviousName: sql.NullString{String: r.GetPreviousName(), Valid: true},
Expand Down
15 changes: 0 additions & 15 deletions database/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ func TestDatabase_Repo_ToLibrary(t *testing.T) {
want.SetPrivate(false)
want.SetTrusted(false)
want.SetActive(true)
want.SetAllowPull(false)
want.SetAllowPush(true)
want.SetAllowDeploy(false)
want.SetAllowTag(false)
want.SetAllowComment(false)
want.SetAllowEvents(e)
want.SetPipelineType("yaml")
want.SetPreviousName("oldName")
Expand Down Expand Up @@ -332,11 +327,6 @@ func TestDatabase_RepoFromLibrary(t *testing.T) {
r.SetPrivate(false)
r.SetTrusted(false)
r.SetActive(true)
r.SetAllowPull(false)
r.SetAllowPush(true)
r.SetAllowDeploy(false)
r.SetAllowTag(false)
r.SetAllowComment(false)
r.SetAllowEvents(e)
r.SetPipelineType("yaml")
r.SetPreviousName("oldName")
Expand Down Expand Up @@ -373,11 +363,6 @@ func testRepo() *Repo {
Private: sql.NullBool{Bool: false, Valid: true},
Trusted: sql.NullBool{Bool: false, Valid: true},
Active: sql.NullBool{Bool: true, Valid: true},
AllowPull: sql.NullBool{Bool: false, Valid: true},
AllowPush: sql.NullBool{Bool: true, Valid: true},
AllowDeploy: sql.NullBool{Bool: false, Valid: true},
AllowTag: sql.NullBool{Bool: false, Valid: true},
AllowComment: sql.NullBool{Bool: false, Valid: true},
AllowEvents: sql.NullInt64{Int64: 1, Valid: true},
PipelineType: sql.NullString{String: "yaml", Valid: true},
PreviousName: sql.NullString{String: "oldName", Valid: true},
Expand Down
2 changes: 2 additions & 0 deletions database/schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ func TestDatabase_Schedule_Validate(t *testing.T) {
if err == nil {
t.Errorf("Validate should have returned err")
}

return
}

if err != nil {
t.Errorf("Validate returned err: %v", err)
}
Expand Down
68 changes: 31 additions & 37 deletions database/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ var (

// Secret is the database representation of a secret.
type Secret struct {
ID sql.NullInt64 `sql:"id"`
Org sql.NullString `sql:"org"`
Repo sql.NullString `sql:"repo"`
Team sql.NullString `sql:"team"`
Name sql.NullString `sql:"name"`
Value sql.NullString `sql:"value"`
Type sql.NullString `sql:"type"`
Images pq.StringArray `sql:"images" gorm:"type:varchar(1000)"`
Events pq.StringArray `sql:"events" gorm:"type:varchar(1000)"`
AllowEvents sql.NullInt64 `sql:"allow_events"`
AllowCommand sql.NullBool `sql:"allow_command"`
CreatedAt sql.NullInt64 `sql:"created_at"`
CreatedBy sql.NullString `sql:"created_by"`
UpdatedAt sql.NullInt64 `sql:"updated_at"`
UpdatedBy sql.NullString `sql:"updated_by"`
ID sql.NullInt64 `sql:"id"`
Org sql.NullString `sql:"org"`
Repo sql.NullString `sql:"repo"`
Team sql.NullString `sql:"team"`
Name sql.NullString `sql:"name"`
Value sql.NullString `sql:"value"`
Type sql.NullString `sql:"type"`
Images pq.StringArray `sql:"images" gorm:"type:varchar(1000)"`
AllowEvents sql.NullInt64 `sql:"allow_events"`
AllowCommand sql.NullBool `sql:"allow_command"`
AllowSubstitution sql.NullBool `sql:"allow_substitution"`
CreatedAt sql.NullInt64 `sql:"created_at"`
CreatedBy sql.NullString `sql:"created_by"`
UpdatedAt sql.NullInt64 `sql:"updated_at"`
UpdatedBy sql.NullString `sql:"updated_by"`
}

// Decrypt will manipulate the existing secret value by
Expand Down Expand Up @@ -193,9 +193,9 @@ func (s *Secret) ToLibrary() *library.Secret {
secret.SetValue(s.Value.String)
secret.SetType(s.Type.String)
secret.SetImages(s.Images)
secret.SetEvents(s.Events)
secret.SetAllowEvents(library.NewEventsFromMask(s.AllowEvents.Int64))
secret.SetAllowCommand(s.AllowCommand.Bool)
secret.SetAllowSubstitution(s.AllowSubstitution.Bool)
secret.SetCreatedAt(s.CreatedAt.Int64)
secret.SetCreatedBy(s.CreatedBy.String)
secret.SetUpdatedAt(s.UpdatedAt.Int64)
Expand Down Expand Up @@ -259,34 +259,28 @@ func (s *Secret) Validate() error {
s.Images[i] = sanitize(v)
}

// ensure that all Events are sanitized
// to avoid unsafe HTML content
for i, v := range s.Events {
s.Events[i] = sanitize(v)
}

return nil
}

// SecretFromLibrary converts the library Secret type
// to a database Secret type.
func SecretFromLibrary(s *library.Secret) *Secret {
secret := &Secret{
ID: sql.NullInt64{Int64: s.GetID(), Valid: true},
Org: sql.NullString{String: s.GetOrg(), Valid: true},
Repo: sql.NullString{String: s.GetRepo(), Valid: true},
Team: sql.NullString{String: s.GetTeam(), Valid: true},
Name: sql.NullString{String: s.GetName(), Valid: true},
Value: sql.NullString{String: s.GetValue(), Valid: true},
Type: sql.NullString{String: s.GetType(), Valid: true},
Images: pq.StringArray(s.GetImages()),
Events: pq.StringArray(s.GetEvents()),
AllowEvents: sql.NullInt64{Int64: s.GetAllowEvents().ToDatabase(), Valid: true},
AllowCommand: sql.NullBool{Bool: s.GetAllowCommand(), Valid: true},
CreatedAt: sql.NullInt64{Int64: s.GetCreatedAt(), Valid: true},
CreatedBy: sql.NullString{String: s.GetCreatedBy(), Valid: true},
UpdatedAt: sql.NullInt64{Int64: s.GetUpdatedAt(), Valid: true},
UpdatedBy: sql.NullString{String: s.GetUpdatedBy(), Valid: true},
ID: sql.NullInt64{Int64: s.GetID(), Valid: true},
Org: sql.NullString{String: s.GetOrg(), Valid: true},
Repo: sql.NullString{String: s.GetRepo(), Valid: true},
Team: sql.NullString{String: s.GetTeam(), Valid: true},
Name: sql.NullString{String: s.GetName(), Valid: true},
Value: sql.NullString{String: s.GetValue(), Valid: true},
Type: sql.NullString{String: s.GetType(), Valid: true},
Images: pq.StringArray(s.GetImages()),
AllowEvents: sql.NullInt64{Int64: s.GetAllowEvents().ToDatabase(), Valid: true},
AllowCommand: sql.NullBool{Bool: s.GetAllowCommand(), Valid: true},
AllowSubstitution: sql.NullBool{Bool: s.GetAllowSubstitution(), Valid: true},
CreatedAt: sql.NullInt64{Int64: s.GetCreatedAt(), Valid: true},
CreatedBy: sql.NullString{String: s.GetCreatedBy(), Valid: true},
UpdatedAt: sql.NullInt64{Int64: s.GetUpdatedAt(), Valid: true},
UpdatedBy: sql.NullString{String: s.GetUpdatedBy(), Valid: true},
}

return secret.Nullify()
Expand Down
34 changes: 17 additions & 17 deletions database/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ func TestDatabase_Secret_ToLibrary(t *testing.T) {
want.SetValue("bar")
want.SetType("repo")
want.SetImages([]string{"alpine"})
want.SetEvents([]string{"push", "tag", "deployment"})
want.SetAllowEvents(library.NewEventsFromMask(1))
want.SetAllowCommand(true)
want.SetAllowSubstitution(true)
want.SetCreatedAt(tsCreate)
want.SetCreatedBy("octocat")
want.SetUpdatedAt(tsUpdate)
Expand Down Expand Up @@ -292,9 +292,9 @@ func TestDatabase_SecretFromLibrary(t *testing.T) {
s.SetValue("bar")
s.SetType("repo")
s.SetImages([]string{"alpine"})
s.SetEvents([]string{"push", "tag", "deployment"})
s.SetAllowEvents(library.NewEventsFromMask(1))
s.SetAllowCommand(true)
s.SetAllowSubstitution(true)
s.SetCreatedAt(tsCreate)
s.SetCreatedBy("octocat")
s.SetUpdatedAt(tsUpdate)
Expand All @@ -314,20 +314,20 @@ func TestDatabase_SecretFromLibrary(t *testing.T) {
// type with all fields set to a fake value.
func testSecret() *Secret {
return &Secret{
ID: sql.NullInt64{Int64: 1, Valid: true},
Org: sql.NullString{String: "github", Valid: true},
Repo: sql.NullString{String: "octocat", Valid: true},
Team: sql.NullString{String: "octokitties", Valid: true},
Name: sql.NullString{String: "foo", Valid: true},
Value: sql.NullString{String: "bar", Valid: true},
Type: sql.NullString{String: "repo", Valid: true},
Images: []string{"alpine"},
Events: []string{"push", "tag", "deployment"},
AllowEvents: sql.NullInt64{Int64: 1, Valid: true},
AllowCommand: sql.NullBool{Bool: true, Valid: true},
CreatedAt: sql.NullInt64{Int64: tsCreate, Valid: true},
CreatedBy: sql.NullString{String: "octocat", Valid: true},
UpdatedAt: sql.NullInt64{Int64: tsUpdate, Valid: true},
UpdatedBy: sql.NullString{String: "octocat2", Valid: true},
ID: sql.NullInt64{Int64: 1, Valid: true},
Org: sql.NullString{String: "github", Valid: true},
Repo: sql.NullString{String: "octocat", Valid: true},
Team: sql.NullString{String: "octokitties", Valid: true},
Name: sql.NullString{String: "foo", Valid: true},
Value: sql.NullString{String: "bar", Valid: true},
Type: sql.NullString{String: "repo", Valid: true},
Images: []string{"alpine"},
AllowEvents: sql.NullInt64{Int64: 1, Valid: true},
AllowCommand: sql.NullBool{Bool: true, Valid: true},
AllowSubstitution: sql.NullBool{Bool: true, Valid: true},
CreatedAt: sql.NullInt64{Int64: tsCreate, Valid: true},
CreatedBy: sql.NullString{String: "octocat", Valid: true},
UpdatedAt: sql.NullInt64{Int64: tsUpdate, Valid: true},
UpdatedBy: sql.NullString{String: "octocat2", Valid: true},
}
}
9 changes: 9 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"`
ReportAs sql.NullString `sql:"report_as"`
}

// 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 ReportAs field should be false
if len(s.ReportAs.String) == 0 {
s.ReportAs.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.SetReportAs(s.ReportAs.String)

return step
}
Expand Down Expand Up @@ -209,6 +216,7 @@ func (s *Step) Validate() error {
s.Host = sql.NullString{String: sanitize(s.Host.String), Valid: s.Host.Valid}
s.Runtime = sql.NullString{String: sanitize(s.Runtime.String), Valid: s.Runtime.Valid}
s.Distribution = sql.NullString{String: sanitize(s.Distribution.String), Valid: s.Distribution.Valid}
s.ReportAs = sql.NullString{String: sanitize(s.ReportAs.String), Valid: s.ReportAs.Valid}

return nil
}
Expand All @@ -233,6 +241,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},
ReportAs: sql.NullString{String: s.GetReportAs(), Valid: true},
}

return step.Nullify()
Expand Down
Loading

0 comments on commit 4e6f169

Please sign in to comment.