pvillard31 commented on code in PR #10322:
URL: https://github.com/apache/nifi/pull/10322#discussion_r2475614588
##########
nifi-extension-bundles/nifi-atlassian-bundle/nifi-atlassian-extensions/src/main/java/org/apache/nifi/atlassian/bitbucket/BitbucketRepositoryClient.java:
##########
@@ -299,13 +419,43 @@ public String createContent(final GitCreateContentRequest
request) throws FlowRe
String.format("Error while committing content for
repository [%s] on branch %s at path %s: %s", repoName, branch, resolvedPath,
getErrorMessage(response)));
}
- final Optional<String> lastCommit = getLatestCommit(branch,
resolvedPath);
+ return getRequiredLatestCommit(branch, resolvedPath);
+ }
- if (lastCommit.isEmpty()) {
- throw new FlowRegistryException(String.format("Could not find
commit for the file %s we just tried to commit on branch %s", resolvedPath,
branch));
+ private String createContentDataCenter(final GitCreateContentRequest
request, final String resolvedPath, final String branch) throws
FlowRegistryException {
+ final StandardMultipartFormDataStreamBuilder multipartBuilder = new
StandardMultipartFormDataStreamBuilder();
+ final String fileName = getFileName(resolvedPath);
+ multipartBuilder.addPart("content", fileName,
StandardHttpContentType.APPLICATION_OCTET_STREAM,
request.getContent().getBytes(StandardCharsets.UTF_8));
+ multipartBuilder.addPart("branch", StandardHttpContentType.TEXT_PLAIN,
branch.getBytes(StandardCharsets.UTF_8));
+
+ final String message = request.getMessage();
+ if (message != null && !message.isEmpty()) {
+ multipartBuilder.addPart("message",
StandardHttpContentType.TEXT_PLAIN, message.getBytes(StandardCharsets.UTF_8));
}
- return lastCommit.get();
+ final String existingContentSha = request.getExistingContentSha();
+ if (existingContentSha != null && !existingContentSha.isEmpty()) {
+ multipartBuilder.addPart("sourceCommitId",
StandardHttpContentType.TEXT_PLAIN,
existingContentSha.getBytes(StandardCharsets.UTF_8));
+ }
+
+ final HttpUriBuilder uriBuilder =
getRepositoryUriBuilder().addPathSegment("browse");
+ addPathSegments(uriBuilder, resolvedPath);
+ final URI uri = uriBuilder.build();
+ final byte[] requestBody = toByteArray(multipartBuilder.build());
+ final HttpResponseEntity response =
this.webClient.getWebClientService()
+ .put()
+ .uri(uri)
+ .body(new ByteArrayInputStream(requestBody),
OptionalLong.of(requestBody.length))
+ .header(AUTHORIZATION_HEADER, authToken.getAuthzHeaderValue())
+ .header(CONTENT_TYPE_HEADER,
multipartBuilder.getHttpContentType().getContentType())
+ .retrieve();
+
+ if (response.statusCode() != HttpURLConnection.HTTP_OK &&
response.statusCode() != HttpURLConnection.HTTP_CREATED) {
Review Comment:
Yes, it can be one or the other depending on potential existing content. I
updated the logic to make it easier to understand.
--
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]