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
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ sentry api organizations/ -f per_page=2 --cursor next --json
sentry api organizations/ -f per_page=2 --cursor prev --json

# Get a specific issue
sentry api issues/123456789/
sentry api organizations/my-org/issues/123456789/

# Create a release
sentry api organizations/my-org/releases/ -X POST -F version=1.0.0

# Update an issue status
sentry api issues/123456789/ -X PUT -F status=resolved
sentry api organizations/my-org/issues/123456789/ -X PUT -F status=resolved

# Send an inline JSON body
sentry api issues/123456789/ -X PUT -d '{"status":"resolved"}'
sentry api organizations/my-org/issues/123456789/ -X PUT -d '{"status":"resolved"}'

# Set a nested field
sentry api projects/my-org/my-project/ -X PUT -F options[sampleRate]=0.5

# Assign an issue
sentry api issues/123456789/ -X PUT --field assignedTo="user@example.com"
sentry api organizations/my-org/issues/123456789/ -X PUT --field assignedTo="user@example.com"

# Delete a project
sentry api projects/my-org/my-project/ -X DELETE
Expand Down
41 changes: 37 additions & 4 deletions packages/cli/src/commands/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,32 @@ export function formatEmptyErrorBody(
return `HTTP ${statusLabel}${request}`;
}

const LEGACY_ISSUE_PREFIX = /^(?:issues|groups)\/(?=[^/?]+\/)/;

/**
* Suggest the org-scoped form of a legacy unscoped `issues/<id>/` route.
* Sentry deprecated those routes and serves them from one region only, so
* they 404 for organizations in other regions and 410 during deprecation
* brownouts. The org-scoped form is routed to the organization's region.
* @internal Exported for testing
*/
export function formatLegacyIssueRouteHint(
status: number,
endpoint: string,
): string | undefined {
if (
(status !== 404 && status !== 410) ||
!LEGACY_ISSUE_PREFIX.test(endpoint)
) {
return;
}
const scoped = endpoint.replace(
LEGACY_ISSUE_PREFIX,
"organizations/<org>/issues/",
);
return `Unscoped issue routes are deprecated and reach only one region. Use ${scoped} instead.`;
}

type ApiResponseOutputOptions = {
silent: boolean;
isTTY: boolean | undefined;
Expand Down Expand Up @@ -1633,27 +1659,27 @@ export const apiCommand = buildCommand({
},
{
description: "Get a specific issue",
run: "api issues/123456789/",
run: "api organizations/my-org/issues/123456789/",
},
{
description: "Create a release",
run: "api organizations/my-org/releases/ -X POST -F version=1.0.0",
},
{
description: "Update an issue status",
run: "api issues/123456789/ -X PUT -F status=resolved",
run: "api organizations/my-org/issues/123456789/ -X PUT -F status=resolved",
},
{
description: "Send an inline JSON body",
run: 'api issues/123456789/ -X PUT -d \'{"status":"resolved"}\'',
run: 'api organizations/my-org/issues/123456789/ -X PUT -d \'{"status":"resolved"}\'',
},
{
description: "Set a nested field",
run: "api projects/my-org/my-project/ -X PUT -F options[sampleRate]=0.5",
},
{
description: "Assign an issue",
run: 'api issues/123456789/ -X PUT --field assignedTo="user@example.com"',
run: 'api organizations/my-org/issues/123456789/ -X PUT --field assignedTo="user@example.com"',
},
{
description: "Delete a project",
Expand Down Expand Up @@ -1842,6 +1868,13 @@ export const apiCommand = buildCommand({
normalizedEndpoint,
flags.method,
);
const hint = formatLegacyIssueRouteHint(
response.status,
normalizedEndpoint,
);
if (hint) {
log.warn(hint);
}
}

let pagination: ApiPaginationMetadata = parseLinkHeader(
Expand Down
25 changes: 25 additions & 0 deletions packages/cli/test/commands/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
extractJsonBody,
formatApiResponse,
formatBinaryErrorBody,
formatLegacyIssueRouteHint,
isApiErrorStatus,
normalizeEndpoint,
normalizeFields,
Expand Down Expand Up @@ -1080,6 +1081,30 @@ describe("formatBinaryErrorBody", () => {
});
});

describe("formatLegacyIssueRouteHint", () => {
test.each([
[404, "issues/123/", "organizations/<org>/issues/123/"],
[
410,
"groups/123/events/latest/",
"organizations/<org>/issues/123/events/latest/",
],
])("suggests the org-scoped route for %i %s", (status, endpoint, scoped) => {
expect(formatLegacyIssueRouteHint(status, endpoint)).toContain(
`Use ${scoped} instead.`,
);
});

test.each([
[500, "issues/123/"],
[404, "organizations/my-org/issues/123/"],
[404, "issues/"],
[404, "projects/my-org/my-project/issues/"],
])("returns undefined for %i %s", (status, endpoint) => {
expect(formatLegacyIssueRouteHint(status, endpoint)).toBeUndefined();
});
});

describe("resolveApiResponseOutput", () => {
const png = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);

Expand Down
Loading