Skip to content

Commit

Permalink
port Source display logic from legacy deployments command
Browse files Browse the repository at this point in the history
for versions view/list
  • Loading branch information
RamIdeas committed Mar 12, 2024
1 parent 38fb9dc commit a608e35
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 26 deletions.
16 changes: 8 additions & 8 deletions packages/wrangler/src/__tests__/versions/versions.list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,28 @@ describe("versions list", () => {
"Version ID: 40000000-0000-0000-0000-000000000000
Created: 1/1/2021, 12:00:00 AM
Author: Jean-Luc-Picard@federation.org
Source: wrangler
Source: Upload
Tag: -
Message: -
Version ID: 30000000-0000-0000-0000-000000000000
Created: 2/2/2021, 12:00:00 AM
Author: Kathryn-Janeway@federation.org
Source: wrangler
Source: Rollback
Tag: -
Message: Rolled back for this version
Version ID: 20000000-0000-0000-0000-000000000000
Created: 2/3/2021, 12:00:00 AM
Author: Kathryn-Janeway@federation.org
Source: wrangler
Source: Wrangler 🤠
Tag: -
Message: -
Version ID: 10000000-0000-0000-0000-000000000000
Created: 1/4/2021, 12:00:00 AM
Author: Jean-Luc-Picard@federation.org
Source: wrangler
Source: Rollback
Tag: -
Message: -
"
Expand All @@ -89,28 +89,28 @@ describe("versions list", () => {
"Version ID: 40000000-0000-0000-0000-000000000000
Created: 1/1/2021, 12:00:00 AM
Author: Jean-Luc-Picard@federation.org
Source: wrangler
Source: Upload
Tag: -
Message: -
Version ID: 30000000-0000-0000-0000-000000000000
Created: 2/2/2021, 12:00:00 AM
Author: Kathryn-Janeway@federation.org
Source: wrangler
Source: Rollback
Tag: -
Message: Rolled back for this version
Version ID: 20000000-0000-0000-0000-000000000000
Created: 2/3/2021, 12:00:00 AM
Author: Kathryn-Janeway@federation.org
Source: wrangler
Source: Wrangler 🤠
Tag: -
Message: -
Version ID: 10000000-0000-0000-0000-000000000000
Created: 1/4/2021, 12:00:00 AM
Author: Jean-Luc-Picard@federation.org
Source: wrangler
Source: Rollback
Tag: -
Message: -
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe("versions view", () => {
"Version ID: 10000000-0000-0000-0000-000000000000
Created: 1/1/2021, 12:00:00 AM
Author: Jean-Luc-Picard@federation.org
Source: wrangler
Source: Upload
Tag: -
Message: -
"
Expand Down Expand Up @@ -170,7 +170,7 @@ describe("versions view", () => {
"Version ID: 10000000-0000-0000-0000-000000000000
Created: 1/1/2021, 12:00:00 AM
Author: Jean-Luc-Picard@federation.org
Source: wrangler
Source: Upload
Tag: -
Message: -
"
Expand Down
47 changes: 44 additions & 3 deletions packages/wrangler/src/versions/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type ApiVersion = {
author_id: string;
author_email: string;
};
annotations?: Record<string, string> & {
annotations?: {
"workers/triggered_by"?: "upload" | string;
"workers/message"?: string;
"workers/tag"?: string;
Expand Down Expand Up @@ -75,14 +75,14 @@ export async function versionsListHandler(args: VersionsListArgs) {
"Version ID:": version.id,
"Created:": new Date(version.metadata["created_on"]).toLocaleString(),
"Author:": version.metadata.author_email,
"Source:": version.metadata.source,
"Source:": getSource(version),
"Tag:": version.annotations?.["workers/tag"] ?? BLANK_INPUT,
"Message:": version.annotations?.["workers/message"] ?? BLANK_INPUT,
});
}
}

function getConfig(
export function getConfig(
args: Pick<VersionsListArgs, "config" | "name" | "experimentalJsonConfig">
) {
const configPath =
Expand All @@ -91,3 +91,44 @@ function getConfig(

return config;
}

export function getSource(version: {
metadata: Pick<ApiVersion["metadata"], "source">;
annotations?: Pick<
NonNullable<ApiVersion["annotations"]>,
"workers/triggered_by"
>;
}) {
return version.annotations?.["workers/triggered_by"] === undefined
? formatSource(version.metadata.source)
: formatTrigger(version.annotations["workers/triggered_by"]);
}

export function formatSource(source: string): string {
switch (source) {
case "api":
return "API 📡";
case "dash":
return "Dashboard 🖥️";
case "wrangler":
return "Wrangler 🤠";
case "terraform":
return "Terraform 🏗️";
default:
return "Other";
}
}
export function formatTrigger(trigger: string): string {
switch (trigger) {
case "upload":
return "Upload";
case "secret":
return "Secret Change";
case "rollback":
return "Rollback";
case "promotion":
return "Promotion";
default:
return "Unknown";
}
}
15 changes: 2 additions & 13 deletions packages/wrangler/src/versions/view.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import path from "path";
import { fetchResult } from "../cfetch";
import { findWranglerToml, readConfig } from "../config";
import { UserError } from "../errors";
import * as metrics from "../metrics";
import { printWranglerBanner } from "../update-check";
import { requireAuth } from "../user";
import renderLabelledValues from "../utils/render-labelled-values";
import { getConfig, getSource } from "./list";
import type {
CommonYargsArgv,
StrictYargsOptionsToInterface,
Expand Down Expand Up @@ -81,18 +80,8 @@ export async function versionsViewHandler(args: VersionsViewArgs) {
"Version ID:": version.id,
"Created:": new Date(version.metadata["created_on"]).toLocaleString(),
"Author:": version.metadata.author_email,
"Source:": version.metadata.source,
"Source:": getSource(version),
"Tag:": version.annotations?.["workers/tag"] ?? BLANK_INPUT,
"Message:": version.annotations?.["workers/message"] ?? BLANK_INPUT,
});
}

function getConfig(
args: Pick<VersionsViewArgs, "config" | "name" | "experimentalJsonConfig">
) {
const configPath =
args.config || (args.name && findWranglerToml(path.dirname(args.name)));
const config = readConfig(configPath, args);

return config;
}

0 comments on commit a608e35

Please sign in to comment.