Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/young-mammals-spend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

Introduce json output flag for wrangler pages deployment list
45 changes: 45 additions & 0 deletions packages/wrangler/src/__tests__/pages/deployment-list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,51 @@ describe("pages deployment list", () => {
`);
});

it("should make request to list deployments and return result as json", async () => {
const deployments: Deployment[] = [
{
id: "87bbc8fe-16be-45cd-81e0-63d722e82cdf",
url: "https://87bbc8fe.images.pages.dev",
environment: "preview",
created_on: "2021-11-17T14:52:26.133835Z",
latest_stage: {
ended_on: "2021-11-17T14:52:26.133835Z",
status: "success",
},
deployment_trigger: {
metadata: {
branch: "main",
commit_hash: "c7649364c4cb32ad4f65b530b9424e8be5bec9d6",
},
},
project_name: "images",
},
];

const requests = mockDeploymentListRequest(deployments);
await runWrangler("pages deployment list --project-name=images --json");

expect(requests.count).toBe(1);
const output = JSON.parse(std.out);

expect(output[0].Status).toBeTypeOf("string");
output[0].Status = "SNAPSHOT_VALUE"; // This value would drift from snapshot if not hardcoded as is

expect(JSON.stringify(output, null, 2)).toMatchInlineSnapshot(`
"[
{
\\"Id\\": \\"87bbc8fe-16be-45cd-81e0-63d722e82cdf\\",
\\"Environment\\": \\"Preview\\",
\\"Branch\\": \\"main\\",
\\"Source\\": \\"c764936\\",
\\"Deployment\\": \\"https://87bbc8fe.images.pages.dev\\",
\\"Status\\": \\"SNAPSHOT_VALUE\\",
\\"Build\\": \\"https://dash.cloudflare.com/some-account-id/pages/view/images/87bbc8fe-16be-45cd-81e0-63d722e82cdf\\"
}
]"
`);
});

it("should pass no environment", async () => {
const deployments: Deployment[] = [
{
Expand Down
13 changes: 11 additions & 2 deletions packages/wrangler/src/pages/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ export const pagesDeploymentListCommand = createCommand({
choices: ["production", "preview"],
description: "Environment type to list deployments for",
},
json: {
type: "boolean",
description: "Return output as clean JSON",
default: false,
},
},
async handler({ projectName, environment }) {
async handler({ projectName, environment, json }) {
const config = getConfigCache<PagesConfigCache>(
PAGES_CONFIG_CACHE_FILENAME
);
Expand Down Expand Up @@ -93,7 +98,11 @@ export const pagesDeploymentListCommand = createCommand({
account_id: accountId,
});

logger.table(data);
if (json) {
logger.log(JSON.stringify(data, null, 2));
} else {
logger.table(data);
}
metrics.sendMetricsEvent("list pages deployments");
},
});
Loading