2021-11-15 13:15:43 +00:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
# include <aws/core/Aws.h>
# include <aws/core/utils/Outcome.h>
# include <aws/codecommit/CodeCommitClient.h>
# include <aws/codecommit/model/ListPullRequestsRequest.h>
# include <aws/codecommit/model/ListPullRequestsResult.h>
# include <iostream>
/**
* Lists pull requests of a repository based on command line inputs
*/
2024-04-24 14:30:38 -04:00
int main ( int argc , char * * argv ) {
if ( argc ! = 2 ) {
std : : cout < < " Usage: list_pull_requests <repository_name> "
< < std : : endl ;
return 1 ;
}
2021-11-15 13:15:43 +00:00
2024-04-24 14:30:38 -04:00
Aws : : SDKOptions options ;
Aws : : InitAPI ( options ) ;
{
Aws : : String repository_name ( argv [ 1 ] ) ;
2021-11-15 13:15:43 +00:00
2024-04-24 14:30:38 -04:00
Aws : : CodeCommit : : CodeCommitClient codecommit ;
2021-11-15 13:15:43 +00:00
2024-04-24 14:30:38 -04:00
Aws : : CodeCommit : : Model : : ListPullRequestsRequest lpr_req ;
2021-11-15 13:15:43 +00:00
2024-04-24 14:30:38 -04:00
lpr_req . SetRepositoryName ( repository_name ) ;
2021-11-15 13:15:43 +00:00
2024-04-24 14:30:38 -04:00
Aws : : Vector < Aws : : String > all_pull_request ;
Aws : : String next_token ; // Used for pagination.
2021-11-15 13:15:43 +00:00
2024-04-24 14:30:38 -04:00
do {
if ( ! next_token . empty ( ) ) {
lpr_req . SetNextToken ( next_token ) ;
}
auto lpr_out = codecommit . ListPullRequests ( lpr_req ) ;
2021-11-15 13:15:43 +00:00
2024-04-24 14:30:38 -04:00
if ( lpr_out . IsSuccess ( ) ) {
const auto & lpr_res = lpr_out . GetResult ( ) . GetPullRequestIds ( ) ;
all_pull_request . insert ( all_pull_request . cend ( ) , lpr_res . cbegin ( ) ,
lpr_res . cend ( ) ) ;
next_token = lpr_out . GetResult ( ) . GetNextToken ( ) ;
}
else {
std : : cout < < " Error getting pull requests "
< < lpr_out . GetError ( ) . GetMessage ( )
< < std : : endl ;
break ;
}
} while ( ! next_token . empty ( ) ) ;
std : : cout < < all_pull_request . size ( ) < < " pull request(s) found. " < < std : : endl ;
for ( const auto & pull_request : all_pull_request ) {
std : : cout < < " Pull request: " < < pull_request < < std : : endl ;
}
2021-11-15 13:15:43 +00:00
}
2024-04-24 14:30:38 -04:00
Aws : : ShutdownAPI ( options ) ;
return 0 ;
2021-11-15 13:15:43 +00:00
}