@@ -51,6 +51,7 @@ use crate::utils::retry::{get_default_backoff, DurationAsMilliseconds};
5151use crate :: utils:: sourcemaps:: get_sourcemap_reference_from_headers;
5252use crate :: utils:: ui:: { capitalize_string, make_byte_progress_bar} ;
5353
54+ use self :: pagination:: Pagination ;
5455use connection_manager:: CurlConnectionManager ;
5556use encoding:: { PathArg , QueryArg } ;
5657use errors:: { ApiError , ApiErrorKind , ApiResult , SentryError } ;
@@ -533,9 +534,9 @@ impl<'a> AuthenticatedApi<'a> {
533534 }
534535 }
535536
536- let next = resp. next_pagination_cursor ( ) ;
537+ let pagination = resp. pagination ( ) ;
537538 rv. extend ( resp. convert :: < Vec < Artifact > > ( ) ?) ;
538- if let Some ( next) = next {
539+ if let Some ( next) = pagination . into_next_cursor ( ) {
539540 cursor = next;
540541 } else {
541542 break ;
@@ -1134,9 +1135,9 @@ impl<'a> AuthenticatedApi<'a> {
11341135 break ;
11351136 }
11361137 }
1137- let next = resp. next_pagination_cursor ( ) ;
1138+ let pagination = resp. pagination ( ) ;
11381139 rv. extend ( resp. convert :: < Vec < Organization > > ( ) ?) ;
1139- if let Some ( next) = next {
1140+ if let Some ( next) = pagination . into_next_cursor ( ) {
11401141 cursor = next;
11411142 } else {
11421143 break ;
@@ -1178,9 +1179,9 @@ impl<'a> AuthenticatedApi<'a> {
11781179 break ;
11791180 }
11801181 }
1181- let next = resp. next_pagination_cursor ( ) ;
1182+ let pagination = resp. pagination ( ) ;
11821183 rv. extend ( resp. convert :: < Vec < Monitor > > ( ) ?) ;
1183- if let Some ( next) = next {
1184+ if let Some ( next) = pagination . into_next_cursor ( ) {
11841185 cursor = next;
11851186 } else {
11861187 break ;
@@ -1206,9 +1207,9 @@ impl<'a> AuthenticatedApi<'a> {
12061207 break ;
12071208 }
12081209 }
1209- let next = resp. next_pagination_cursor ( ) ;
1210+ let pagination = resp. pagination ( ) ;
12101211 rv. extend ( resp. convert :: < Vec < Project > > ( ) ?) ;
1211- if let Some ( next) = next {
1212+ if let Some ( next) = pagination . into_next_cursor ( ) {
12121213 cursor = next;
12131214 } else {
12141215 break ;
@@ -1246,14 +1247,14 @@ impl<'a> AuthenticatedApi<'a> {
12461247 }
12471248 }
12481249
1249- let next = resp. next_pagination_cursor ( ) ;
1250+ let pagination = resp. pagination ( ) ;
12501251 rv. extend ( resp. convert :: < Vec < ProcessedEvent > > ( ) ?) ;
12511252
12521253 if requests_no == max_pages {
12531254 break ;
12541255 }
12551256
1256- if let Some ( next) = next {
1257+ if let Some ( next) = pagination . into_next_cursor ( ) {
12571258 cursor = next;
12581259 } else {
12591260 break ;
@@ -1272,7 +1273,7 @@ impl<'a> AuthenticatedApi<'a> {
12721273 query : Option < String > ,
12731274 ) -> ApiResult < Vec < Issue > > {
12741275 let mut rv = vec ! [ ] ;
1275- let mut cursor = String :: from ( "" ) ;
1276+ let mut cursor = "" . to_string ( ) ;
12761277 let mut requests_no = 0 ;
12771278
12781279 let url = if let Some ( query) = query {
@@ -1299,14 +1300,14 @@ impl<'a> AuthenticatedApi<'a> {
12991300 }
13001301 }
13011302
1302- let next = resp. next_pagination_cursor ( ) ;
1303+ let pagination = resp. pagination ( ) ;
13031304 rv. extend ( resp. convert :: < Vec < Issue > > ( ) ?) ;
13041305
13051306 if requests_no == max_pages {
13061307 break ;
13071308 }
13081309
1309- if let Some ( next) = next {
1310+ if let Some ( next) = pagination . into_next_cursor ( ) {
13101311 cursor = next;
13111312 } else {
13121313 break ;
@@ -1330,12 +1331,13 @@ impl<'a> AuthenticatedApi<'a> {
13301331 if resp. status ( ) == 404 {
13311332 break ;
13321333 } else {
1333- if let Some ( next) = resp. next_pagination_cursor ( ) {
1334+ let pagination = resp. pagination ( ) ;
1335+ rv. extend ( resp. convert :: < Vec < Repo > > ( ) ?) ;
1336+ if let Some ( next) = pagination. into_next_cursor ( ) {
13341337 cursor = next;
13351338 } else {
13361339 break ;
13371340 }
1338- rv. extend ( resp. convert :: < Vec < Repo > > ( ) ?) ;
13391341 }
13401342 }
13411343 Ok ( rv)
@@ -1968,10 +1970,11 @@ impl ApiResponse {
19681970 None
19691971 }
19701972
1971- fn next_pagination_cursor ( & self ) -> Option < String > {
1973+ /// Returns the pagination info
1974+ pub fn pagination ( & self ) -> Pagination {
19721975 self . get_header ( "link" )
1973- . and_then ( pagination :: next_cursor )
1974- . map ( String :: from )
1976+ . and_then ( |x| x . parse ( ) . ok ( ) )
1977+ . unwrap_or_default ( )
19751978 }
19761979
19771980 /// Returns true if the response is JSON.
0 commit comments