Skip to content

docs(id-support): Document that -p and -o arguments accept slugs and IDs #2098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions src/commands/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub fn make_command(mut command: Command) -> Command {
.about("Manage events on Sentry.")
.subcommand_required(true)
.arg_required_else_help(true)
.org_arg()
.project_arg(true);
.org_arg_with_id()
.project_arg_with_id(true);
each_subcommand!(add_subcommand);
command
}
Expand Down
31 changes: 31 additions & 0 deletions src/utils/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ pub fn get_timestamp(value: &str) -> Result<DateTime<Utc>> {

pub trait ArgExt: Sized {
fn org_arg(self) -> Self;
fn org_arg_with_id(self) -> Self;
fn project_arg(self, multiple: bool) -> Self;
fn project_arg_with_id(self, multiple: bool) -> Self;
fn release_arg(self) -> Self;
fn version_arg(self, global: bool) -> Self;
}
Expand All @@ -94,6 +96,18 @@ impl<'a: 'b, 'b> ArgExt for Command {
)
}

fn org_arg_with_id(self) -> Command {
self.arg(
Arg::new("org")
.value_name("ORG")
.long("org")
.short('o')
.value_parser(validate_org)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are still using the same value parser as the org argument here. I think the validation itself should be correct, but if you pass an invalid value, it prints "Invalid value for organization. Use the URL slug and not the name!", which is misleading.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the changes I requested, we would no longer have a separate org_arg_with_id function.

Instead, we would need to update the existing validate_org value parser to state that an organization slug or ID needs to be provided.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, that also (like the rest of the changes) can only be done once all Sentry APIs support org or project IDs

.global(true)
.help("The organization id or slug."),
)
}

fn project_arg(self, multiple: bool) -> Command {
self.arg(
Arg::new("project")
Expand All @@ -111,6 +125,23 @@ impl<'a: 'b, 'b> ArgExt for Command {
)
}

fn project_arg_with_id(self, multiple: bool) -> Command {
self.arg(
Arg::new("project")
.value_name("PROJECT")
.long("project")
.short('p')
.value_parser(validate_project)
.global(true)
.action(if multiple {
ArgAction::Append
} else {
ArgAction::Set
})
.help("The project id or slug."),
)
}

