cmccabe commented on code in PR #17684:
URL: https://github.com/apache/kafka/pull/17684#discussion_r1829719740


##########
generator/src/main/java/org/apache/kafka/message/checker/CheckerUtils.java:
##########
@@ -91,4 +102,54 @@ static MessageSpec readMessageSpecFromFile(String 
schemaPath) {
             throw new RuntimeException("Unable to parse file as MessageSpec: " 
+ schemaPath, e);
         }
     }
+
+    /**
+     * Return a MessageSpec file give file contents.
+     *
+     * @param contents      The path to read the file from.
+     * @return              The MessageSpec.
+     */
+    static MessageSpec readMessageSpecFromString(String contents) {
+        try {
+            File tempFile = new File("temp.txt");
+            tempFile.createNewFile();
+            Files.write(Paths.get("temp.txt"), contents.getBytes());
+            MessageSpec messageSpec = 
MessageGenerator.JSON_SERDE.readValue(tempFile, MessageSpec.class);
+            tempFile.deleteOnExit();
+            return messageSpec;
+        } catch (Exception e) {
+            throw new RuntimeException("Unable to parse file as MessageSpec: " 
+ contents, e);
+        }
+    }
+
+
+    /**
+     * Read a MessageSpec file from remote git repo.
+     *
+     * @param fileCheckMetadata    The file to read from remote git repo.
+     * @return                     The file contents.
+     */
+    static String GetDataFromGit(String fileCheckMetadata) throws IOException {
+        String gitPath = 
String.valueOf(Paths.get("").toAbsolutePath()).replaceFirst("/generator", "");
+        Git git = Git.open(new File(gitPath + "/.git"));
+        Repository repository = git.getRepository();
+        Ref head = 
git.getRepository().getRefDatabase().firstExactRef("refs/heads/trunk");
+
+        try (RevWalk revWalk = new RevWalk(repository)) {
+            RevCommit commit = revWalk.parseCommit(head.getObjectId());
+            RevTree tree = commit.getTree();
+            try (TreeWalk treeWalk = new TreeWalk(repository)) {
+                treeWalk.addTree(tree);
+                treeWalk.setRecursive(true);
+                
treeWalk.setFilter(PathFilter.create(String.valueOf(Paths.get("metadata/src/main/resources/common/metadata/"
 + fileCheckMetadata))));

Review Comment:
   please use a constant for `metadata/src/main/resources/common/metadata`



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to