Skip to content

Commit

Permalink
feat: env0 deployment logs (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
meniRoy authored Aug 15, 2023
1 parent 28227ba commit c799eed
Show file tree
Hide file tree
Showing 6 changed files with 342 additions and 86 deletions.
25 changes: 17 additions & 8 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const cancelDeployment = async (env: Environment) => {
return;
}

await apiClient.cancelDeployment(id);
return await apiClient.cancelDeployment(id);
};

const resumeDeployment = async (env: Environment) => {
Expand All @@ -43,24 +43,27 @@ const resumeDeployment = async (env: Environment) => {
if (!id) {
return;
}
await apiClient.resumeDeployment(id);
return await apiClient.resumeDeployment(id);
};

const redeployEnvironment = async (env: Environment) => {
if (!env.id) {
return;
}
await apiClient.redeployEnvironment(env.id);
return await apiClient.redeployEnvironment(env.id);
};

const destroyEnvironment = async (env: Environment) => {
if (!env.id) {
return;
}
await apiClient.destroyEnvironment(env.id);
return await apiClient.destroyEnvironment(env.id);
};

const actions: Record<string, (env: Environment) => Promise<void>> = {
const actions: Record<
string,
(env: Environment) => Promise<{ id: string } | void>
> = {
"env0.redeploy": redeployEnvironment,
"env0.abort": abortEnvironmentDeploy,
"env0.destroy": destroyEnvironment,
Expand All @@ -70,8 +73,9 @@ const actions: Record<string, (env: Environment) => Promise<void>> = {

export const registerEnvironmentActions = (
context: vscode.ExtensionContext,
environmentsTree: vscode.TreeView<Environment>,
environmentsDataProvider: Env0EnvironmentsProvider,
restartLogs: (env: Environment) => any
restartLogs: (env: Environment, deploymentId?: string) => any
) => {
context.subscriptions.push(
vscode.commands.registerCommand("env0.openInEnv0", (env) => {
Expand All @@ -89,11 +93,16 @@ export const registerEnvironmentActions = (
location: { viewId: ENV0_ENVIRONMENTS_VIEW_ID },
},
async () => {
let actionResponse;
try {
await actions[actionCommand](env);
await environmentsTree.reveal(env, {
select: true,
focus: true,
});
actionResponse = await actions[actionCommand](env);
} finally {
environmentsDataProvider.refresh();
restartLogs(env);
restartLogs(env, actionResponse?.id);
}
}
);
Expand Down
66 changes: 49 additions & 17 deletions src/api-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AuthService } from "./auth";
import axios, { AxiosInstance } from "axios";
import { ENV0_API_URL, ENV0_WEB_URL } from "./common";
import { ENV0_API_URL } from "./common";
import { EnvironmentModel } from "./get-environments";
import { DeploymentStepLogsResponse, DeploymentStepResponse } from "./types";

Expand All @@ -22,59 +21,92 @@ class ApiClient {
}

public async abortDeployment(deploymentId: string) {
return this.instance.post(
const response = await this.instance.post<null>(
`/environments/deployments/${deploymentId}/abort`,
{}
);
return response.data;
}

public async redeployEnvironment(envId: string) {
return this.instance.post(`/environments/${envId}/deployments`, {});
const response = await this.instance.post<{ id: string }>(
`/environments/${envId}/deployments`,
{}
);
return response.data;
}

public async cancelDeployment(deploymentId: string) {
return this.instance.put(
const response = await this.instance.put<{ id: string }>(
`/environments/deployments/${deploymentId}/cancel`
);
return response.data;
}

public async resumeDeployment(deploymentId: string) {
return this.instance.put(`/environments/deployments/${deploymentId}`);
const response = await this.instance.put<{ id: string }>(
`/environments/deployments/${deploymentId}`
);
return response.data;
}

public async destroyEnvironment(deploymentId: string) {
this.instance.post(`/environments/${deploymentId}/destroy`, {});
const response = await this.instance.post<{ id: string }>(
`/environments/${deploymentId}/destroy`,
{}
);
return response.data;
}

public async getEnvironments(organizationId: string) {
const res = await this.instance.get<EnvironmentModel[]>(`/environments`, {
params: { organizationId },
});
const response = await this.instance.get<EnvironmentModel[]>(
`/environments`,
{
params: { organizationId },
}
);

return res.data;
return response.data;
}

public async getOrganizations() {
const res = await this.instance.get(`/organizations`);
return res.data;
const response = await this.instance.get(`/organizations`);
return response.data;
}

public async getDeploymentSteps(deploymentLogId: string) {
public async getDeployment(
deploymentLogId: string,
abortController?: AbortController
) {
const response = await this.instance.get(
`environments/deployments/${deploymentLogId}`,
{ signal: abortController?.signal }
);
return response.data;
}

public async getDeploymentSteps(
deploymentLogId: string,
abortController?: AbortController
) {
const response = await this.instance.get<DeploymentStepResponse>(
`/deployments/${deploymentLogId}/steps`
`/deployments/${deploymentLogId}/steps`,
{ signal: abortController?.signal }
);
return response.data;
}

public async getDeploymentStepLogs(
deploymentLogId: string,
stepName: string,
stepStartTime?: string | number
stepStartTime?: string | number,
abortController?: AbortController
) {
const response = await this.instance.get<DeploymentStepLogsResponse>(
`/deployments/${deploymentLogId}/steps/${stepName}/log?startTime=${
stepStartTime ?? ""
}`
}`,
{ signal: abortController?.signal }
);
return response.data;
}
Expand Down
4 changes: 4 additions & 0 deletions src/env0-environments-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export class Env0EnvironmentsProvider
);
}

getParent(element: Environment): vscode.ProviderResult<Environment> {
return null;
}

private shouldUpdate(environmentsToCompareTo: EnvironmentModel[]): boolean {
if (environmentsToCompareTo.length !== this.environments.length) {
return true;
Expand Down
Loading

0 comments on commit c799eed

Please sign in to comment.