fn release_arg(self) -> Command {
self.arg(
Arg::new("release")
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/_cases/events/events-help.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Commands:
help Print this message or the help of the given subcommand(s)

Options:
-o, --org <ORG> The organization slug
-o, --org <ORG> The organization id or slug.
--header <KEY:VALUE> Custom headers that should be attached to all requests
in key:value format.
-p, --project <PROJECT> The project slug.
-p, --project <PROJECT> The project id or slug.
--auth-token <AUTH_TOKEN> Use the given Sentry auth token.
--log-level <LOG_LEVEL> Set the log output verbosity. [possible values: trace, debug, info,
warn, error]
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/_cases/events/events-list-empty-id.trycmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```
$ sentry-cli events list --org 123 --project 1234
? success
No events found

```
4 changes: 2 additions & 2 deletions tests/integration/_cases/events/events-list-help.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ List all events in your organization.
Usage: sentry-cli[EXE] events list [OPTIONS]

Options:
-o, --org <ORG> The organization slug
-o, --org <ORG> The organization id or slug.
-U, --show-user Display the Users column.
--header <KEY:VALUE> Custom headers that should be attached to all requests
in key:value format.
-p, --project <PROJECT> The project slug.
-p, --project <PROJECT> The project id or slug.
-T, --show-tags Display the Tags column.
--auth-token <AUTH_TOKEN> Use the given Sentry auth token.
--max-rows <MAX_ROWS> Maximum number of rows to print.
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/_cases/events/events-list-id.trycmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```
$ sentry-cli events list --org 123 --project 1234
? success
+--------------------------------------+----------------------+--------------------+
| Event ID | Date | Title |
+--------------------------------------+----------------------+--------------------+
| 12345612-3456-1234-5612-345612345612 | 2024-07-10T16:45:57Z | Test Error Title |
| 12345671-2345-6712-3456-712345671234 | 2024-07-11T16:45:57Z | Test Error Title 2 |
+--------------------------------------+----------------------+--------------------+

```

12 changes: 12 additions & 0 deletions tests/integration/_cases/events/events-list.trycmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```
$ sentry-cli events list
? success
+--------------------------------------+----------------------+--------------------+
| Event ID | Date | Title |
+--------------------------------------+----------------------+--------------------+
| 12345612-3456-1234-5612-345612345612 | 2024-07-10T16:45:57Z | Test Error Title |
| 12345671-2345-6712-3456-712345671234 | 2024-07-11T16:45:57Z | Test Error Title 2 |
+--------------------------------------+----------------------+--------------------+

```

4 changes: 2 additions & 2 deletions tests/integration/_cases/events/events-no-subcommand.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Commands:
help Print this message or the help of the given subcommand(s)

Options:
-o, --org <ORG> The organization slug
-o, --org <ORG> The organization id or slug.
--header <KEY:VALUE> Custom headers that should be attached to all requests
in key:value format.
-p, --project <PROJECT> The project slug.
-p, --project <PROJECT> The project id or slug.
--auth-token <AUTH_TOKEN> Use the given Sentry auth token.
--log-level <LOG_LEVEL> Set the log output verbosity. [possible values: trace, debug, info,
warn, error]
Expand Down
66 changes: 66 additions & 0 deletions tests/integration/_responses/events/list-events.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[
{
"id": "id1",
"event.type": "error",
"groupID": "1234",
"eventID": "12345612345612345612345612345612",
"projectID": "1",
"message": "Test Error Message",
"title": "Test Error Title",
"location": "location.py",
"culprit": "/culprit/",
"user": {
"id": null,
"email": null,
"username": null,
"ip_address": null,
"name": null,
"data": null
},
"tags": [
{
"key": "environment",
"value": "[rpf"
},
{
"key": "handled",
"value": "yes"
},
{
"key": "level",
"value": "error"
}
],
"platform": "python",
"dateCreated": "2024-07-10T16:45:57Z",
"crashFile": null
},
{
"id": "id2",
"event.type": "error",
"groupID": "12345",
"eventID": "12345671234567123456712345671234",
"projectID": "1",
"message": "Test Error Message 2",
"title": "Test Error Title 2",
"location": "location.py",
"culprit": "/culprit/",
"user": {
"id": null,
"email": null,
"username": null,
"ip_address": null,
"name": null,
"data": null
},
"tags": [
{
"key": "environment",
"value": "prod"
}
],
"platform": "python",
"dateCreated": "2024-07-11T16:45:57Z",
"crashFile": null
}
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
]
]

Let's make sure this file ends in a newline

31 changes: 31 additions & 0 deletions tests/integration/events/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,34 @@ fn doesnt_fail_with_empty_response() {
);
register_test("events/events-list-empty.trycmd");
}

#[test]
fn doesnt_fail_with_empty_response_id() {
let _server = mock_endpoint(
EndpointOptions::new("GET", "/api/0/projects/123/1234/events/?cursor=", 200)
.with_response_body("[]"),
);
register_test("events/events-list-empty-id.trycmd");
}

#[test]
fn command_events_list() {
let _server = mock_endpoint(
EndpointOptions::new(
"GET",
"/api/0/projects/wat-org/wat-project/events/?cursor=",
200,
)
.with_response_file("events/list-events.json"),
);
register_test("events/events-list.trycmd");
}

#[test]
fn command_events_list_id() {
let _server = mock_endpoint(
EndpointOptions::new("GET", "/api/0/projects/123/1234/events/?cursor=", 200)
.with_response_file("events/list-events.json"),
);
register_test("events/events-list-id.trycmd");
}
Loading