Skip to content

Commit

Permalink
Merge pull request #2143 from keboola/ph-PSGO-902_push_ignore
Browse files Browse the repository at this point in the history
feat: Ignore configuration for push command
  • Loading branch information
hosekpeter authored Nov 19, 2024
2 parents 3823eed + c7c1fc8 commit 753e6ed
Show file tree
Hide file tree
Showing 34 changed files with 281 additions and 3 deletions.
5 changes: 5 additions & 0 deletions internal/pkg/fixtures/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type MockedObjectState struct {
*MockedManifest
Local *MockedObject
Remote *MockedObject
Ignore bool
}

type MockedManifestSideRelation struct {
Expand Down Expand Up @@ -196,6 +197,10 @@ func (o *MockedObjectState) HasManifest() bool {
return o.MockedManifest != nil
}

func (o *MockedObjectState) IsIgnored() bool {
return o.Ignore
}

func (o *MockedObjectState) SetManifest(manifest model.ObjectManifest) {
o.MockedManifest = manifest.(*MockedManifest)
}
Expand Down
14 changes: 14 additions & 0 deletions internal/pkg/model/objectstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ type ObjectState interface {
RemoteState() Object
LocalOrRemoteState() Object
RemoteOrLocalState() Object
IsIgnored() bool
}

type BranchState struct {
*BranchManifest
Remote *Branch
Local *Branch
Ignore bool
}

type ConfigState struct {
Expand Down Expand Up @@ -194,6 +196,18 @@ func (r *ConfigRowState) HasRemoteState() bool {
return r.Remote != nil
}

func (b *BranchState) IsIgnored() bool {
return b.Ignore
}

func (c *ConfigState) IsIgnored() bool {
return c.Ignore
}

func (r *ConfigRowState) IsIgnored() bool {
return r.Ignore
}

func (b *BranchState) SetRemoteState(object Object) {
if object == nil {
b.Remote = nil
Expand Down
11 changes: 8 additions & 3 deletions internal/pkg/plan/diffop/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ func (p *Plan) Log(w io.Writer) {
skippedDeleteCount := 0
for _, action := range actions {
msg := action.String()
if !p.allowedRemoteDelete &&
(action.action == ActionDeleteRemote) {
msg += " - SKIPPED"
if !p.allowedRemoteDelete && action.action == ActionDeleteRemote {
// determine if it is ignored or skipped
if action.IsIgnored() {
msg += " - IGNORED"
} else {
msg += " - SKIPPED"
}

skippedDeleteCount++
}
fmt.Fprintln(w, " "+msg)
Expand Down
13 changes: 13 additions & 0 deletions pkg/lib/operation/project/sync/push/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/keboola/keboola-as-code/internal/pkg/log"
"github.com/keboola/keboola-as-code/internal/pkg/plan/push"
"github.com/keboola/keboola-as-code/internal/pkg/project"
"github.com/keboola/keboola-as-code/internal/pkg/project/ignore"
"github.com/keboola/keboola-as-code/internal/pkg/telemetry"
"github.com/keboola/keboola-as-code/pkg/lib/operation/project/local/encrypt"
"github.com/keboola/keboola-as-code/pkg/lib/operation/project/local/validate"
Expand Down Expand Up @@ -65,6 +66,18 @@ func Run(ctx context.Context, projectState *project.State, o Options, d dependen
}
}

if projectState.Fs().Exists(ctx, ignore.KBCIgnoreFilePath) {
// Load ignore file
file, err := ignore.LoadFile(ctx, projectState.Fs(), projectState.Registry, ignore.KBCIgnoreFilePath)
if err != nil {
return err
}

if err = file.IgnoreConfigsOrRows(); err != nil {
return err
}
}

// Diff
results, err := createDiff.Run(ctx, createDiff.Options{Objects: projectState}, d, diff.WithIgnoreBranchName(projectState.ProjectManifest().AllowTargetENV()))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions test/cli/push/ignore-configurations/args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
push --storage-api-token %%TEST_KBC_STORAGE_API_TOKEN%%
1 change: 1 addition & 0 deletions test/cli/push/ignore-configurations/expected-code
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
58 changes: 58 additions & 0 deletions test/cli/push/ignore-configurations/expected-state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"branches": [
{
"branch": {
"name": "Main",
"description": "",
"isDefault": true
},
"configs": [
{
"componentId": "keboola.ex-db-mysql",
"name": "with-rows",
"description": "test fixture",
"configuration": {
"parameters": {
"db": {
"host": "mysql.example.com"
}
}
},
"rows": [
{
"name": "disabled",
"description": "test fixture",
"isDisabled": true,
"configuration": {
"parameters": {
"incremental": false
}
}
},
{
"name": "test_view",
"description": "test fixture",
"isDisabled": false,
"configuration": {
"parameters": {
"incremental": false
}
}
},
{
"name": "users",
"description": "test fixture",
"isDisabled": false,
"configuration": {
"parameters": {
"incremental": false
}
}
}
],
"isDisabled": false
}
]
}
]
}
Empty file.
5 changes: 5 additions & 0 deletions test/cli/push/ignore-configurations/expected-stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Plan for "push" operation:
× R main/extractor/keboola.ex-db-mysql/with-rows/rows/test-view - IGNORED
× R main/extractor/keboola.ex-db-mysql/with-rows/rows/users - SKIPPED
Skipped remote objects deletion, use "--force" to delete them.
Push done.
Empty file.
1 change: 1 addition & 0 deletions test/cli/push/ignore-configurations/in/.keboola/kbc_ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
keboola.ex-db-mysql/%%TEST_BRANCH_MAIN_CONFIG_WITH_ROWS_ID%%/%%TEST_BRANCH_MAIN_CONFIG_WITH_ROWS_ROW_TEST_VIEW_ID%%
54 changes: 54 additions & 0 deletions test/cli/push/ignore-configurations/in/.keboola/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"version": 2,
"project": {
"id": %%TEST_KBC_PROJECT_ID%%,
"apiHost": "%%TEST_KBC_STORAGE_API_HOST%%"
},
"allowTargetEnv": false,
"sortBy": "path",
"naming": {
"branch": "{branch_name}",
"config": "{component_type}/{component_id}/{config_name}",
"configRow": "rows/{config_row_name}",
"schedulerConfig": "schedules/{config_name}",
"sharedCodeConfig": "_shared/{target_component_id}",
"sharedCodeConfigRow": "codes/{config_row_name}",
"variablesConfig": "variables",
"variablesValuesRow": "values/{config_row_name}",
"dataAppConfig": "app/{component_id}/{config_name}"
},
"allowedBranches": [
"__all__"
],
"ignoredComponents": [],
"templates": {
"repositories": [
{
"type": "git",
"name": "keboola",
"url": "https://github.com/keboola/keboola-as-code-templates.git",
"ref": "main"
}
]
},
"branches": [
{
"id": %%TEST_BRANCH_MAIN_ID%%,
"path": "main"
}
],
"configurations": [
{
"branchId": %%TEST_BRANCH_MAIN_ID%%,
"componentId": "keboola.ex-db-mysql",
"id": "%%TEST_BRANCH_MAIN_CONFIG_WITH_ROWS_ID%%",
"path": "extractor/keboola.ex-db-mysql/with-rows",
"rows": [
{
"id": "%%TEST_BRANCH_MAIN_CONFIG_WITH_ROWS_ROW_DISABLED_ID%%",
"path": "rows/disabled"
}
]
}
]
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parameters": {
"db": {
"host": "mysql.example.com"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "with-rows",
"isDisabled": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"parameters": {
"incremental": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "disabled",
"isDisabled": true
}
4 changes: 4 additions & 0 deletions test/cli/push/ignore-configurations/in/main/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Main",
"isDefault": true
}
14 changes: 14 additions & 0 deletions test/cli/push/ignore-configurations/initial-state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"allBranchesConfigs": [],
"branches": [
{
"branch": {
"name": "Main",
"isDefault": true
},
"configs": [
"with-rows"
]
}
]
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
keboola.ex-db-mysql/%%TEST_BRANCH_MAIN_CONFIG_WITH_ROWS_ID%%/%%TEST_BRANCH_MAIN_CONFIG_WITH_ROWS_ROW_TEST_VIEW_ID%%
54 changes: 54 additions & 0 deletions test/cli/push/ignore-configurations/out/.keboola/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"version": 2,
"project": {
"id": %%TEST_KBC_PROJECT_ID%%,
"apiHost": "%%TEST_KBC_STORAGE_API_HOST%%"
},
"allowTargetEnv": false,
"sortBy": "path",
"naming": {
"branch": "{branch_name}",
"config": "{component_type}/{component_id}/{config_name}",
"configRow": "rows/{config_row_name}",
"schedulerConfig": "schedules/{config_name}",
"sharedCodeConfig": "_shared/{target_component_id}",
"sharedCodeConfigRow": "codes/{config_row_name}",
"variablesConfig": "variables",
"variablesValuesRow": "values/{config_row_name}",
"dataAppConfig": "app/{component_id}/{config_name}"
},
"allowedBranches": [
"__all__"
],
"ignoredComponents": [],
"templates": {
"repositories": [
{
"type": "git",
"name": "keboola",
"url": "https://github.com/keboola/keboola-as-code-templates.git",
"ref": "main"
}
]
},
"branches": [
{
"id": %%TEST_BRANCH_MAIN_ID%%,
"path": "main"
}
],
"configurations": [
{
"branchId": %%TEST_BRANCH_MAIN_ID%%,
"componentId": "keboola.ex-db-mysql",
"id": "%%TEST_BRANCH_MAIN_CONFIG_WITH_ROWS_ID%%",
"path": "extractor/keboola.ex-db-mysql/with-rows",
"rows": [
{
"id": "%%TEST_BRANCH_MAIN_CONFIG_WITH_ROWS_ROW_DISABLED_ID%%",
"path": "rows/disabled"
}
]
}
]
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parameters": {
"db": {
"host": "mysql.example.com"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "with-rows",
"isDisabled": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"parameters": {
"incremental": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "disabled",
"isDisabled": true
}
4 changes: 4 additions & 0 deletions test/cli/push/ignore-configurations/out/main/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Main",
"isDefault": true
}

0 comments on commit 753e6ed

Please sign in to comment.