{{ message }}
Repository navigation
feat: add plan metadata flags for title and description with validation #20705
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
Open
manhvu1997
wants to merge
2
commits into
bytebase:main
Choose a base branch
from
manhvu1997:feat/add-plan-metadata-flags
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package command | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/bytebase/bytebase/action/world" | ||
| ) | ||
|
|
||
| func TestNewRolloutCommandRegistersPlanCustomizationFlags(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| w := world.NewWorld() | ||
| cmd := NewRolloutCommand(w) | ||
|
|
||
| require.NotNil(t, cmd) | ||
| require.NotNil(t, cmd.Flags().Lookup("plan-title")) | ||
| require.NotNil(t, cmd.Flags().Lookup("plan-description")) | ||
| require.NotNil(t, cmd.Flags().Lookup("release-id-template")) | ||
| require.NotNil(t, cmd.Flags().Lookup("release-id-timezone")) | ||
| require.NotNil(t, cmd.Flags().Lookup("target-stage")) | ||
| } | ||
|
|
||
| func TestRolloutUsesConfiguredPlanMetadata(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| w := world.NewWorld() | ||
| w.PlanTitle = "custom title" | ||
| w.PlanDescription = "custom description" | ||
| w.ReleaseIDTemplate = "release_{date}" | ||
| w.ReleaseIDTimezone = "America/Los_Angeles" | ||
| w.TargetStage = "environments/prod" | ||
|
|
||
| require.Equal(t, "custom title", w.PlanTitle) | ||
| require.Equal(t, "custom description", w.PlanDescription) | ||
| require.Equal(t, "release_{date}", w.ReleaseIDTemplate) | ||
| require.Equal(t, "America/Los_Angeles", w.ReleaseIDTimezone) | ||
| require.Equal(t, "environments/prod", w.TargetStage) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,67 +1,84 @@ | ||
| package validation | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/bytebase/bytebase/action/world" | ||
| ) | ||
|
|
||
| func TestValidateTargets(t *testing.T) { | ||
| func TestValidateFlagsAcceptsValidPlanCustomizationAndTargets(t *testing.T) { | ||
| t.Setenv("BYTEBASE_ACCESS_TOKEN", "env-token") | ||
| w := &world.World{ | ||
| URL: "https://bytebase.example.com/", | ||
| Project: "projects/demo", | ||
| Targets: []string{"instances/instance-a/databases/db-a"}, | ||
| PlanTitle: "Release plan", | ||
| PlanDescription: "Describe the rollout", | ||
| } | ||
|
|
||
| err := ValidateFlags(w) | ||
| require.NoError(t, err) | ||
| require.Equal(t, "env-token", w.AccessToken) | ||
| require.Equal(t, "https://bytebase.example.com", w.URL) | ||
| } | ||
|
|
||
| func TestValidateFlagsRejectsPlanCustomizationLimits(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| targets []string | ||
| wantErr string | ||
| name string | ||
| mutate func(*world.World) | ||
| wantError string | ||
| }{ | ||
| { | ||
| name: "workspace database targets", | ||
| targets: []string{ | ||
| "instances/test/databases/hr_test", | ||
| "instances/prod/databases/hr_prod", | ||
| name: "plan title too long", | ||
| mutate: func(w *world.World) { | ||
| w.PlanTitle = strings.Repeat("a", 201) | ||
| }, | ||
| wantError: "--plan-title", | ||
| }, | ||
| { | ||
| name: "project instance database targets", | ||
| targets: []string{ | ||
| "projects/hr/instances/test/databases/hr_test", | ||
| "projects/hr/instances/prod/databases/hr_prod", | ||
| name: "plan description too long", | ||
| mutate: func(w *world.World) { | ||
| w.PlanDescription = strings.Repeat("b", 10001) | ||
| }, | ||
| }, | ||
| { | ||
| name: "mixed workspace and project instance database targets", | ||
| targets: []string{ | ||
| "instances/test/databases/hr_test", | ||
| "projects/hr/instances/prod/databases/hr_prod", | ||
| }, | ||
| }, | ||
| { | ||
| name: "database target and database group", | ||
| targets: []string{"projects/hr/instances/test/databases/hr_test", "projects/hr/databaseGroups/all"}, | ||
| wantErr: "either database targets or a database group target", | ||
| }, | ||
| { | ||
| name: "multiple database groups", | ||
| targets: []string{"projects/hr/databaseGroups/one", "projects/hr/databaseGroups/two"}, | ||
| wantErr: "single database group target", | ||
| }, | ||
| { | ||
| name: "malformed project instance target", | ||
| targets: []string{"projects/hr/instances//databases/hr_test"}, | ||
| wantErr: "invalid target format", | ||
| wantError: "--plan-description", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| err := validateTargets(tt.targets) | ||
| if tt.wantErr == "" { | ||
| require.NoError(t, err) | ||
| return | ||
| w := &world.World{ | ||
| URL: "https://bytebase.example.com", | ||
| Project: "projects/demo", | ||
| Targets: []string{"instances/instance-a/databases/db-a"}, | ||
| AccessToken: "token", | ||
| } | ||
| require.ErrorContains(t, err, tt.wantErr) | ||
| tt.mutate(w) | ||
|
|
||
| err := ValidateFlags(w) | ||
| require.Error(t, err) | ||
| require.ErrorContains(t, err, tt.wantError) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestValidateFlagsRejectsInvalidTargets(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| w := &world.World{ | ||
| URL: "https://bytebase.example.com", | ||
| Project: "projects/demo", | ||
| Targets: []string{"not-a-target"}, | ||
| AccessToken: "token", | ||
| } | ||
|
|
||
| err := ValidateFlags(w) | ||
| require.Error(t, err) | ||
| require.ErrorContains(t, err, "invalid target format") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You can’t perform that action at this time.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When users pass non-ASCII plan titles or descriptions,
lencounts UTF-8 bytes rather than characters, so the CLI rejects values that fit the documented/proto character limits. The repo's validation standard calls these tiers chars (proto/v1/v1/VALIDATION_STANDARDS.md:43 and :68), andPlan.title/Plan.descriptionusemax_len200/10000 (proto/v1/v1/plan_service.proto:208-211); for example, a 100-character CJK title is rejected here before it can create a plan. Use a rune count for these CLI checks.Useful? React with 👍 / 👎.