-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from aarondill/dev
feat: add vercel.DashboardURL for use with teams
- Loading branch information
Showing
6 changed files
with
53 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |