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

Wire new Release + SDLC Core Entities #3839

Merged
merged 11 commits into from
Jul 12, 2024
6 changes: 4 additions & 2 deletions cmd/dev/app/rule_type/rttst.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ func readEntityFromFile(fpath string, entType minderv1.Entity) (protoreflect.Pro
out = &minderv1.Artifact{}
case minderv1.Entity_ENTITY_PULL_REQUESTS:
out = &minderv1.PullRequest{}
case minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS:
return nil, fmt.Errorf("build environments not yet supported")
case minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS, minderv1.Entity_ENTITY_RELEASE,
minderv1.Entity_ENTITY_PIPELINE_RUN,
minderv1.Entity_ENTITY_TASK_RUN, minderv1.Entity_ENTITY_BUILD:
return nil, fmt.Errorf("entity type not yet supported")
case minderv1.Entity_ENTITY_UNSPECIFIED:
return nil, fmt.Errorf("entity type unspecified")
default:
Expand Down
13 changes: 13 additions & 0 deletions database/migrations/000074_sdlc_entities.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Copyright 2024 Stacklok, Inc
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
22 changes: 22 additions & 0 deletions database/migrations/000074_sdlc_entities.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Copyright 2024 Stacklok, Inc
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

BEGIN TRANSACTION;

ALTER TYPE entities ADD VALUE 'release';
ALTER TYPE entities ADD VALUE 'pipeline_run';
ALTER TYPE entities ADD VALUE 'task_run';
ALTER TYPE entities ADD VALUE 'build';

COMMIT;
32 changes: 32 additions & 0 deletions docs/docs/ref/proto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion internal/controlplane/handlers_evalstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,14 @@ func dbEntityToEntity(dbEnt db.Entities) minderv1.Entity {
return minderv1.Entity_ENTITY_REPOSITORIES
case db.EntitiesBuildEnvironment:
return minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS
case db.EntitiesRelease:
return minderv1.Entity_ENTITY_RELEASE
case db.EntitiesPipelineRun:
return minderv1.Entity_ENTITY_PIPELINE_RUN
case db.EntitiesTaskRun:
return minderv1.Entity_ENTITY_TASK_RUN
case db.EntitiesBuild:
return minderv1.Entity_ENTITY_BUILD
default:
return minderv1.Entity_ENTITY_UNSPECIFIED
}
Expand Down Expand Up @@ -628,7 +636,8 @@ func getEntityName(
row.RepoOwner.String,
row.RepoName.String,
), nil
case db.EntitiesBuildEnvironment:
case db.EntitiesBuildEnvironment, db.EntitiesRelease,
db.EntitiesPipelineRun, db.EntitiesTaskRun, db.EntitiesBuild:
return "", errors.New("invalid entity type")
default:
return "", errors.New("invalid entity type")
Expand Down
4 changes: 4 additions & 0 deletions internal/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions internal/eea/eea.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,11 @@ func (e *EEA) buildEntityWrapper(
return e.buildArtifactInfoWrapper(ctx, repoID, projID, artID)
case db.EntitiesPullRequest:
return e.buildPullRequestInfoWrapper(ctx, repoID, projID, prID)
case db.EntitiesBuildEnvironment:
return nil, fmt.Errorf("build environment entity not supported")
case db.EntitiesBuildEnvironment, db.EntitiesRelease,
db.EntitiesPipelineRun, db.EntitiesTaskRun, db.EntitiesBuild:
return nil, fmt.Errorf("entity type %q not yet supported", entity)
default:
return nil, fmt.Errorf("unknown entity type: %s", entity)
return nil, fmt.Errorf("unknown entity type: %q", entity)
}
}

