exceptionfactory commented on code in PR #10948:
URL: https://github.com/apache/nifi/pull/10948#discussion_r2914383193


##########
nifi-extension-bundles/nifi-azure-bundle/nifi-azure-registry-clients/src/main/java/org/apache/nifi/azure/devops/AzureDevOpsRepositoryClient.java:
##########
@@ -389,11 +372,59 @@ public String createContent(final GitCreateContentRequest 
request) throws FlowRe
         }
 
         final String encoded = 
Base64.getEncoder().encodeToString(request.getContent().getBytes(StandardCharsets.UTF_8));
+        final URI pushUri = getUriBuilder().addPathSegment(SEGMENT_PUSHES)
+                .addQueryParameter(API, API_VERSION)
+                .build();
+
+        for (int attempt = 1; attempt <= MAX_PUSH_ATTEMPTS; attempt++) {
+            if (expectedFileCommit != null) {
+                final Optional<String> currentFileCommit = 
getContentSha(request.getPath(), branch);
+                if (currentFileCommit.isPresent() && 
!currentFileCommit.get().equals(expectedFileCommit)) {
+                    throw new FlowRegistryException("File [%s] has been 
modified by another commit".formatted(path));
+                }
+            }
 
+            final String branchHead = fetchBranchHead(branch);
+            final HttpResponseEntity response = executePush(pushUri, branch, 
branchHead, encoded, message, changeType, path);
+
+            if (response.statusCode() == HttpURLConnection.HTTP_CREATED) {
+                try {
+                    final JsonNode pushResponse = 
MAPPER.readTree(response.body());
+                    return 
pushResponse.get(SEGMENT_COMMITS).get(0).get(JSON_FIELD_COMMIT_ID).asText();
+                } catch (final IOException e) {
+                    throw new FlowRegistryException("Failed to parse push 
response", e);

Review Comment:
   It would be helpful to include the `pushUri` in this message.



##########
nifi-extension-bundles/nifi-azure-bundle/nifi-azure-registry-clients/src/main/java/org/apache/nifi/azure/devops/AzureDevOpsRepositoryClient.java:
##########
@@ -389,11 +372,59 @@ public String createContent(final GitCreateContentRequest 
request) throws FlowRe
         }
 
         final String encoded = 
Base64.getEncoder().encodeToString(request.getContent().getBytes(StandardCharsets.UTF_8));
+        final URI pushUri = getUriBuilder().addPathSegment(SEGMENT_PUSHES)
+                .addQueryParameter(API, API_VERSION)
+                .build();
+
+        for (int attempt = 1; attempt <= MAX_PUSH_ATTEMPTS; attempt++) {
+            if (expectedFileCommit != null) {
+                final Optional<String> currentFileCommit = 
getContentSha(request.getPath(), branch);
+                if (currentFileCommit.isPresent() && 
!currentFileCommit.get().equals(expectedFileCommit)) {
+                    throw new FlowRegistryException("File [%s] has been 
modified by another commit".formatted(path));

Review Comment:
   It would be helpful to include the current file commit value in the message 
for reference purposes.



##########
nifi-extension-bundles/nifi-atlassian-bundle/nifi-atlassian-extensions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitbucketRepositoryClient.java:
##########
@@ -427,33 +429,75 @@ public String createContent(final GitCreateContentRequest 
request) throws FlowRe
     }
 
     private String createContentCloud(final GitCreateContentRequest request, 
final String resolvedPath, final String branch) throws FlowRegistryException {
-        final StandardMultipartFormDataStreamBuilder multipartBuilder = new 
StandardMultipartFormDataStreamBuilder();
-        multipartBuilder.addPart(resolvedPath, 
StandardHttpContentType.APPLICATION_JSON, 
request.getContent().getBytes(StandardCharsets.UTF_8));
-        multipartBuilder.addPart(FIELD_MESSAGE, 
StandardHttpContentType.TEXT_PLAIN, 
request.getMessage().getBytes(StandardCharsets.UTF_8));
-        multipartBuilder.addPart(FIELD_BRANCH, 
StandardHttpContentType.TEXT_PLAIN, branch.getBytes(StandardCharsets.UTF_8));
+        final String expectedFileCommit = request.getExpectedCommitSha();
+        final URI uri = 
getRepositoryUriBuilder().addPathSegment("src").build();
 
-        // Add parents parameter for atomic commit - Bitbucket Cloud will 
reject if the branch has moved
-        final String expectedCommitSha = request.getExpectedCommitSha();
-        if (expectedCommitSha != null && !expectedCommitSha.isBlank()) {
-            multipartBuilder.addPart(FIELD_PARENTS, 
StandardHttpContentType.TEXT_PLAIN, 
expectedCommitSha.getBytes(StandardCharsets.UTF_8));
+        for (int attempt = 1; attempt <= MAX_PUSH_ATTEMPTS; attempt++) {
+            if (expectedFileCommit != null) {
+                final Optional<String> currentFileCommit = 
getLatestCommit(branch, resolvedPath);
+                if (currentFileCommit.isPresent() && 
!currentFileCommit.get().equals(expectedFileCommit)) {
+                    throw new FlowRegistryException("File [%s] has been 
modified by another commit".formatted(resolvedPath));

Review Comment:
   It would be helpful to include the current file commit is this message.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to