pvillard31 commented on code in PR #11925:
URL: https://github.com/apache/nifi/pull/11925#discussion_r4592281324
##########
nifi-extension-bundles/nifi-github-bundle/nifi-github-extensions/src/main/java/org/apache/nifi/github/GitHubRepositoryClient.java:
##########
@@ -337,6 +338,53 @@ public List<GitCommit> getCommits(final String path, final
String branch) throws
});
}
+ /**
+ * Gets the SHA of the most recent commit that changed the given path on
the given branch with a single request.
+ * The default implementation lists a page of commits and resolves each
commit author, which costs an
+ * additional request per commit not already cached, while this value is
requested for every versioned
+ * Process Group on every synchronization with the registry.
+ *
+ * @param path the path
+ * @param branch the branch
+ * @return the SHA of the latest commit for the path, or empty when no
commit changed the path
+ *
+ * @throws IOException if an I/O error happens calling GitHub
+ * @throws FlowRegistryException if a non I/O error happens calling GitHub
+ */
+ @Override
+ public Optional<String> getLatestCommitSha(final String path, final String
branch) throws IOException, FlowRegistryException {
+ final String resolvedPath = getResolvedPath(path);
+ logger.debug("Getting latest commit for [{}] from branch [{}] in repo
[{}]", resolvedPath, branch, repository.getName());
+
+ return execute(() -> {
+ try {
+ return getLatestCommitSha(repository, resolvedPath, branch);
+ } catch (final FileNotFoundException fnf) {
+ throwPathOrBranchNotFound(fnf, resolvedPath,
BRANCH_REF_PATTERN.formatted(branch));
+ return null;
+ }
+ });
+ }
+
+ static Optional<String> getLatestCommitSha(final GHRepository repository,
final String resolvedPath, final String branch) throws IOException {
+ // The branch name is passed as the starting point of the listing, so
no separate request resolves the branch reference
+ final PagedIterator<GHCommit> commits = repository.queryCommits()
+ .path(resolvedPath)
+ .from(branch)
Review Comment:
GitHub resolves the sha parameter as any ref, so a tag or commit SHA with
this name now returns a commit, where the previous getRef("refs/heads/...")
threw "Path or Branch not found". Should we pass
BRANCH_REF_PATTERN.formatted(branch) here? GitHub accepts it and it keeps the
single request.
##########
nifi-extension-bundles/nifi-github-bundle/nifi-github-extensions/src/test/java/org/apache/nifi/github/GitHubRepositoryClientTest.java:
##########
@@ -84,4 +96,62 @@ void
testResolveCommitAuthorReturnsPlaceholderWhenNoAuthorAvailable() throws IOE
final String author =
GitHubRepositoryClient.resolveCommitAuthor(ghCommit, shortInfo);
assertEquals("unknown", author);
}
+
+ private static final String PATH = "bucket/flow.json";
Review Comment:
Could these constants move to the top of the class, with the other fields?
--
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]