Expand Down
16 changes: 16 additions & 0 deletions internal/engine/entities/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ func EntityTypeFromDB(entity db.Entities) minderv1.Entity {
return minderv1.Entity_ENTITY_ARTIFACTS
case db.EntitiesPullRequest:
return minderv1.Entity_ENTITY_PULL_REQUESTS
case db.EntitiesRelease:
return minderv1.Entity_ENTITY_RELEASE
case db.EntitiesPipelineRun:
return minderv1.Entity_ENTITY_PIPELINE_RUN
case db.EntitiesTaskRun:
return minderv1.Entity_ENTITY_TASK_RUN
case db.EntitiesBuild:
return minderv1.Entity_ENTITY_BUILD
default:
return minderv1.Entity_ENTITY_UNSPECIFIED
}
Expand All @@ -74,6 +82,14 @@ func EntityTypeToDB(entity minderv1.Entity) db.Entities {
dbEnt = db.EntitiesArtifact
case minderv1.Entity_ENTITY_PULL_REQUESTS:
dbEnt = db.EntitiesPullRequest
case minderv1.Entity_ENTITY_RELEASE:
dbEnt = db.EntitiesRelease
case minderv1.Entity_ENTITY_PIPELINE_RUN:
dbEnt = db.EntitiesPipelineRun
case minderv1.Entity_ENTITY_TASK_RUN:
dbEnt = db.EntitiesTaskRun
case minderv1.Entity_ENTITY_BUILD:
dbEnt = db.EntitiesBuild
case minderv1.Entity_ENTITY_UNSPECIFIED:
// This shouldn't happen
}
Expand Down
76 changes: 76 additions & 0 deletions internal/engine/entities/entity_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ const (
ArtifactIDEventKey = "artifact_id"
// PullRequestIDEventKey is the key for the pull request ID
PullRequestIDEventKey = "pull_request_id"
// ReleaseIDEventKey is the key for the pull request ID
ReleaseIDEventKey = "release_id"
// PipelineRunIDEventKey is the key for a pipeline run
PipelineRunIDEventKey = "pipeline_run_id"
// TaskRunIDEventKey is the key for a task run
TaskRunIDEventKey = "task_run_id"
// BuildIDEventKey is the key for a build
BuildIDEventKey = "build_run_id"
// ExecutionIDKey is the key for the execution ID. This is set when acquiring a lock.
ExecutionIDKey = "execution_id"
// ActionEventKey is the key for the action event
Expand Down Expand Up @@ -129,6 +137,38 @@ func (eiw *EntityInfoWrapper) WithPullRequest(p *minderv1.PullRequest) *EntityIn
return eiw
}

// WithRelease sets a Release as the entity of the wrapper
func (eiw *EntityInfoWrapper) WithRelease(r *minderv1.Release) *EntityInfoWrapper {
eiw.Type = minderv1.Entity_ENTITY_RELEASE
eiw.Entity = r

return eiw
}

// WithPipelineRun sets a PipelineRun as the entity of the wrapper
func (eiw *EntityInfoWrapper) WithPipelineRun(plr *minderv1.PipelineRun) *EntityInfoWrapper {
eiw.Type = minderv1.Entity_ENTITY_PIPELINE_RUN
eiw.Entity = plr

return eiw
}

// WithTaskRun sets a TaskRun as the entity of the wrapper
func (eiw *EntityInfoWrapper) WithTaskRun(tr *minderv1.TaskRun) *EntityInfoWrapper {
eiw.Type = minderv1.Entity_ENTITY_TASK_RUN
eiw.Entity = tr

return eiw
}

// WithBuild sets a Build as the entity of the wrapper
func (eiw *EntityInfoWrapper) WithBuild(tr *minderv1.Build) *EntityInfoWrapper {
eiw.Type = minderv1.Entity_ENTITY_TASK_RUN
eiw.Entity = tr

return eiw
}

// WithProjectID sets the project ID
func (eiw *EntityInfoWrapper) WithProjectID(id uuid.UUID) *EntityInfoWrapper {
eiw.ProjectID = id
Expand Down Expand Up @@ -157,6 +197,34 @@ func (eiw *EntityInfoWrapper) WithPullRequestID(id uuid.UUID) *EntityInfoWrapper
return eiw
}

// WithReleaseID sets the release ID
func (eiw *EntityInfoWrapper) WithReleaseID(id uuid.UUID) *EntityInfoWrapper {
eiw.withID(ReleaseIDEventKey, id.String())

return eiw
}

// WithPipelineRunID sets the pipeline run ID
func (eiw *EntityInfoWrapper) WithPipelineRunID(id uuid.UUID) *EntityInfoWrapper {
eiw.withID(PipelineRunIDEventKey, id.String())

return eiw
}

// WithTaskRunID sets the pipeline run ID
func (eiw *EntityInfoWrapper) WithTaskRunID(id uuid.UUID) *EntityInfoWrapper {
eiw.withID(TaskRunIDEventKey, id.String())

return eiw
}

// WithBuildID sets the pipeline run ID
func (eiw *EntityInfoWrapper) WithBuildID(id uuid.UUID) *EntityInfoWrapper {
eiw.withID(BuildIDEventKey, id.String())

return eiw
}

