Search in sources :

Example 6 with LicenseData

use of org.eclipse.dash.licenses.LicenseData in project dash-licenses by eclipse.

the class GitLabSupport method createReviews.

public void createReviews(List<LicenseData> needsReview, PrintWriter output) {
    execute(connection -> {
        var count = 0;
        for (LicenseData licenseData : needsReview) {
            if (count >= MAXIMUM_REVIEWS)
                break;
            count++;
            output.println(String.format("Setting up a review for %s.", licenseData.getId().toString()));
            if (!licenseData.getId().isValid()) {
                output.println(" - Don't know what to do with this.");
                continue;
            }
            Stream<ExtendedContentData> extendedData = dataService.findFor(licenseData.getId());
            /*
				 * Ideally, we need a way to "create if does not already exist" feature in the
				 * GitLab API. But since we don't have that, we'll leverage the expectation that
				 * concurrent requests to review the same content will be relatively rare (there
				 * is some risk that between asking if we have an existing issue for a review
				 * for a particular bit of content and creating a new one, that somebody else
				 * might be doing the same). Our expectation is that the potential additional
				 * churn on the backend should require significantly less effort than that
				 * required to prevent rare duplication.
				 */
            try {
                GitLabReview review = new GitLabReview(settings.getProjectId(), licenseData, extendedData);
                Issue existing = connection.findIssue(review);
                if (existing != null) {
                    output.println(String.format(" - Existing: %s", existing.getWebUrl()));
                    continue;
                }
                Issue created = connection.createIssue(review);
                if (created == null) {
                    output.println(" - An error occurred while attempting to create a review request");
                    // TODO If we break creating a review, then don't try to create any more.
                    break;
                }
                output.println(String.format(" - Created: %s", created.getWebUrl()));
                output.flush();
            } catch (GitLabApiException e) {
                throw new RuntimeException(e);
            }
        }
        if (count < needsReview.size()) {
            output.println();
            output.println("More content needs to be reviewed.");
            output.printf("For now, however, this experimental feature only submits the first %d.\n", count);
            output.println();
        }
    });
}
Also used : Issue(org.gitlab4j.api.models.Issue) LicenseData(org.eclipse.dash.licenses.LicenseData) GitLabApiException(org.gitlab4j.api.GitLabApiException) ExtendedContentData(org.eclipse.dash.licenses.extended.ExtendedContentData)

Aggregations

LicenseData (org.eclipse.dash.licenses.LicenseData)6 IContentId (org.eclipse.dash.licenses.IContentId)4 ExtendedContentData (org.eclipse.dash.licenses.extended.ExtendedContentData)2 GitLabApiException (org.gitlab4j.api.GitLabApiException)2 Issue (org.gitlab4j.api.models.Issue)2 Test (org.junit.jupiter.api.Test)2 Guice (com.google.inject.Guice)1 Injector (com.google.inject.Injector)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 StandardCharsets (java.nio.charset.StandardCharsets)1 MessageFormat (java.text.MessageFormat)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1