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 information about merge conflicts between the before and after commit
16// IDs for a pull request in a repository.
17func (c *Client) GetMergeConflicts(ctx context.Context, params *GetMergeConflictsInput, optFns ...func(*Options)) (*GetMergeConflictsOutput, error) {
18	if params == nil {
19		params = &GetMergeConflictsInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "GetMergeConflicts", params, optFns, addOperationGetMergeConflictsMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*GetMergeConflictsOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type GetMergeConflictsInput struct {
33
34	// The branch, tag, HEAD, or other fully qualified reference used to identify a
35	// commit (for example, a branch name or a full commit ID).
36	//
37	// This member is required.
38	DestinationCommitSpecifier *string
39
40	// The merge option or strategy you want to use to merge the code.
41	//
42	// This member is required.
43	MergeOption types.MergeOptionTypeEnum
44
45	// The name of the repository where the pull request was created.
46	//
47	// This member is required.
48	RepositoryName *string
49
50	// The branch, tag, HEAD, or other fully qualified reference used to identify a
51	// commit (for example, a branch name or a full commit ID).
52	//
53	// This member is required.
54	SourceCommitSpecifier *string
55
56	// The level of conflict detail to use. If unspecified, the default FILE_LEVEL is
57	// used, which returns a not-mergeable result if the same file has differences in
58	// both branches. If LINE_LEVEL is specified, a conflict is considered not
59	// mergeable if the same file in both branches has differences on the same line.
60	ConflictDetailLevel types.ConflictDetailLevelTypeEnum
61
62	// Specifies which branch to use when resolving conflicts, or whether to attempt
63	// automatically merging two versions of a file. The default is NONE, which
64	// requires any conflicts to be resolved manually before the merge operation is
65	// successful.
66	ConflictResolutionStrategy types.ConflictResolutionStrategyTypeEnum
67
68	// The maximum number of files to include in the output.
69	MaxConflictFiles *int32
70
71	// An enumeration token that, when provided in a request, returns the next batch of
72	// the results.
73	NextToken *string
74}
75
76type GetMergeConflictsOutput struct {
77
78	// A list of metadata for any conflicting files. If the specified merge strategy is
79	// FAST_FORWARD_MERGE, this list is always empty.
80	//
81	// This member is required.
82	ConflictMetadataList []types.ConflictMetadata
83
84	// The commit ID of the destination commit specifier that was used in the merge
85	// evaluation.
86	//
87	// This member is required.
88	DestinationCommitId *string
89
90	// A Boolean value that indicates whether the code is mergeable by the specified
91	// merge option.
92	//
93	// This member is required.
94	Mergeable bool
95
96	// The commit ID of the source commit specifier that was used in the merge
97	// evaluation.
98	//
99	// This member is required.
100	SourceCommitId *string
101
102	// The commit ID of the merge base.
103	BaseCommitId *string
104
105	// An enumeration token that can be used in a request to return the next batch of
106	// the results.
107	NextToken *string
108
109	// Metadata pertaining to the operation's result.
110	ResultMetadata middleware.Metadata
111}
112
113func addOperationGetMergeConflictsMiddlewares(stack *middleware.Stack, options Options) (err error) {
114	err = stack.Serialize.Add(&awsAwsjson11_serializeOpGetMergeConflicts{}, middleware.After)
115	if err != nil {
116		return err
117	}
118	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpGetMergeConflicts{}, middleware.After)
119	if err != nil {
120		return err
121	}
122	if err = addSetLoggerMiddleware(stack, options); err != nil {
123		return err
124	}
125	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
126		return err
127	}
128	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
129		return err
130	}
131	if err = addResolveEndpointMiddleware(stack, options); err != nil {
132		return err
133	}
134	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
135		return err
136	}
137	if err = addRetryMiddlewares(stack, options); err != nil {
138		return err
139	}
140	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
141		return err
142	}
143	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
144		return err
145	}
146	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
147		return err
148	}
149	if err = addClientUserAgent(stack); err != nil {
150		return err
151	}
152	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
153		return err
154	}
155	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
156		return err
157	}
158	if err = addOpGetMergeConflictsValidationMiddleware(stack); err != nil {
159		return err
160	}
161	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetMergeConflicts(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
176// GetMergeConflictsAPIClient is a client that implements the GetMergeConflicts
177// operation.
178type GetMergeConflictsAPIClient interface {
179	GetMergeConflicts(context.Context, *GetMergeConflictsInput, ...func(*Options)) (*GetMergeConflictsOutput, error)
180}
181
182var _ GetMergeConflictsAPIClient = (*Client)(nil)
183
184// GetMergeConflictsPaginatorOptions is the paginator options for GetMergeConflicts
185type GetMergeConflictsPaginatorOptions struct {
186	// The maximum number of files to include in the output.
187	Limit int32
188
189	// Set to true if pagination should stop if the service returns a pagination token
190	// that matches the most recent token provided to the service.
191	StopOnDuplicateToken bool
192}
193
194// GetMergeConflictsPaginator is a paginator for GetMergeConflicts
195type GetMergeConflictsPaginator struct {
196	options   GetMergeConflictsPaginatorOptions
197	client    GetMergeConflictsAPIClient
198	params    *GetMergeConflictsInput
199	nextToken *string
200	firstPage bool
201}
202
203// NewGetMergeConflictsPaginator returns a new GetMergeConflictsPaginator
204func NewGetMergeConflictsPaginator(client GetMergeConflictsAPIClient, params *GetMergeConflictsInput, optFns ...func(*GetMergeConflictsPaginatorOptions)) *GetMergeConflictsPaginator {
205	if params == nil {
206		params = &GetMergeConflictsInput{}
207	}
208
209	options := GetMergeConflictsPaginatorOptions{}
210	if params.MaxConflictFiles != nil {
211		options.Limit = *params.MaxConflictFiles
212	}
213
214	for _, fn := range optFns {
215		fn(&options)
216	}
217
218	return &GetMergeConflictsPaginator{
219		options:   options,
220		client:    client,
221		params:    params,
222		firstPage: true,
223	}
224}
225
226// HasMorePages returns a boolean indicating whether more pages are available
227func (p *GetMergeConflictsPaginator) HasMorePages() bool {
228	return p.firstPage || p.nextToken != nil
229}
230
231// NextPage retrieves the next GetMergeConflicts page.
232func (p *GetMergeConflictsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*GetMergeConflictsOutput, error) {
233	if !p.HasMorePages() {
234		return nil, fmt.Errorf("no more pages available")
235	}
236
237	params := *p.params
238	params.NextToken = p.nextToken
239
240	var limit *int32
241	if p.options.Limit > 0 {
242		limit = &p.options.Limit
243	}
244	params.MaxConflictFiles = limit
245
246	result, err := p.client.GetMergeConflicts(ctx, &params, optFns...)
247	if err != nil {
248		return nil, err
249	}
250	p.firstPage = false
251
252	prevToken := p.nextToken
253	p.nextToken = result.NextToken
254
255	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
256		p.nextToken = nil
257	}
258
259	return result, nil
260}
261
262func newServiceMetadataMiddleware_opGetMergeConflicts(region string) *awsmiddleware.RegisterServiceMetadata {
263	return &awsmiddleware.RegisterServiceMetadata{
264		Region:        region,
265		ServiceID:     ServiceID,
266		SigningName:   "codecommit",
267		OperationName: "GetMergeConflicts",
268	}
269}
270