// WithExecutionID sets the execution ID
func (eiw *EntityInfoWrapper) WithExecutionID(id uuid.UUID) *EntityInfoWrapper {
eiw.ExecutionID = &id
Expand Down Expand Up @@ -368,6 +436,14 @@ func pbEntityTypeToString(t minderv1.Entity) (string, error) {
return VersionedArtifactEventEntityType, nil
case minderv1.Entity_ENTITY_PULL_REQUESTS:
return PullRequestEventEntityType, nil
case minderv1.Entity_ENTITY_RELEASE:
return "", fmt.Errorf("releases not yet supported")
case minderv1.Entity_ENTITY_PIPELINE_RUN:
return "", fmt.Errorf("pipeline runs not yet supported")
case minderv1.Entity_ENTITY_TASK_RUN:
return "", fmt.Errorf("task runs not yet supported")
case minderv1.Entity_ENTITY_BUILD:
return "", fmt.Errorf("builds not yet supported")
case minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS:
return "", fmt.Errorf("build environments not yet supported")
case minderv1.Entity_ENTITY_UNSPECIFIED:
Expand Down
5 changes: 3 additions & 2 deletions internal/engine/eval_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ func (e *executor) createEvalStatusParams(
entityID = params.RepoID
case db.EntitiesPullRequest:
entityID = params.PullRequestID
case db.EntitiesBuildEnvironment:
return nil, fmt.Errorf("build environment entity type not supported")
case db.EntitiesBuildEnvironment, db.EntitiesRelease, db.EntitiesPipelineRun,
db.EntitiesTaskRun, db.EntitiesBuild:
return nil, fmt.Errorf("entity type not yet supported")
}

ruleTypeName := sql.NullString{
Expand Down
4 changes: 4 additions & 0 deletions internal/engine/interfaces/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ type EvalStatusParams struct {
ArtifactID uuid.NullUUID
PullRequestID uuid.NullUUID
ProjectID uuid.UUID
ReleaseID uuid.UUID
PipelineRunID uuid.UUID
TaskRunID uuid.UUID
BuildID uuid.UUID
EntityType db.Entities
RuleTypeID uuid.UUID
EvalStatusFromDb *db.ListRuleEvaluationsByProfileIdRow
Expand Down
5 changes: 3 additions & 2 deletions internal/history/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ func paramsFromEntity(
params.PullRequestID = nullableEntityID
case db.EntitiesArtifact:
params.ArtifactID = nullableEntityID
case db.EntitiesBuildEnvironment:
case db.EntitiesBuildEnvironment, db.EntitiesRelease,
db.EntitiesPipelineRun, db.EntitiesTaskRun, db.EntitiesBuild:
default:
return nil, fmt.Errorf("unknown entity %s", entityType)
return nil, fmt.Errorf("unknown entity %q", entityType)
}
return &params, nil
}
Expand Down
8 changes: 7 additions & 1 deletion internal/logger/telemetry_store_watermill.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ func newTelemetryStoreFromEntity(inf *entities.EntityInfoWrapper) (*TelemetrySto
ts.Artifact = ent
case minderv1.Entity_ENTITY_PULL_REQUESTS:
ts.PullRequest = ent
case minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS:
case minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS,
minderv1.Entity_ENTITY_RELEASE, minderv1.Entity_ENTITY_PIPELINE_RUN,
minderv1.Entity_ENTITY_TASK_RUN, minderv1.Entity_ENTITY_BUILD:
// Noop, see https://github.com/stacklok/minder/issues/3838
case minderv1.Entity_ENTITY_UNSPECIFIED:
// Do nothing
}
Expand All @@ -121,6 +124,9 @@ func getEntityID(inf *entities.EntityInfoWrapper) (uuid.UUID, error) {
ent = artID.UUID
case minderv1.Entity_ENTITY_PULL_REQUESTS:
ent = prID.UUID
case minderv1.Entity_ENTITY_RELEASE, minderv1.Entity_ENTITY_PIPELINE_RUN,
minderv1.Entity_ENTITY_TASK_RUN, minderv1.Entity_ENTITY_BUILD:
// Noop, see https://github.com/stacklok/minder/issues/3838
}

return ent, nil
Expand Down
8 changes: 8 additions & 0 deletions internal/profiles/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ func (p *profileService) CreateProfile(
minderv1.Entity_ENTITY_ARTIFACTS: profile.GetArtifact(),
minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS: profile.GetBuildEnvironment(),
minderv1.Entity_ENTITY_PULL_REQUESTS: profile.GetPullRequest(),
minderv1.Entity_ENTITY_RELEASE: profile.GetRelease(),
minderv1.Entity_ENTITY_PIPELINE_RUN: profile.GetPipelineRun(),
minderv1.Entity_ENTITY_TASK_RUN: profile.GetTaskRun(),
minderv1.Entity_ENTITY_BUILD: profile.GetBuild(),
} {
if err := createProfileRulesForEntity(ctx, ent, &newProfile, qtx, entRules, rulesInProf); err != nil {
return nil, err
Expand Down Expand Up @@ -259,6 +263,10 @@ func (p *profileService) UpdateProfile(
minderv1.Entity_ENTITY_ARTIFACTS: profile.GetArtifact(),
minderv1.Entity_ENTITY_BUILD_ENVIRONMENTS: profile.GetBuildEnvironment(),
minderv1.Entity_ENTITY_PULL_REQUESTS: profile.GetPullRequest(),
minderv1.Entity_ENTITY_RELEASE: profile.GetRelease(),
minderv1.Entity_ENTITY_PIPELINE_RUN: profile.GetPipelineRun(),
minderv1.Entity_ENTITY_TASK_RUN: profile.GetTaskRun(),
minderv1.Entity_ENTITY_BUILD: profile.GetBuild(),
} {
if err = updateProfileRulesForEntity(ctx, ent, &updatedProfile, qtx, entRules, rules); err != nil {
return nil, err
Expand Down
Loading