Skip to content

Commit

Permalink
Merge pull request #15 from aarondill/dev
Browse files Browse the repository at this point in the history
feat: add vercel.DashboardURL for use with teams
  • Loading branch information
aarondill authored Jul 3, 2024
2 parents 649d804 + 4736386 commit d4458fa
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 24 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This extension contributes the following settings:

- `vercel.RefreshRate`: Number of minutes to wait between refreshes of Deployments and Environment. (Default 5 minutes)
- `vercel.DeploymentCount`: Number of deployments to display from Vercel. (Default 20)
- `vercel.TeamDashboardURL`: (For use with teams) The URL to append the project name to.

## Contributing

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@
"minimum": 1,
"maximum": 100,
"description": "Number of deployments to fetch from Vercel."
},
"vercel.TeamDashboardURL": {
"type": "string",
"default": "",
"description": "(For use with teams) The URL to append the project name to. If not set, it will default to https://vercel.com/{user}/{project}"
}
}
},
Expand Down
16 changes: 3 additions & 13 deletions src/commands/Deployments/openDeploymentsLink.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import * as vscode from "vscode";
import type { Command } from "../../CommandManager";
import type { VercelManager } from "../../features/VercelManager";
import getProjectDashboard from "../../utils/dashboard";

export class OpenDeploymentsLink implements Command {
public readonly id = "vercel.openDeploymentsLink";
constructor(private readonly vercel: VercelManager) {}
dispose() {}
async execute() {
const projectInfo = await this.vercel.project.getInfo();
if (!projectInfo) return;
const user = await this.vercel.user.getInfo();
if (!user)
return void vscode.window.showErrorMessage("Could not get user info!");
const base = vscode.Uri.parse("https://vercel.com");
const url = vscode.Uri.joinPath(
base,
user.username,
projectInfo.name,
"/deployments"
);
await vscode.env.openExternal(url);
const url = await getProjectDashboard(this.vercel, "/deployments");
if (url) await vscode.env.openExternal(url);
}
}
15 changes: 4 additions & 11 deletions src/commands/Environment/openEnvironmentLink.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import * as vscode from "vscode";
import type { Command } from "../../CommandManager";
import type { VercelManager } from "../../features/VercelManager";
import getProjectDashboard from "../../utils/dashboard";

export class OpenEnvironmentLink implements Command {
public readonly id = "vercel.openEnvironmentLink";
constructor(private readonly vercel: VercelManager) {}
dispose() {}
async execute() {
const projectInfo = await this.vercel.project.getInfo();
if (!projectInfo) return;
const user = await this.vercel.user.getInfo();
if (!user)
return void vscode.window.showErrorMessage("Could not get user info!");
const base = vscode.Uri.parse("https://vercel.com");
const url = vscode.Uri.joinPath(
base,
user.username,
projectInfo.name,
const url = await getProjectDashboard(
this.vercel,
"/settings/environment-variables"
);
await vscode.commands.executeCommand("vscode.open", url);
if (url) await vscode.env.openExternal(url);
}
}
1 change: 1 addition & 0 deletions src/features/VercelManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class VercelManager {
};
}
loggedIn = async () => !!(await this.token.getAuth())?.accessToken;
teamId = async () => (await this.token.getAuth())?.teamId;
async debug(): Promise<Record<string, unknown>> {
const ident = (x: unknown) => x;
const orErr = <T>(p: Thenable<T>) => p.then(ident, ident);
Expand Down
39 changes: 39 additions & 0 deletions src/utils/dashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { VercelManager } from "../features/VercelManager";
import * as vscode from "vscode";

async function getBaseURL(
vercel: VercelManager
): Promise<vscode.Uri | undefined> {
const teamId = await vercel.teamId();
const projectAccountId = (await vercel.project.getInfo())?.accountId;
// If the current progect is a team project, use the team dashboard URL
if (teamId && projectAccountId === teamId) {
const userURL = vscode.workspace
.getConfiguration("vercel")
.get("TeamDashboardURL");
if (typeof userURL !== "string" || userURL.length === 0) {
return void vscode.window.showErrorMessage(
"To open the team dashboard, please set the TeamDashboardURL setting."
);
}
return vscode.Uri.parse(userURL);
}

// Else, use the default URL and append the username
const base = vscode.Uri.parse("https://vercel.com");
const user = await vercel.user.getInfo();
if (!user)
return void vscode.window.showErrorMessage("Could not get user info!");
return vscode.Uri.joinPath(base, user.username);
}
export async function getProjectDashboard(
vercel: VercelManager,
path: string
): Promise<vscode.Uri | undefined> {
const projectInfo = await vercel.project.getInfo();
if (!projectInfo) return;
const base = await getBaseURL(vercel);
if (!base) return;
return vscode.Uri.joinPath(base, projectInfo.name, path);
}
export default getProjectDashboard;

0 comments on commit d4458fa

Please sign in to comment.