Skip to content

Commit a1e38cc

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 7570215 commit a1e38cc

4 files changed

Lines changed: 19 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
### Fixes
1414

1515
- Fixed a bug that prevented project IDs from being used with the `sentry-cli releases new` command for users with self-hosted Sentry instances on versions older than 25.12.1 ([#3068](https://github.com/getsentry/sentry-cli/issues/3068)).
16+
- 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.
1617

1718
## 3.0.3
1819

src/api/mod.rs

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

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

549555
/// 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)