-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(releases): Revert pagination refactor
Revert 29df3e8 (and also d62d2ec, which contains tests for 29df3e8). These changes, which meant to simplify our pagination logic, appear to have caused several closely-related regressions in Sentry CLI version 2.31.1. Fixes GH-2053 May fix (potentially, need to verify) GH-2052, GH-2054, and GH-2055
- Loading branch information
1 parent
038f6ee
commit 9e81b91
Showing
2 changed files
with
53 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,42 @@ | ||
use std::str::FromStr; | ||
|
||
use crate::utils::http; | ||
|
||
pub(super) fn next_cursor(value: &str) -> Option<&str> { | ||
http::parse_link_header(value) | ||
.iter() | ||
.rev() // Reversing is necessary for backwards compatibility with a previous implementation | ||
.find(|item| item.get("rel") == Some(&"next")) | ||
.and_then::<&str, _>(|item| { | ||
if item.get("results") == Some(&"true") { | ||
Some(item.get("cursor").unwrap_or(&"")) | ||
} else { | ||
None | ||
} | ||
}) | ||
#[derive(Debug, Clone)] | ||
pub struct Link { | ||
results: bool, | ||
cursor: String, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
#[derive(Debug, Default, Clone)] | ||
pub struct Pagination { | ||
next: Option<Link>, | ||
} | ||
|
||
#[test] | ||
fn test_pagination_empty_string() { | ||
let result = next_cursor(""); | ||
assert_eq!(result, None); | ||
impl Pagination { | ||
pub fn into_next_cursor(self) -> Option<String> { | ||
self.next | ||
.and_then(|x| if x.results { Some(x.cursor) } else { None }) | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_pagination_with_next() { | ||
let result = next_cursor( | ||
"<https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:-1:1>; \ | ||
rel=\"previous\"; results=\"false\"; cursor=\"100:-1:1\", \ | ||
<https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:1:0>; \ | ||
rel=\"next\"; results=\"true\"; cursor=\"100:1:0\"", | ||
); | ||
assert_eq!(result, Some("100:1:0")); | ||
} | ||
impl FromStr for Pagination { | ||
type Err = (); | ||
|
||
fn from_str(s: &str) -> Result<Pagination, ()> { | ||
let mut rv = Pagination::default(); | ||
for item in http::parse_link_header(s) { | ||
let target = match item.get("rel") { | ||
Some(&"next") => &mut rv.next, | ||
_ => continue, | ||
}; | ||
|
||
*target = Some(Link { | ||
results: item.get("results") == Some(&"true"), | ||
cursor: (*item.get("cursor").unwrap_or(&"")).to_string(), | ||
}); | ||
} | ||
|
||
#[test] | ||
fn test_pagination_without_next() { | ||
let result = next_cursor( | ||
"<https://sentry.io/api/0/organizations/sentry/releases/?&cursor=100:-1:1>; \ | ||
rel=\"previous\"; results=\"false\"; cursor=\"100:-1:1\"", | ||
); | ||
assert_eq!(result, None); | ||
Ok(rv) | ||
} | ||
} |