@crazyrabbitltc/railway-mcp
Version:
Railway MCP Server - 146+ tools with 100% Railway API coverage, comprehensive MCP testing framework, and real infrastructure management through AI assistants. Enhanced version with enterprise features, based on original work by Jason Tan.
138 lines (137 loc) • 3.94 kB
JavaScript
export class EnvironmentRepository {
client;
constructor(client) {
this.client = client;
}
async create(projectId, name, isEphemeral = false) {
const query = `
mutation environmentCreate($input: EnvironmentCreateInput!) {
environmentCreate(input: $input) {
id
name
projectId
createdAt
updatedAt
isEphemeral
unmergedChangesCount
}
}
`;
const variables = {
input: {
projectId,
name,
isEphemeral
}
};
const data = await this.client.request(query, variables);
return data.environmentCreate;
}
async delete(environmentId) {
const query = `
mutation environmentDelete($id: String!) {
environmentDelete(id: $id)
}
`;
const variables = {
id: environmentId
};
const data = await this.client.request(query, variables);
return data.environmentDelete;
}
async rename(environmentId, name) {
const query = `
mutation environmentRename($id: String!, $input: EnvironmentRenameInput!) {
environmentRename(id: $id, input: $input) {
id
name
projectId
createdAt
updatedAt
isEphemeral
unmergedChangesCount
}
}
`;
const variables = {
id: environmentId,
input: {
name
}
};
const data = await this.client.request(query, variables);
return data.environmentRename;
}
async get(environmentId) {
const query = `
query environment($id: String!) {
environment(id: $id) {
id
name
projectId
createdAt
updatedAt
isEphemeral
unmergedChangesCount
}
}
`;
const variables = {
id: environmentId
};
const data = await this.client.request(query, variables);
return data.environment;
}
async list(projectId, isEphemeral) {
const query = `
query environments($projectId: String!, $isEphemeral: Boolean) {
environments(projectId: $projectId, isEphemeral: $isEphemeral) {
edges {
node {
id
name
projectId
createdAt
updatedAt
isEphemeral
unmergedChangesCount
}
}
}
}
`;
const variables = {
projectId
};
if (isEphemeral !== undefined) {
variables.isEphemeral = isEphemeral;
}
const data = await this.client.request(query, variables);
return data.environments.edges.map(edge => edge.node);
}
async cloneWithVariables(sourceEnvironmentId, targetEnvironmentId) {
// This is a utility method that copies variables from one environment to another
// It requires fetching variables from source and creating them in target
// This will be implemented using the variable repository
// For now, return a placeholder indicating this needs variable repository integration
return {
success: true,
message: "Environment clone with variables requires variable repository integration"
};
}
async triggerDeploy(environmentId, serviceId) {
const query = `
mutation environmentTriggersDeploy($input: EnvironmentTriggersDeployInput!) {
environmentTriggersDeploy(input: $input)
}
`;
const variables = {
input: {
environmentId,
serviceId
}
};
const data = await this.client.request(query, variables);
return data.environmentTriggersDeploy;
}
}