Skip to content

Commit fe979c4

Browse files
fix(releases): Allow filtering to single release when listing
Partially revert #2991 to allow filtering by projects when running `releases list`. Resolves #3046 Resolves [CLI-253](https://linear.app/getsentry/issue/CLI-253/project-does-not-work-when-using-organization-token)
1 parent 483c3e2 commit fe979c4

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Fixed a bug, introduced in version 3.0.0, where the `sentry-cli releases list` command ignored the `--project` option ([#3048](https://github.com/getsentry/sentry-cli/pull/3048)). The command now correctly can filter releases by a single project when supplied via `--project`. This change does not enable filtering by multiple projects, which has never been supported.
8+
39
## 3.0.1
410

511
### Performance Improvements

src/api/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,16 @@ impl AuthenticatedApi<'_> {
542542

543543
/// Returns a list of releases for a given project. This is currently a
544544
/// capped list by what the server deems an acceptable default limit.
545-
pub fn list_releases(&self, org: &str) -> ApiResult<Vec<ReleaseInfo>> {
546-
let path = format!("/organizations/{}/releases/", PathArg(org));
547-
self.get(&path)?
548-
.convert_rnf::<Vec<ReleaseInfo>>(ApiErrorKind::OrganizationNotFound)
545+
pub fn list_releases(&self, org: &str, project: Option<&str>) -> ApiResult<Vec<ReleaseInfo>> {
546+
if let Some(project) = project {
547+
let path = format!("/projects/{}/{}/releases/", PathArg(org), PathArg(project));
548+
self.get(&path)?
549+
.convert_rnf::<Vec<ReleaseInfo>>(ApiErrorKind::ProjectNotFound)
550+
} else {
551+
let path = format!("/organizations/{}/releases/", PathArg(org));
552+
self.get(&path)?
553+
.convert_rnf::<Vec<ReleaseInfo>>(ApiErrorKind::OrganizationNotFound)
554+
}
549555
}
550556

551557
/// Looks up a release commits and returns it. If it does not exist `None`

src/commands/releases/list.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ pub fn make_command(command: Command) -> Command {
4343
pub fn execute(matches: &ArgMatches) -> Result<()> {
4444
let config = Config::current();
4545
let api = Api::current();
46+
let project = config.get_project(matches).ok();
4647
let releases = api
4748
.authenticated()?
48-
.list_releases(&config.get_org(matches)?)?;
49+
.list_releases(&config.get_org(matches)?, project.as_deref())?;
4950

5051
if matches.get_flag("raw") {
5152
let versions = releases

tests/integration/releases/list.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::integration::{MockEndpointBuilder, TestManager};
44
fn displays_releases() {
55
TestManager::new()
66
.mock_endpoint(
7-
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/releases/")
7+
MockEndpointBuilder::new("GET", "/api/0/projects/wat-org/wat-project/releases/")
88
.with_response_file("releases/get-releases.json"),
99
)
1010
.register_trycmd_test("releases/releases-list.trycmd")
@@ -15,7 +15,7 @@ fn displays_releases() {
1515
fn displays_releases_with_projects() {
1616
TestManager::new()
1717
.mock_endpoint(
18-
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/releases/")
18+
MockEndpointBuilder::new("GET", "/api/0/projects/wat-org/wat-project/releases/")
1919
.with_response_file("releases/get-releases.json"),
2020
)
2121
.register_trycmd_test("releases/releases-list-with-projects.trycmd")
@@ -26,7 +26,7 @@ fn displays_releases_with_projects() {
2626
fn doesnt_fail_with_empty_response() {
2727
TestManager::new()
2828
.mock_endpoint(
29-
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/releases/")
29+
MockEndpointBuilder::new("GET", "/api/0/projects/wat-org/wat-project/releases/")
3030
.with_response_body("[]"),
3131
)
3232
.register_trycmd_test("releases/releases-list-empty.trycmd")
@@ -37,7 +37,7 @@ fn doesnt_fail_with_empty_response() {
3737
fn can_override_org() {
3838
TestManager::new()
3939
.mock_endpoint(
40-
MockEndpointBuilder::new("GET", "/api/0/organizations/whynot/releases/")
40+
MockEndpointBuilder::new("GET", "/api/0/projects/whynot/wat-project/releases/")
4141
.with_response_file("releases/get-releases.json"),
4242
)
4343
.register_trycmd_test("releases/releases-list-override-org.trycmd")
@@ -48,7 +48,7 @@ fn can_override_org() {
4848
fn displays_releases_in_raw_mode() {
4949
TestManager::new()
5050
.mock_endpoint(
51-
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/releases/")
51+
MockEndpointBuilder::new("GET", "/api/0/projects/wat-org/wat-project/releases/")
5252
.with_response_file("releases/get-releases.json"),
5353
)
5454
.register_trycmd_test("releases/releases-list-raw.trycmd")
@@ -59,7 +59,7 @@ fn displays_releases_in_raw_mode() {
5959
fn displays_releases_in_raw_mode_with_delimiter() {
6060
TestManager::new()
6161
.mock_endpoint(
62-
MockEndpointBuilder::new("GET", "/api/0/organizations/wat-org/releases/")
62+
MockEndpointBuilder::new("GET", "/api/0/projects/wat-org/wat-project/releases/")
6363
.with_response_file("releases/get-releases.json"),
6464
)
6565
.register_trycmd_test("releases/releases-list-raw-delimiter.trycmd")

0 commit comments

Comments
 (0)