Skip to content

Commit a4984de

Browse files
authored
Use workspace based queries/mutations (#664)
Team concept is being removed from the platform
1 parent 00f7ed2 commit a4984de

File tree

10 files changed

+161
-196
lines changed

10 files changed

+161
-196
lines changed

src/commands/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub async fn command(args: Args) -> Result<()> {
3535
Some(project_name)
3636
},
3737
description: None,
38-
team_id: workspace.team_id(),
38+
workspace_id: Some(workspace.id().to_owned()),
3939
};
4040
let project_create =
4141
post_graphql::<mutations::ProjectCreate, _>(&client, configs.get_backboard(), vars)

src/commands/link.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,36 @@ pub struct Args {
2626
#[clap(long, short)]
2727
service: Option<String>,
2828

29-
/// The team to link to.
29+
/// The team to link to (deprecated: use --workspace instead).
3030
#[clap(long, short)]
3131
team: Option<String>,
32+
33+
/// The workspace to link to.
34+
#[clap(long, short)]
35+
workspace: Option<String>,
3236
}
3337

3438
pub async fn command(args: Args) -> Result<()> {
3539
let mut configs = Configs::new()?;
3640

41+
// Support both team (deprecated) and workspace arguments
42+
let workspace_arg = match (args.team.as_ref(), args.workspace.as_ref()) {
43+
(Some(_), None) => {
44+
eprintln!(
45+
"{}",
46+
"Warning: The --team flag is deprecated. Please use --workspace instead.".yellow()
47+
);
48+
args.team
49+
}
50+
(None, workspace) => workspace.cloned(),
51+
(Some(_), Some(_)) => {
52+
eprintln!("{}", "Warning: Both --team and --workspace provided. Using --workspace. The --team flag is deprecated.".yellow());
53+
args.workspace
54+
}
55+
};
56+
3757
let workspaces = workspaces().await?;
38-
let workspace = select_workspace(args.project.clone(), args.team, workspaces)?;
58+
let workspace = select_workspace(args.project.clone(), workspace_arg, workspaces)?;
3959

4060
let project = select_project(workspace, args.project.clone())?;
4161

@@ -149,14 +169,14 @@ fn select_project(
149169
fake_select("Select a project", &project.to_string());
150170
project
151171
} else {
152-
return Err(RailwayError::ProjectNotFoundInTeam(
172+
return Err(RailwayError::ProjectNotFoundInWorkspace(
153173
project,
154174
workspace.name().to_owned(),
155175
)
156176
.into());
157177
}
158178
} else {
159-
prompt_team_projects(projects)?
179+
prompt_workspace_projects(projects)?
160180
}
161181
});
162182
Ok(project)
@@ -182,18 +202,18 @@ fn select_workspace(
182202
prompt_workspaces(workspaces)?
183203
}
184204
}
185-
(None, Some(team_arg)) | (Some(_), Some(team_arg)) => {
205+
(None, Some(workspace_arg)) | (Some(_), Some(workspace_arg)) => {
186206
if let Some(workspace) = workspaces.iter().find(|w| {
187-
w.team_id()
188-
.is_some_and(|id| id.to_lowercase() == team_arg.to_lowercase())
189-
|| w.name().to_lowercase() == team_arg.to_lowercase()
207+
w.id().to_lowercase() == workspace_arg.to_lowercase()
208+
|| w.team_id().map(str::to_lowercase) == Some(workspace_arg.to_lowercase())
209+
|| w.name().to_lowercase() == workspace_arg.to_lowercase()
190210
}) {
191211
fake_select("Select a workspace", workspace.name());
192212
workspace.clone()
193-
} else if team_arg.to_lowercase() == "personal" {
213+
} else if workspace_arg.to_lowercase() == "personal" {
194214
bail!(RailwayError::NoPersonalWorkspace);
195215
} else {
196-
return Err(RailwayError::TeamNotFound(team_arg.clone()).into());
216+
return Err(RailwayError::WorkspaceNotFound(workspace_arg.clone()).into());
197217
}
198218
}
199219
(None, None) => prompt_workspaces(workspaces)?,
@@ -212,7 +232,7 @@ fn prompt_workspaces(workspaces: Vec<Workspace>) -> Result<Workspace> {
212232
prompt_options("Select a workspace", workspaces)
213233
}
214234

215-
fn prompt_team_projects(projects: Vec<Project>) -> Result<Project, anyhow::Error> {
235+
fn prompt_workspace_projects(projects: Vec<Project>) -> Result<Project, anyhow::Error> {
216236
prompt_options("Select a project", projects)
217237
}
218238

@@ -277,7 +297,7 @@ impl From<Project> for NormalisedProject {
277297
})
278298
.collect(),
279299
),
280-
Project::Team(project) => NormalisedProject::new(
300+
Project::Workspace(project) => NormalisedProject::new(
281301
project.id,
282302
project.name,
283303
project

src/errors.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,15 @@ pub enum RailwayError {
4949
)]
5050
EnvironmentNotFound(String),
5151

52-
#[error("Project \"{0}\" was not found in the \"{1}\" team.")]
53-
ProjectNotFoundInTeam(String, String),
52+
#[error("Project \"{0}\" was not found in the \"{1}\" workspace.")]
53+
ProjectNotFoundInWorkspace(String, String),
5454

5555
#[error("Workspace \"{0}\" not found.")]
5656
WorkspaceNotFound(String),
5757

5858
#[error("Service \"{0}\" not found.")]
5959
ServiceNotFound(String),
6060

61-
#[error("Team \"{0}\" not found.")]
62-
TeamNotFound(String),
63-
6461
#[error("Project has no services.")]
6562
ProjectHasNoServices,
6663

src/gql/mutations/strings/ProjectCreate.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
mutation ProjectCreate($name: String, $description: String, $teamId: String) {
1+
mutation ProjectCreate($name: String, $description: String, $workspaceId: String) {
22
projectCreate(
3-
input: { name: $name, description: $description, teamId: $teamId }
3+
input: { name: $name, description: $description, workspaceId: $workspaceId }
44
) {
55
name
66
id

src/gql/queries/strings/Project.graphql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ query Project($id: String!) {
33
id
44
name
55
deletedAt
6-
team {
6+
workspace {
77
name
88
}
99
environments {
@@ -81,4 +81,4 @@ query Project($id: String!) {
8181
}
8282
}
8383
}
84-
}
84+
}

src/gql/queries/strings/Projects.graphql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
query Projects($teamId: String) {
2-
projects(teamId: $teamId) {
1+
query Projects($workspaceId: String) {
2+
projects(workspaceId: $workspaceId) {
33
edges {
44
node {
55
id
66
name
77
updatedAt
8-
team {
8+
workspace {
99
id
1010
name
1111
}

src/gql/queries/strings/UserProjects.graphql

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ query UserProjects {
99
createdAt
1010
updatedAt
1111
deletedAt
12-
team {
13-
id
14-
name
15-
}
1612
environments {
1713
edges {
1814
node {
@@ -44,36 +40,32 @@ query UserProjects {
4440
name
4541
team {
4642
id
47-
projects {
48-
edges {
49-
node {
50-
id
51-
name
52-
createdAt
53-
updatedAt
54-
deletedAt
55-
team {
56-
id
57-
name
58-
}
59-
environments {
60-
edges {
61-
node {
62-
id
63-
name
64-
}
43+
}
44+
projects {
45+
edges {
46+
node {
47+
id
48+
name
49+
createdAt
50+
updatedAt
51+
deletedAt
52+
environments {
53+
edges {
54+
node {
55+
id
56+
name
6557
}
6658
}
67-
services {
68-
edges {
69-
node {
70-
id
71-
name
72-
serviceInstances {
73-
edges {
74-
node {
75-
environmentId
76-
}
59+
}
60+
services {
61+
edges {
62+
node {
63+
id
64+
name
65+
serviceInstances {
66+
edges {
67+
node {
68+
environmentId
7769
}
7870
}
7971
}

0 commit comments

Comments
 (0)