From a2f436c6cb8fb74f2aa16bb13796ee9e62d7c3bb Mon Sep 17 00:00:00 2001 From: nqhoan-axonivy Date: Thu, 26 Dec 2024 15:36:18 +0700 Subject: [PATCH] If not define owner then ignore pr --- .../github/file/CodeOwnerFilesDetector.java | 2 +- .../github/file/GitHubMissingFilesDetector.java | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/github-repo-manager/src/main/java/com/axonivy/github/file/CodeOwnerFilesDetector.java b/github-repo-manager/src/main/java/com/axonivy/github/file/CodeOwnerFilesDetector.java index 974d346..869921e 100644 --- a/github-repo-manager/src/main/java/com/axonivy/github/file/CodeOwnerFilesDetector.java +++ b/github-repo-manager/src/main/java/com/axonivy/github/file/CodeOwnerFilesDetector.java @@ -31,7 +31,7 @@ protected byte[] loadReferenceFileContent(String repoURL) throws IOException { return String.format(CODE_OWNER_FORMAT, codeOwner.owner).getBytes(); } } - return new byte[0]; + return null; } private List getAllCodeOwners() throws IOException { diff --git a/github-repo-manager/src/main/java/com/axonivy/github/file/GitHubMissingFilesDetector.java b/github-repo-manager/src/main/java/com/axonivy/github/file/GitHubMissingFilesDetector.java index 192aae2..06613f8 100644 --- a/github-repo-manager/src/main/java/com/axonivy/github/file/GitHubMissingFilesDetector.java +++ b/github-repo-manager/src/main/java/com/axonivy/github/file/GitHubMissingFilesDetector.java @@ -82,7 +82,11 @@ private GHContent getFileContent(String path, GHRepository repo) { } private boolean hasSimilarContent(GHContent existingFile) throws IOException { - Reader targetContent = new CharSequenceReader(new String(loadReferenceFileContent(existingFile.getGitUrl()))); + var fileContent = loadReferenceFileContent(existingFile.getGitUrl()); + if (fileContent == null) { + return true; + } + Reader targetContent = new CharSequenceReader(new String(fileContent)); Reader actualContent; try (var inputStream = existingFile.read()) { actualContent = new CharSequenceReader(new String(inputStream.readAllBytes())); @@ -106,13 +110,17 @@ private void handleMissingFile(GHRepository repo) throws IOException { } private void addMissingFile(GHRepository repo) throws IOException { + var fileContent = loadReferenceFileContent(repo.getUrl().toString()); + if (fileContent == null) { + return; + } var defaultBranch = repo.getBranch(repo.getDefaultBranch()); String refURL = createBranchIfMissing(repo, BRANCH_PREFIX + reference.meta().branchName(), defaultBranch.getSHA1()); try { repo.createContent() .branch(refURL) .path(reference.meta().filePath()) - .content(loadReferenceFileContent(repo.getUrl().toString())) + .content(fileContent) .message(reference.meta().commitMessage()) .commit(); } catch (GHFileNotFoundException notFoundException) { @@ -181,6 +189,10 @@ private void handleOtherContent(GHRepository repo) throws IOException { } private void updateFile(GHRepository repo) throws IOException { + var fileContent = loadReferenceFileContent(repo.getUrl().toString()); + if (fileContent == null) { + return; + } var headBranch = repo.getBranch(repo.getDefaultBranch()); String refURL = createBranchIfMissing(repo, BRANCH_PREFIX + reference.meta().branchName(), headBranch.getSHA1()); repo.getFileContent(reference.meta().filePath(), refURL)