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

Iss #123 - Update status UI page to handle revalidation more intuitively

parent bd5af934
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@
<artifactId>git-eca</artifactId>
<version>1.1.0</version>
<properties>
<eclipse-api-version>0.6.10</eclipse-api-version>
<eclipse-api-version>0.7.1</eclipse-api-version>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>11</maven.compiler.source>
......@@ -14,7 +14,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>2.9.2.Final</quarkus.platform.version>
<quarkus.platform.version>2.14.2.Final</quarkus.platform.version>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
<auto-value.version>1.8.2</auto-value.version>
<org.mapstruct.version>1.4.1.Final</org.mapstruct.version>
......
......@@ -51,6 +51,13 @@ paths:
description: Error while retrieving data
/eca/status/{fingerprint}/ui:
parameters:
- name: fingerprint
in: path
description: Unique ID for the request group
required: true
schema:
type: string
get:
summary: Historic ECA validation status in a HTML format
description: Returns an HTMl page containing validation messages
......@@ -76,6 +83,67 @@ paths:
500:
description: Error while retrieving data
/webhooks/github:
post:
tags:
- Github validation processing
summary: Github incoming hook event processing
description: Process incoming pull request hook events from Github
parameters:
- in: header
name: X-GitHub-Delivery
schema:
type: string
required: true
- in: header
name: X-GitHub-Event
schema:
type: string
required: true
- in: header
name: X-GitHub-Hook-ID
schema:
type: string
required: true
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/GithubWebhookEvent"
responses:
200:
description: Success
500:
description: Error while processing data
/webhooks/github/revalidate/{fingerprint}:
parameters:
- name: fingerprint
in: path
description: Unique ID for the request group
required: true
schema:
type: string
post:
tags:
- Github validation processing
summary: Gitlab webhook revalidation request
description: Process incoming system hooks from GitLab
requestBody:
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/RevalidationRequest'
responses:
200:
description: Success
400:
description: Bad request
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
404:
description: Not found
/webhooks/gitlab/system:
post:
tags:
......@@ -429,6 +497,45 @@ components:
- "null"
description: the project deletion date if it was deleted
GithubWebhookEvent:
type: object
properties:
installation:
type: object
description: Information about the Github App installation making this request
properties:
id:
type: string
description: The ID of the app installation that is making the validation request on behalf of the repository/user.
repository:
type: object
description: Information about the repository that triggered this request
properties:
full_name:
type: string
description: The full name of the repository, including organization.
html_url:
type: string
description: The link to the repository the event was triggered by
pull_request:
type: object
description: Information on the pull request that triggered this workflow.
properties:
number:
type: int
description: The numeric ID of the pull request that triggered the flow
head:
type: object
properties:
sha:
type: string
description: The SHA hash of the head of the pull request.
RevalidationRequest:
type: object
properties:
h-form-captcha-response:
type: string
description: the hCaptcha challenge response.
Error:
type: object
properties:
......
/*********************************************************************
* Copyright (c) 2020 Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Author: Martin Lowe <martin.lowe@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipsefoundation.git.eca.model;
import java.net.URI;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.google.auto.value.AutoValue;
/**
* Basic object representing a revalidation location post request. This was done to better integrate with the UI which
* fails on CORS requests when attempting to use natural redirects in AJAX.
*
* @author Martin Lowe
*
*/
@AutoValue
@JsonDeserialize(builder = AutoValue_RevalidationResponse.Builder.class)
public abstract class RevalidationResponse {
public abstract URI getLocation();
public static Builder builder() {
return new AutoValue_RevalidationResponse.Builder();
}
@AutoValue.Builder
@JsonPOJOBuilder(withPrefix = "set")
public abstract static class Builder {
public abstract Builder setLocation(URI location);
public abstract RevalidationResponse build();
}
}
\ No newline at end of file
......@@ -26,7 +26,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RestClient;
......@@ -43,6 +42,7 @@ import org.eclipsefoundation.git.eca.helper.CaptchaHelper;
import org.eclipsefoundation.git.eca.helper.JwtHelper;
import org.eclipsefoundation.git.eca.model.Commit;
import org.eclipsefoundation.git.eca.model.GitUser;
import org.eclipsefoundation.git.eca.model.RevalidationResponse;
import org.eclipsefoundation.git.eca.model.ValidationRequest;
import org.eclipsefoundation.git.eca.model.ValidationResponse;
import org.eclipsefoundation.git.eca.namespace.GitEcaParameterNames;
......@@ -170,8 +170,8 @@ public class GithubWebhooksResource {
sb.append(tracking.getRepositoryFullName());
sb.append("/pull/");
sb.append(tracking.getPullRequestNumber());
// redirect to the pull request page on successful trigger of the webhook
return Response.status(Status.FOUND).location(URI.create(sb.toString())).build();
// respond with a URL to the new location in a standard request
return Response.ok(RevalidationResponse.builder().setLocation(URI.create(sb.toString())).build()).build();
}
/**
......
{#include eclipse_header /}
{#include eclipse_header}
{#title}Git ECA Validation{/}
{/include}
{#include eclipse_breadcrumb /}
{|<style>
.panel.list-group>div {
......@@ -140,7 +142,7 @@
{/if}
{#if statuses.0.provider == ProviderType:GITHUB}
<div>
<form action="/git/webhooks/github/revalidate/{fingerprint}" method="POST">
<form id="git-eca-hook-revalidation" data-request-id="{fingerprint}">
<div class="captcha">
<div class="h-captcha" data-sitekey="{config:['eclipse.hcaptcha.sitekey']}"></div>
</div>
......@@ -218,8 +220,10 @@
$newToast.fadeOut("slow");
}, 10000);
}
// set up accordion
$('#accordion').on('hidden.bs.collapse', toggleIcon);
$('#accordion').on('shown.bs.collapse', toggleIcon);
// bind to ECA status lookup submit
document.getElementById("eclipse-eca-lookup-form").addEventListener("submit", function (e) {
// don't submit the form as we will handle it w/ ajax
e.preventDefault();
......@@ -250,6 +254,40 @@
}
});
});
// Revalidation button binding
const revalidationForm = document.getElementById("git-eca-hook-revalidation");
if (revalidationForm !== null) {
revalidationForm.addEventListener("submit", function (e) {
// don't submit the form as we will handle it w/ ajax
e.preventDefault();
// grab the constants from the form and perform a check
const $form = $(e.target);
const $submitButton = $form.find('button');
// disable the button so that requests won't be spammed
$submitButton.attr("disabled", "disabled");
// use ajax to revalidate the commit with GH
$.ajax({
url: `/git/webhooks/github/revalidate/${$form.data('request-id')}`,
data: $form.serialize(),
type: 'POST',
success: function (data) {
toast(`Revalidation complete! Forwarding to pull request.`, 'success');
setTimeout(() => {
window.location.replace(data.location);
}, '2500');
},
error: function (xhr) {
const json = JSON.parse(xhr.responseText);
console.log('Error encountered while revalidating: ' + json.message);
toast(json.message, 'danger');
},
complete: function () {
$submitButton.removeAttr("disabled");
}
});
});
}
});
</script>|}
......
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