< prev index next >

bots/mlbridge/src/main/java/org/openjdk/skara/bots/mlbridge/WebrevStorage.java

Print this page

 45     WebrevStorage(HostedRepository storage, String ref, Path baseFolder, URI baseUri, EmailAddress author) {
 46         this.baseFolder = baseFolder;
 47         this.baseUri = baseUri;
 48         this.storage = storage;
 49         storageRef = ref;
 50         this.author = author;
 51     }
 52 
 53     private void generate(PullRequestInstance prInstance, Path folder, Hash base, Hash head) throws IOException {
 54         Files.createDirectories(folder);
 55         Webrev.repository(prInstance.localRepo()).output(folder)
 56               .generate(base, head);
 57     }
 58 
 59     private void push(Repository localStorage, Path webrevFolder, String identifier) throws IOException {
 60         var batchIndex = new AtomicInteger();
 61         try (var files = Files.walk(webrevFolder)) {
 62             // Try to push 1000 files at a time
 63             var batches = files.filter(Files::isRegularFile)
 64                                .filter(file -> {
 65                                    // Huge files are not that useful in a webrev
 66                                    try {
 67                                        return Files.size(file) < 1000 * 1000;




 68                                    } catch (IOException e) {
 69                                        return false;
 70                                    }
 71                                })
 72                                .collect(Collectors.groupingBy(path -> {
 73                                    int curIndex = batchIndex.incrementAndGet();
 74                                    return Math.floorDiv(curIndex, 1000);
 75                                }));
 76 
 77             for (var batch : batches.entrySet()) {
 78                 localStorage.add(batch.getValue());
 79                 Hash hash;
 80                 var message = "Added webrev for " + identifier +
 81                         (batches.size() > 1 ? " (" + (batch.getKey() + 1) + "/" + batches.size() + ")" : "");
 82                 try {
 83                     hash = localStorage.commit(message, author.fullName().orElseThrow(), author.address());
 84                 } catch (IOException e) {
 85                     // If the commit fails, it probably means that we're resuming a partially completed previous update
 86                     // where some of the files have already been committed. Ignore it and continue.
 87                     continue;

 45     WebrevStorage(HostedRepository storage, String ref, Path baseFolder, URI baseUri, EmailAddress author) {
 46         this.baseFolder = baseFolder;
 47         this.baseUri = baseUri;
 48         this.storage = storage;
 49         storageRef = ref;
 50         this.author = author;
 51     }
 52 
 53     private void generate(PullRequestInstance prInstance, Path folder, Hash base, Hash head) throws IOException {
 54         Files.createDirectories(folder);
 55         Webrev.repository(prInstance.localRepo()).output(folder)
 56               .generate(base, head);
 57     }
 58 
 59     private void push(Repository localStorage, Path webrevFolder, String identifier) throws IOException {
 60         var batchIndex = new AtomicInteger();
 61         try (var files = Files.walk(webrevFolder)) {
 62             // Try to push 1000 files at a time
 63             var batches = files.filter(Files::isRegularFile)
 64                                .filter(file -> {
 65                                    // Huge files are not that useful in a webrev - but make an exception for the index
 66                                    try {
 67                                        if (file.getFileName().toString().equals("index.html")) {
 68                                            return true;
 69                                        } else {
 70                                            return Files.size(file) < 1000 * 1000;
 71                                        }
 72                                    } catch (IOException e) {
 73                                        return false;
 74                                    }
 75                                })
 76                                .collect(Collectors.groupingBy(path -> {
 77                                    int curIndex = batchIndex.incrementAndGet();
 78                                    return Math.floorDiv(curIndex, 1000);
 79                                }));
 80 
 81             for (var batch : batches.entrySet()) {
 82                 localStorage.add(batch.getValue());
 83                 Hash hash;
 84                 var message = "Added webrev for " + identifier +
 85                         (batches.size() > 1 ? " (" + (batch.getKey() + 1) + "/" + batches.size() + ")" : "");
 86                 try {
 87                     hash = localStorage.commit(message, author.fullName().orElseThrow(), author.address());
 88                 } catch (IOException e) {
 89                     // If the commit fails, it probably means that we're resuming a partially completed previous update
 90                     // where some of the files have already been committed. Ignore it and continue.
 91                     continue;
< prev index next >