-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(cube-cli): add data-model enable-branch / disable-branch commands #11433
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ use anyhow::{Context as _, Result}; | |||||||||||
| use clap::Subcommand; | ||||||||||||
| use serde_json::json; | ||||||||||||
|
|
||||||||||||
| use crate::client::Query; | ||||||||||||
| use crate::client::{Client, Query}; | ||||||||||||
| use crate::{output, util, Ctx}; | ||||||||||||
|
|
||||||||||||
| /// Manage a deployment's data model files (schema). | ||||||||||||
|
|
@@ -96,6 +96,21 @@ enum Cmd { | |||||||||||
| #[arg(long)] | ||||||||||||
| dev_mode: bool, | ||||||||||||
| }, | ||||||||||||
| /// Enable a branch: keep its staging environment always active | ||||||||||||
| EnableBranch { | ||||||||||||
| /// Deployment id | ||||||||||||
| deployment: i64, | ||||||||||||
| /// Branch to enable (a shared branch — not a personal dev branch) | ||||||||||||
| branch: String, | ||||||||||||
| }, | ||||||||||||
| /// Disable a branch: its staging environment is active only while the | ||||||||||||
| /// branch is viewed in Cube Cloud | ||||||||||||
| DisableBranch { | ||||||||||||
| /// Deployment id | ||||||||||||
| deployment: i64, | ||||||||||||
| /// Branch to disable | ||||||||||||
| branch: String, | ||||||||||||
| }, | ||||||||||||
| /// Enter dev mode on a branch (prints the personal dev-mode branch that | ||||||||||||
| /// file writes must target) | ||||||||||||
| DevMode { | ||||||||||||
|
|
@@ -221,6 +236,41 @@ fn write_body( | |||||||||||
| util::body(body) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /// Enabling a branch keeps its staging environment always active and accessible | ||||||||||||
| /// at `<deploymentUrl>/dev-mode/<branch>/cubejs-api/v1`; disabled (the default) | ||||||||||||
| /// it is only active while someone views the branch in Cube Cloud. Enabled | ||||||||||||
| /// branches are the ones `cube environments list --type staging` reports. Only | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correcting the suggestion above — it dropped the trailing
Suggested change
|
||||||||||||
| /// shared branches qualify — personal dev branches are served as your own | ||||||||||||
| /// development environment, and the deploy branch is production. | ||||||||||||
| async fn set_branch_enabled( | ||||||||||||
| api: &Client, | ||||||||||||
| ctx: &Ctx, | ||||||||||||
| deployment: i64, | ||||||||||||
| branch: &str, | ||||||||||||
| enabled: bool, | ||||||||||||
| ) -> Result<()> { | ||||||||||||
| let body = json!({ "branchName": branch, "enabled": enabled }); | ||||||||||||
| let res = api | ||||||||||||
| .put( | ||||||||||||
| &format!("/build/api/v1/deployments/{deployment}/branches/staging-environment"), | ||||||||||||
| Some(&body), | ||||||||||||
| ) | ||||||||||||
| .await?; | ||||||||||||
| if ctx.json { | ||||||||||||
| output::print_json(&res); | ||||||||||||
| } else if enabled { | ||||||||||||
| output::success(&format!( | ||||||||||||
| "Enabled branch {branch}; its staging environment stays active \ | ||||||||||||
| (see `cube environments list {deployment} --type staging`)" | ||||||||||||
| )); | ||||||||||||
| } else { | ||||||||||||
| output::success(&format!( | ||||||||||||
| "Disabled branch {branch}; its staging environment is active only while viewed" | ||||||||||||
| )); | ||||||||||||
| } | ||||||||||||
| Ok(()) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| fn read_content(file: Option<String>, content: Option<String>) -> Result<String> { | ||||||||||||
| if let Some(path) = file { | ||||||||||||
| return std::fs::read_to_string(&path).with_context(|| format!("failed to read {path}")); | ||||||||||||
|
|
@@ -351,8 +401,8 @@ pub async fn command(args: Args, ctx: &Ctx) -> Result<()> { | |||||||||||
| &res, | ||||||||||||
| &[ | ||||||||||||
| ("NAME", "name"), | ||||||||||||
| ("DEFAULT", "isDefault"), | ||||||||||||
| ("CURRENT", "isCurrent"), | ||||||||||||
| ("PARENT", "parentBranch"), | ||||||||||||
| ("ENABLED", "isStagingEnvironmentEnabled"), | ||||||||||||
| ], | ||||||||||||
|
Comment on lines
403
to
406
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Since the endpoint lives in the enterprise repo, could you confirm against a real (non-stub) response that both keys are always present on every branch object, including branches never toggled? If Separately: dropping |
||||||||||||
| ); | ||||||||||||
| } | ||||||||||||
|
|
@@ -384,6 +434,12 @@ pub async fn command(args: Args, ctx: &Ctx) -> Result<()> { | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| Cmd::EnableBranch { deployment, branch } => { | ||||||||||||
| set_branch_enabled(&api, ctx, deployment, &branch, true).await?; | ||||||||||||
| } | ||||||||||||
| Cmd::DisableBranch { deployment, branch } => { | ||||||||||||
| set_branch_enabled(&api, ctx, deployment, &branch, false).await?; | ||||||||||||
| } | ||||||||||||
| Cmd::DevMode { deployment, branch } => { | ||||||||||||
| let body = json!({ "branchName": branch }); | ||||||||||||
| let res = api | ||||||||||||
|
|
||||||||||||
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.
docs-mintlify/CLAUDE.mdlists "Cube Cloud" as legacy naming that shouldn't be used in new content. The new docs text correctly says "the Cube UI"; this help string (and the module doc at line 241) still says "Cube Cloud", and--helpoutput is user-facing too. Worth aligning both to "the Cube UI".