1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package codecommit 4 5import ( 6 "context" 7 "fmt" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 10 "github.com/aws/aws-sdk-go-v2/service/codecommit/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Returns a list of pull requests for a specified repository. The return list can 16// be refined by pull request status or pull request author ARN. 17func (c *Client) ListPullRequests(ctx context.Context, params *ListPullRequestsInput, optFns ...func(*Options)) (*ListPullRequestsOutput, error) { 18 if params == nil { 19 params = &ListPullRequestsInput{} 20 } 21 22 result, metadata, err := c.invokeOperation(ctx, "ListPullRequests", params, optFns, addOperationListPullRequestsMiddlewares) 23 if err != nil { 24 return nil, err 25 } 26 27 out := result.(*ListPullRequestsOutput) 28 out.ResultMetadata = metadata 29 return out, nil 30} 31 32type ListPullRequestsInput struct { 33 34 // The name of the repository for which you want to list pull requests. 35 // 36 // This member is required. 37 RepositoryName *string 38 39 // Optional. The Amazon Resource Name (ARN) of the user who created the pull 40 // request. If used, this filters the results to pull requests created by that 41 // user. 42 AuthorArn *string 43 44 // A non-zero, non-negative integer used to limit the number of returned results. 45 MaxResults *int32 46 47 // An enumeration token that, when provided in a request, returns the next batch of 48 // the results. 49 NextToken *string 50 51 // Optional. The status of the pull request. If used, this refines the results to 52 // the pull requests that match the specified status. 53 PullRequestStatus types.PullRequestStatusEnum 54} 55 56type ListPullRequestsOutput struct { 57 58 // The system-generated IDs of the pull requests. 59 // 60 // This member is required. 61 PullRequestIds []string 62 63 // An enumeration token that allows the operation to batch the next results of the 64 // operation. 65 NextToken *string 66 67 // Metadata pertaining to the operation's result. 68 ResultMetadata middleware.Metadata 69} 70 71func addOperationListPullRequestsMiddlewares(stack *middleware.Stack, options Options) (err error) { 72 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListPullRequests{}, middleware.After) 73 if err != nil { 74 return err 75 } 76 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListPullRequests{}, middleware.After) 77 if err != nil { 78 return err 79 } 80 if err = addSetLoggerMiddleware(stack, options); err != nil { 81 return err 82 } 83 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 84 return err 85 } 86 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 87 return err 88 } 89 if err = addResolveEndpointMiddleware(stack, options); err != nil { 90 return err 91 } 92 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 93 return err 94 } 95 if err = addRetryMiddlewares(stack, options); err != nil { 96 return err 97 } 98 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 99 return err 100 } 101 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 102 return err 103 } 104 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 105 return err 106 } 107 if err = addClientUserAgent(stack); err != nil { 108 return err 109 } 110 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 111 return err 112 } 113 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 114 return err 115 } 116 if err = addOpListPullRequestsValidationMiddleware(stack); err != nil { 117 return err 118 } 119 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListPullRequests(options.Region), middleware.Before); err != nil { 120 return err 121 } 122 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 123 return err 124 } 125 if err = addResponseErrorMiddleware(stack); err != nil { 126 return err 127 } 128 if err = addRequestResponseLogging(stack, options); err != nil { 129 return err 130 } 131 return nil 132} 133 134// ListPullRequestsAPIClient is a client that implements the ListPullRequests 135// operation. 136type ListPullRequestsAPIClient interface { 137 ListPullRequests(context.Context, *ListPullRequestsInput, ...func(*Options)) (*ListPullRequestsOutput, error) 138} 139 140var _ ListPullRequestsAPIClient = (*Client)(nil) 141 142// ListPullRequestsPaginatorOptions is the paginator options for ListPullRequests 143type ListPullRequestsPaginatorOptions struct { 144 // A non-zero, non-negative integer used to limit the number of returned results. 145 Limit int32 146 147 // Set to true if pagination should stop if the service returns a pagination token 148 // that matches the most recent token provided to the service. 149 StopOnDuplicateToken bool 150} 151 152// ListPullRequestsPaginator is a paginator for ListPullRequests 153type ListPullRequestsPaginator struct { 154 options ListPullRequestsPaginatorOptions 155 client ListPullRequestsAPIClient 156 params *ListPullRequestsInput 157 nextToken *string 158 firstPage bool 159} 160 161// NewListPullRequestsPaginator returns a new ListPullRequestsPaginator 162func NewListPullRequestsPaginator(client ListPullRequestsAPIClient, params *ListPullRequestsInput, optFns ...func(*ListPullRequestsPaginatorOptions)) *ListPullRequestsPaginator { 163 options := ListPullRequestsPaginatorOptions{} 164 if params.MaxResults != nil { 165 options.Limit = *params.MaxResults 166 } 167 168 for _, fn := range optFns { 169 fn(&options) 170 } 171 172 if params == nil { 173 params = &ListPullRequestsInput{} 174 } 175 176 return &ListPullRequestsPaginator{ 177 options: options, 178 client: client, 179 params: params, 180 firstPage: true, 181 } 182} 183 184// HasMorePages returns a boolean indicating whether more pages are available 185func (p *ListPullRequestsPaginator) HasMorePages() bool { 186 return p.firstPage || p.nextToken != nil 187} 188 189// NextPage retrieves the next ListPullRequests page. 190func (p *ListPullRequestsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListPullRequestsOutput, error) { 191 if !p.HasMorePages() { 192 return nil, fmt.Errorf("no more pages available") 193 } 194 195 params := *p.params 196 params.NextToken = p.nextToken 197 198 var limit *int32 199 if p.options.Limit > 0 { 200 limit = &p.options.Limit 201 } 202 params.MaxResults = limit 203 204 result, err := p.client.ListPullRequests(ctx, ¶ms, optFns...) 205 if err != nil { 206 return nil, err 207 } 208 p.firstPage = false 209 210 prevToken := p.nextToken 211 p.nextToken = result.NextToken 212 213 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 214 p.nextToken = nil 215 } 216 217 return result, nil 218} 219 220func newServiceMetadataMiddleware_opListPullRequests(region string) *awsmiddleware.RegisterServiceMetadata { 221 return &awsmiddleware.RegisterServiceMetadata{ 222 Region: region, 223 ServiceID: ServiceID, 224 SigningName: "codecommit", 225 OperationName: "ListPullRequests", 226 } 227} 228