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();
}
});
}
Aggregations