1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package codegurureviewer 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/codegurureviewer/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Use to associate an Amazon Web Services CodeCommit repository or a repostory 16// managed by Amazon Web Services CodeStar Connections with Amazon CodeGuru 17// Reviewer. When you associate a repository, CodeGuru Reviewer reviews source code 18// changes in the repository's pull requests and provides automatic 19// recommendations. You can view recommendations using the CodeGuru Reviewer 20// console. For more information, see Recommendations in Amazon CodeGuru Reviewer 21// (https://docs.aws.amazon.com/codeguru/latest/reviewer-ug/recommendations.html) 22// in the Amazon CodeGuru Reviewer User Guide. If you associate a CodeCommit or S3 23// repository, it must be in the same Amazon Web Services Region and Amazon Web 24// Services account where its CodeGuru Reviewer code reviews are configured. 25// Bitbucket and GitHub Enterprise Server repositories are managed by Amazon Web 26// Services CodeStar Connections to connect to CodeGuru Reviewer. For more 27// information, see Associate a repository 28// (https://docs.aws.amazon.com/codeguru/latest/reviewer-ug/getting-started-associate-repository.html) 29// in the Amazon CodeGuru Reviewer User Guide. You cannot use the CodeGuru Reviewer 30// SDK or the Amazon Web Services CLI to associate a GitHub repository with Amazon 31// CodeGuru Reviewer. To associate a GitHub repository, use the console. For more 32// information, see Getting started with CodeGuru Reviewer 33// (https://docs.aws.amazon.com/codeguru/latest/reviewer-ug/getting-started-with-guru.html) 34// in the CodeGuru Reviewer User Guide. 35func (c *Client) AssociateRepository(ctx context.Context, params *AssociateRepositoryInput, optFns ...func(*Options)) (*AssociateRepositoryOutput, error) { 36 if params == nil { 37 params = &AssociateRepositoryInput{} 38 } 39 40 result, metadata, err := c.invokeOperation(ctx, "AssociateRepository", params, optFns, c.addOperationAssociateRepositoryMiddlewares) 41 if err != nil { 42 return nil, err 43 } 44 45 out := result.(*AssociateRepositoryOutput) 46 out.ResultMetadata = metadata 47 return out, nil 48} 49 50type AssociateRepositoryInput struct { 51 52 // The repository to associate. 53 // 54 // This member is required. 55 Repository *types.Repository 56 57 // Amazon CodeGuru Reviewer uses this value to prevent the accidental creation of 58 // duplicate repository associations if there are failures and retries. 59 ClientRequestToken *string 60 61 // A KMSKeyDetails object that contains: 62 // 63 // * The encryption option for this 64 // repository association. It is either owned by Amazon Web Services Key Management 65 // Service (KMS) (AWS_OWNED_CMK) or customer managed (CUSTOMER_MANAGED_CMK). 66 // 67 // * The 68 // ID of the Amazon Web Services KMS key that is associated with this respository 69 // association. 70 KMSKeyDetails *types.KMSKeyDetails 71 72 // An array of key-value pairs used to tag an associated repository. A tag is a 73 // custom attribute label with two parts: 74 // 75 // * A tag key (for example, CostCenter, 76 // Environment, Project, or Secret). Tag keys are case sensitive. 77 // 78 // * An optional 79 // field known as a tag value (for example, 111122223333, Production, or a team 80 // name). Omitting the tag value is the same as using an empty string. Like tag 81 // keys, tag values are case sensitive. 82 Tags map[string]string 83 84 noSmithyDocumentSerde 85} 86 87type AssociateRepositoryOutput struct { 88 89 // Information about the repository association. 90 RepositoryAssociation *types.RepositoryAssociation 91 92 // An array of key-value pairs used to tag an associated repository. A tag is a 93 // custom attribute label with two parts: 94 // 95 // * A tag key (for example, CostCenter, 96 // Environment, Project, or Secret). Tag keys are case sensitive. 97 // 98 // * An optional 99 // field known as a tag value (for example, 111122223333, Production, or a team 100 // name). Omitting the tag value is the same as using an empty string. Like tag 101 // keys, tag values are case sensitive. 102 Tags map[string]string 103 104 // Metadata pertaining to the operation's result. 105 ResultMetadata middleware.Metadata 106 107 noSmithyDocumentSerde 108} 109 110func (c *Client) addOperationAssociateRepositoryMiddlewares(stack *middleware.Stack, options Options) (err error) { 111 err = stack.Serialize.Add(&awsRestjson1_serializeOpAssociateRepository{}, middleware.After) 112 if err != nil { 113 return err 114 } 115 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpAssociateRepository{}, middleware.After) 116 if err != nil { 117 return err 118 } 119 if err = addSetLoggerMiddleware(stack, options); err != nil { 120 return err 121 } 122 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 123 return err 124 } 125 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 126 return err 127 } 128 if err = addResolveEndpointMiddleware(stack, options); err != nil { 129 return err 130 } 131 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 132 return err 133 } 134 if err = addRetryMiddlewares(stack, options); err != nil { 135 return err 136 } 137 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 138 return err 139 } 140 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 141 return err 142 } 143 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 144 return err 145 } 146 if err = addClientUserAgent(stack); err != nil { 147 return err 148 } 149 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 150 return err 151 } 152 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 153 return err 154 } 155 if err = addIdempotencyToken_opAssociateRepositoryMiddleware(stack, options); err != nil { 156 return err 157 } 158 if err = addOpAssociateRepositoryValidationMiddleware(stack); err != nil { 159 return err 160 } 161 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opAssociateRepository(options.Region), middleware.Before); err != nil { 162 return err 163 } 164 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 165 return err 166 } 167 if err = addResponseErrorMiddleware(stack); err != nil { 168 return err 169 } 170 if err = addRequestResponseLogging(stack, options); err != nil { 171 return err 172 } 173 return nil 174} 175 176type idempotencyToken_initializeOpAssociateRepository struct { 177 tokenProvider IdempotencyTokenProvider 178} 179 180func (*idempotencyToken_initializeOpAssociateRepository) ID() string { 181 return "OperationIdempotencyTokenAutoFill" 182} 183 184func (m *idempotencyToken_initializeOpAssociateRepository) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) ( 185 out middleware.InitializeOutput, metadata middleware.Metadata, err error, 186) { 187 if m.tokenProvider == nil { 188 return next.HandleInitialize(ctx, in) 189 } 190 191 input, ok := in.Parameters.(*AssociateRepositoryInput) 192 if !ok { 193 return out, metadata, fmt.Errorf("expected middleware input to be of type *AssociateRepositoryInput ") 194 } 195 196 if input.ClientRequestToken == nil { 197 t, err := m.tokenProvider.GetIdempotencyToken() 198 if err != nil { 199 return out, metadata, err 200 } 201 input.ClientRequestToken = &t 202 } 203 return next.HandleInitialize(ctx, in) 204} 205func addIdempotencyToken_opAssociateRepositoryMiddleware(stack *middleware.Stack, cfg Options) error { 206 return stack.Initialize.Add(&idempotencyToken_initializeOpAssociateRepository{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before) 207} 208 209func newServiceMetadataMiddleware_opAssociateRepository(region string) *awsmiddleware.RegisterServiceMetadata { 210 return &awsmiddleware.RegisterServiceMetadata{ 211 Region: region, 212 ServiceID: ServiceID, 213 SigningName: "codeguru-reviewer", 214 OperationName: "AssociateRepository", 215 } 216} 217