Skip to content
Snippets Groups Projects
Commit 195ca532 authored by Martin Lowe's avatar Martin Lowe :flag_ca:
Browse files

feat(ui): Add last validation time, disable revalidation if PR not open

In the status UI, previously we never stated when the last validation
occurred. As we have access to this data, we should tell the user when
the last validation of a commit associated with a PR happened. This
better supports users to know if their failure may be due to out of date
validation.

Additionally, in the case of GH PRs where we have logic to manage those
calls separately, we can now check if the PR is open. We use this to now
toggle whether the revalidation button will be usable and whether the
hCaptcha is injected.
parent 6e45fd09
No related branches found
No related tags found
1 merge request!219feat(ui): Add last validation time, disable revalidation if PR not open
Pipeline #68237 passed
......@@ -11,6 +11,7 @@
**********************************************************************/
package org.eclipsefoundation.git.eca.config;
import java.time.format.DateTimeFormatter;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
......@@ -49,6 +50,24 @@ public class EclipseQuteTemplateExtensions {
return statuses.stream().flatMap(s -> s.getErrors().stream()).toList();
}
/**
* Formats and flattens a list of statuses to a list of errors encountered while validation a set of commits.
*
* @param statuses a list of commit validation statuses to retrieve errors from
* @return a list of flattened errors, or an empty list if (none are found.
*/
static String getLastKnownValidationTime(List<CommitValidationStatus> statuses) {
CommitValidationStatus latestStatus = statuses
.stream()
.sorted((o1, o2) -> o1.getLastModified().compareTo(o2.getLastModified()))
.findFirst()
.orElse(null);
if (latestStatus == null) {
return "Unknown";
}
return latestStatus.getLastModified().format(DateTimeFormatter.RFC_1123_DATE_TIME);
}
/**
* Converts the status list to a list of email addresses that were associated with validated commits.
*
......
......@@ -12,9 +12,11 @@
package org.eclipsefoundation.git.eca.resource;
import java.util.List;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.eclipsefoundation.efservices.api.models.Project;
import org.eclipsefoundation.git.eca.api.models.GithubWebhookRequest.PullRequest;
import org.eclipsefoundation.git.eca.config.EclipseQuteTemplateExtensions;
import org.eclipsefoundation.git.eca.dto.CommitValidationStatus;
import org.eclipsefoundation.git.eca.helper.GithubValidationHelper;
......@@ -187,7 +189,13 @@ public class StatusResource extends CommonResource {
// retrieve the status of the commits to display on the status page
statuses = validationStatus.getHistoricValidationStatusByShas(wrapper, r.getCommits().keySet().stream().toList());
}
// fetch the PR so we can indicate whether it's closed, open, or merged
String lastKnownStatus = "unknown";
Optional<PullRequest> pr = ghAppService.getPullRequest(installationId, org, repoName, prNo);
if (pr.isPresent()) {
lastKnownStatus = pr.get().getState();
}
// get projects for use in queries + UI
List<Project> ps = projects.retrieveProjectsForRepoURL(repoUrl, ProviderType.GITHUB);
// render and return the status UI
......@@ -203,6 +211,7 @@ public class StatusResource extends CommonResource {
.data("installationId", installationId)
.data("currentUser", getUserForLoggedInAccount())
.data("redirectUri", info.getPath())
.data("lastKnownStatus", lastKnownStatus)
.render())
.build();
} catch (BadRequestException e) {
......
......@@ -76,6 +76,9 @@
<strong>Pull request:</strong> <a class="underline" href="https://github.com/{orgName}/{repoName}/pull/{pullRequestNumber}" target="_blank" >#{pullRequestNumber}</a>
</li>
{/if}
<li><strong>Last Validation Time:</strong>
{statuses.getLastKnownValidationTime}
</li>
</ul>
<a href="{repoUrl}" target="_blank" rel="noopener" class="btn btn-primary margin-top-10">Project repository</a>
</div>
......@@ -163,13 +166,18 @@
</div>
{/if}
{#if statuses.0.provider == ProviderType:GITHUB && pullRequestNumber != null && repoName != null && orgName != null}
<div>
<div data-state="{lastKnownStatus}">
{#if lastKnownStatus ne null && lastKnownStatus ne 'open'}
<button class="btn-success margin-top-10 btn form-submit" type="submit" disabled>Revalidate</button>
<p class="small">Revalidation is disabled as the Pull Request is in a non-open state</p>
{#else}
<form id="git-eca-hook-revalidation" data-request-number="{pullRequestNumber}" data-request-repo="{repoName}" data-request-org="{orgName}" data-request-installation="{installationId}">
<div class="captcha">
<div class="h-captcha" data-sitekey="{config:['eclipse.hcaptcha.site-key']}"></div>
</div>
<button class="btn-success margin-top-10 btn form-submit" type="submit">Revalidate</button>
<button class="btn-success margin-top-10 btn form-submit" type="submit" { lastKnownStatus ne null && lastKnownStatus ne 'open' ? 'disabled' : '' }>Revalidate</button>
</form>
{/if}
</div>
{/if}
</section>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment