|
28 | 28 | import org.openrewrite.SourceFile; |
29 | 29 | import org.openrewrite.shaded.jgit.api.CreateBranchCommand; |
30 | 30 | import org.openrewrite.shaded.jgit.api.Git; |
| 31 | +import org.openrewrite.shaded.jgit.api.ListBranchCommand; |
31 | 32 | import org.openrewrite.shaded.jgit.api.ResetCommand; |
32 | 33 | import org.openrewrite.shaded.jgit.api.errors.GitAPIException; |
33 | 34 | import org.openrewrite.shaded.jgit.lib.Ref; |
@@ -160,10 +161,11 @@ void loop() throws IOException, GitAPIException { |
160 | 161 |
|
161 | 162 | if(versionToRecipeMap.containsKey(currentBootVersion)) { |
162 | 163 | String newBootVersion = calculateNextBootVersion(currentBootVersion); |
| 164 | + log.info("Found migration path to Spring Boot %s".formatted(newBootVersion)); |
163 | 165 | String branchName = calculateBranchName(newBootVersion); |
164 | 166 | Git git = Git.open(baseDir.resolve(".git").toFile()); |
165 | 167 | if(branchExists(git, branchName)) { |
166 | | - log.info("Found open branch: " + branchName); |
| 168 | + log.info("There might be an open PR? Otherwise please delete this remote branch: " + branchName); |
167 | 169 | return; |
168 | 170 | } |
169 | 171 | // find recipe name |
@@ -195,7 +197,11 @@ private boolean branchExists(Git git, String branchName) { |
195 | 197 | try { |
196 | 198 | git.fetch().call(); |
197 | 199 | // FIXME: This works only in this example. origin could be different |
198 | | - return git.branchList().call().stream().anyMatch(b -> "remotes/origin/%s".formatted(branchName).equals(b.getName())); |
| 200 | + return git.branchList() |
| 201 | + .setListMode(ListBranchCommand.ListMode.REMOTE) |
| 202 | + .call() |
| 203 | + .stream() |
| 204 | + .anyMatch(b -> "refs/remotes/origin/%s".formatted(branchName).equals(b.getName())); |
199 | 205 | } catch (GitAPIException e) { |
200 | 206 | throw new RuntimeException(e); |
201 | 207 | } |
@@ -314,6 +320,7 @@ private GHPullRequest createPullRequest(String ghToken, String name, String head |
314 | 320 |
|
315 | 321 | private void applyRecipe(ProjectResourceSet projectResourceSet, List<Recipe> recipes) { |
316 | 322 | // FIXME: If recipes is a list they need to be provided through Recipe.getRecipeList() to not require a new parse |
| 323 | + log.info("Applying recipes %s".formatted(recipes.stream().map(Recipe::getDisplayName).toList())); |
317 | 324 | if(recipes.size() > 1) throw new UnsupportedOperationException("Can only handle single recipes."); |
318 | 325 | recipes.forEach(r -> this.applyRecipe(projectResourceSet, r)); |
319 | 326 | } |
|
0 commit comments