Search in sources :

Example 1 with Milestone

use of org.springframework.boot.build.bom.bomr.github.Milestone in project spring-boot by spring-projects.

the class UpgradeBom method upgradeDependencies.

@TaskAction
@SuppressWarnings("deprecation")
void upgradeDependencies() {
    GitHubRepository repository = createGitHub().getRepository(this.bom.getUpgrade().getGitHub().getOrganization(), this.bom.getUpgrade().getGitHub().getRepository());
    List<String> availableLabels = repository.getLabels();
    List<String> issueLabels = this.bom.getUpgrade().getGitHub().getIssueLabels();
    if (!availableLabels.containsAll(issueLabels)) {
        List<String> unknownLabels = new ArrayList<>(issueLabels);
        unknownLabels.removeAll(availableLabels);
        throw new InvalidUserDataException("Unknown label(s): " + StringUtils.collectionToCommaDelimitedString(unknownLabels));
    }
    Milestone milestone = determineMilestone(repository);
    List<Issue> existingUpgradeIssues = repository.findIssues(issueLabels, milestone);
    List<Upgrade> upgrades = new InteractiveUpgradeResolver(new MavenMetadataVersionResolver(this.repositoryUrls), this.bom.getUpgrade().getPolicy(), getServices().get(UserInputHandler.class)).resolveUpgrades(this.bom.getLibraries());
    Path buildFile = getProject().getBuildFile().toPath();
    Path gradleProperties = new File(getProject().getRootProject().getProjectDir(), "gradle.properties").toPath();
    UpgradeApplicator upgradeApplicator = new UpgradeApplicator(buildFile, gradleProperties);
    for (Upgrade upgrade : upgrades) {
        String title = "Upgrade to " + upgrade.getLibrary().getName() + " " + upgrade.getVersion();
        Issue existingUpgradeIssue = findExistingUpgradeIssue(existingUpgradeIssues, upgrade);
        if (existingUpgradeIssue != null) {
            System.out.println(title + " (supersedes #" + existingUpgradeIssue.getNumber() + " " + existingUpgradeIssue.getTitle() + ")");
        } else {
            System.out.println(title);
        }
        try {
            Path modified = upgradeApplicator.apply(upgrade);
            int issueNumber = repository.openIssue(title, (existingUpgradeIssue != null) ? "Supersedes #" + existingUpgradeIssue.getNumber() : "", issueLabels, milestone);
            if (existingUpgradeIssue != null) {
                existingUpgradeIssue.label(Arrays.asList("type: task", "status: superseded"));
            }
            if (new ProcessBuilder().command("git", "add", modified.toFile().getAbsolutePath()).start().waitFor() != 0) {
                throw new IllegalStateException("git add failed");
            }
            if (new ProcessBuilder().command("git", "commit", "-m", title + "\n\nCloses gh-" + issueNumber).start().waitFor() != 0) {
                throw new IllegalStateException("git commit failed");
            }
        } catch (IOException ex) {
            throw new TaskExecutionException(this, ex);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }
}
Also used : Path(java.nio.file.Path) Issue(org.springframework.boot.build.bom.bomr.github.Issue) Milestone(org.springframework.boot.build.bom.bomr.github.Milestone) ArrayList(java.util.ArrayList) IOException(java.io.IOException) GitHubRepository(org.springframework.boot.build.bom.bomr.github.GitHubRepository) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) InvalidUserDataException(org.gradle.api.InvalidUserDataException) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 TaskAction (org.gradle.api.tasks.TaskAction)1 TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)1 GitHubRepository (org.springframework.boot.build.bom.bomr.github.GitHubRepository)1 Issue (org.springframework.boot.build.bom.bomr.github.Issue)1 Milestone (org.springframework.boot.build.bom.bomr.github.Milestone)1