diff --git a/.github/workflows/build-hub.yaml b/.github/workflows/build-hub.yaml index 155b17a..5ae846d 100644 --- a/.github/workflows/build-hub.yaml +++ b/.github/workflows/build-hub.yaml @@ -58,11 +58,6 @@ jobs: echo "Flags: ${{ steps.buildx.outputs.flags }}" echo "Platforms: ${{ steps.buildx.outputs.platforms }}" - - name: Build Workflows Client (required, not yet in Maven Central) - run: | - cd workflows - mvn install -Dmaven.javadoc.skip=true --no-transfer-progress -DtrimStackTrace=false - - name: Build Apicurio API Lifecycle Hub run: | cd hub diff --git a/hub/app/pom.xml b/hub/app/pom.xml index 04afce6..7a7e445 100644 --- a/hub/app/pom.xml +++ b/hub/app/pom.xml @@ -14,6 +14,13 @@ apicurio-api-lifecycle-hub-app + + + io.apicurio + apicurio-api-lifecycle-hub-clients + ${project.version} + + io.apicurio @@ -36,13 +43,6 @@ ${apicurio-common-app-components.version} - - - io.apicurio - apicurio-api-lifecycle-workflows-client - ${apicurio-api-lifecycle-workflows.version} - - io.quarkus @@ -96,12 +96,6 @@ junit-jupiter-params test - - io.apicurio - apicurio-api-lifecycle-hub-client - ${project.version} - test - diff --git a/hub/app/src/main/java/io/apicurio/lifecycle/rest/clients/LifecycleWorkflowsClientProducer.java b/hub/app/src/main/java/io/apicurio/lifecycle/rest/clients/LifecycleWorkflowsClientProducer.java index 8229733..8416a83 100644 --- a/hub/app/src/main/java/io/apicurio/lifecycle/rest/clients/LifecycleWorkflowsClientProducer.java +++ b/hub/app/src/main/java/io/apicurio/lifecycle/rest/clients/LifecycleWorkflowsClientProducer.java @@ -5,7 +5,7 @@ import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider; import com.microsoft.kiota.http.OkHttpRequestAdapter; -import io.apicurio.lifecycle.workflows.rest.client.LifecycleWorkflowsClient; +import io.apicurio.lifecycle.rest.clients.workflows.LifecycleWorkflowsClient; import jakarta.annotation.PostConstruct; import jakarta.enterprise.context.ApplicationScoped; import jakarta.enterprise.inject.Produces; diff --git a/hub/app/src/main/java/io/apicurio/lifecycle/rest/v0/impl/ApisResourceImpl.java b/hub/app/src/main/java/io/apicurio/lifecycle/rest/v0/impl/ApisResourceImpl.java index 013d02b..2bde43b 100644 --- a/hub/app/src/main/java/io/apicurio/lifecycle/rest/v0/impl/ApisResourceImpl.java +++ b/hub/app/src/main/java/io/apicurio/lifecycle/rest/v0/impl/ApisResourceImpl.java @@ -25,6 +25,9 @@ import org.slf4j.Logger; import io.apicurio.common.apps.content.IoUtil; +import io.apicurio.lifecycle.rest.clients.workflows.LifecycleWorkflowsClient; +import io.apicurio.lifecycle.rest.clients.workflows.models.Event; +import io.apicurio.lifecycle.rest.clients.workflows.models.EventContext; import io.apicurio.lifecycle.rest.v0.ApisResource; import io.apicurio.lifecycle.rest.v0.beans.Api; import io.apicurio.lifecycle.rest.v0.beans.ApiSearchResults; @@ -45,15 +48,12 @@ import io.apicurio.lifecycle.storage.dtos.UpdateVersionContentDto; import io.apicurio.lifecycle.storage.dtos.VersionContentDto; import io.apicurio.lifecycle.storage.dtos.VersionSearchResultsDto; -import io.apicurio.lifecycle.workflows.rest.client.LifecycleWorkflowsClient; -import io.apicurio.lifecycle.workflows.rest.client.models.Event; -import io.apicurio.lifecycle.workflows.rest.client.models.EventContext; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; +import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.constraints.NotNull; -import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Context; -import jakarta.servlet.http.HttpServletRequest; +import jakarta.ws.rs.core.Response; /** * @author eric.wittmann@gmail.com @@ -145,11 +145,15 @@ public void createVersion(String apiId, @NotNull NewVersion data) { storage.createVersion(apiId, ToDto.newVersion(data)); // Fire event (trigger workflow) + String workflow = "default"; + if (data.getWorkflow() != null && data.getWorkflow().trim().length() > 0) { + workflow = data.getWorkflow(); + } Event event = new Event(); event.setType("version:create"); event.setId(UUID.randomUUID().toString()); event.setContext(new EventContext()); - event.getContext().setAdditionalData(Map.of("apiId", apiId, "version", data.getVersion())); + event.getContext().setAdditionalData(Map.of("apiId", apiId, "version", data.getVersion(), "workflow", workflow)); workflowsClient.events().post(event); } diff --git a/hub/app/src/main/resources/META-INF/openapi.json b/hub/app/src/main/resources/META-INF/openapi.json index 5cf197d..1167a44 100644 --- a/hub/app/src/main/resources/META-INF/openapi.json +++ b/hub/app/src/main/resources/META-INF/openapi.json @@ -1118,6 +1118,10 @@ "content": { "$ref": "#/components/schemas/NewContent", "description": "" + }, + "workflow": { + "description": "", + "type": "string" } }, "example": { diff --git a/hub/app/src/main/resources/application.properties b/hub/app/src/main/resources/application.properties index c1dba16..2c55a0d 100644 --- a/hub/app/src/main/resources/application.properties +++ b/hub/app/src/main/resources/application.properties @@ -73,3 +73,6 @@ app.description=${alh.description} app.version=${alh.version} app.date=${alh.date} +quarkus.http.test-port=7071 + + diff --git a/hub/app/src/test/java/io/apicurio/lifecycle/rest/AbstractResourceTest.java b/hub/app/src/test/java/io/apicurio/lifecycle/rest/AbstractResourceTest.java index 0d48b91..5db879f 100644 --- a/hub/app/src/test/java/io/apicurio/lifecycle/rest/AbstractResourceTest.java +++ b/hub/app/src/test/java/io/apicurio/lifecycle/rest/AbstractResourceTest.java @@ -21,7 +21,7 @@ import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider; import com.microsoft.kiota.http.OkHttpRequestAdapter; -import io.apicurio.lifecycle.rest.client.LifecycleHubClient; +import io.apicurio.lifecycle.rest.clients.self.LifecycleHubClient; /** * @author eric.wittmann@gmail.com diff --git a/hub/app/src/test/java/io/apicurio/lifecycle/rest/ApisResourceTest.java b/hub/app/src/test/java/io/apicurio/lifecycle/rest/ApisResourceTest.java index 66983e3..40067d9 100644 --- a/hub/app/src/test/java/io/apicurio/lifecycle/rest/ApisResourceTest.java +++ b/hub/app/src/test/java/io/apicurio/lifecycle/rest/ApisResourceTest.java @@ -24,16 +24,16 @@ import org.junit.jupiter.api.Test; import io.apicurio.common.apps.content.IoUtil; -import io.apicurio.lifecycle.rest.client.models.Api; -import io.apicurio.lifecycle.rest.client.models.ApiType; -import io.apicurio.lifecycle.rest.client.models.Labels; -import io.apicurio.lifecycle.rest.client.models.NewApi; -import io.apicurio.lifecycle.rest.client.models.NewContent; -import io.apicurio.lifecycle.rest.client.models.NewVersion; -import io.apicurio.lifecycle.rest.client.models.UpdateApi; -import io.apicurio.lifecycle.rest.client.models.UpdateVersion; -import io.apicurio.lifecycle.rest.client.models.Version; -import io.apicurio.lifecycle.rest.client.models.VersionSearchResults; +import io.apicurio.lifecycle.rest.clients.self.models.Api; +import io.apicurio.lifecycle.rest.clients.self.models.ApiType; +import io.apicurio.lifecycle.rest.clients.self.models.Labels; +import io.apicurio.lifecycle.rest.clients.self.models.NewApi; +import io.apicurio.lifecycle.rest.clients.self.models.NewContent; +import io.apicurio.lifecycle.rest.clients.self.models.NewVersion; +import io.apicurio.lifecycle.rest.clients.self.models.UpdateApi; +import io.apicurio.lifecycle.rest.clients.self.models.UpdateVersion; +import io.apicurio.lifecycle.rest.clients.self.models.Version; +import io.apicurio.lifecycle.rest.clients.self.models.VersionSearchResults; import io.quarkus.test.junit.QuarkusTest; /** diff --git a/hub/app/src/test/java/io/apicurio/lifecycle/rest/SystemResourceTest.java b/hub/app/src/test/java/io/apicurio/lifecycle/rest/SystemResourceTest.java index 2237f62..6fc5750 100644 --- a/hub/app/src/test/java/io/apicurio/lifecycle/rest/SystemResourceTest.java +++ b/hub/app/src/test/java/io/apicurio/lifecycle/rest/SystemResourceTest.java @@ -19,7 +19,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import io.apicurio.lifecycle.rest.client.models.SystemInfo; +import io.apicurio.lifecycle.rest.clients.self.models.SystemInfo; import io.quarkus.test.junit.QuarkusTest; /** diff --git a/hub/client/pom.xml b/hub/clients/pom.xml similarity index 77% rename from hub/client/pom.xml rename to hub/clients/pom.xml index a91a32b..d9653de 100644 --- a/hub/client/pom.xml +++ b/hub/clients/pom.xml @@ -8,9 +8,9 @@ 0.1.0-SNAPSHOT ../pom.xml - apicurio-api-lifecycle-hub-client + apicurio-api-lifecycle-hub-clients jar - apicurio-api-lifecycle-hub-client + apicurio-api-lifecycle-hub-clients 0.7.8 @@ -64,16 +64,28 @@ 0.0.7 + self generate + + ../app/src/main/resources/META-INF/openapi.json + io.apicurio.lifecycle.rest.clients.self + LifecycleHubClient + + + + workflows + + generate + + + ../../workflows/app/src/main/resources/META-INF/openapi.json + io.apicurio.lifecycle.rest.clients.workflows + LifecycleWorkflowsClient + - - ../app/src/main/resources/META-INF/openapi.json - io.apicurio.lifecycle.rest.client - LifecycleHubClient - org.codehaus.mojo diff --git a/hub/pom.xml b/hub/pom.xml index 0a7240c..e268787 100644 --- a/hub/pom.xml +++ b/hub/pom.xml @@ -51,7 +51,7 @@ app - client + clients dist/docker diff --git a/ui/public/workflow_default.bpmn b/ui/public/workflow_default.bpmn index 0640114..dad04d2 100644 --- a/ui/public/workflow_default.bpmn +++ b/ui/public/workflow_default.bpmn @@ -1,6 +1,10 @@ - - + + + + + + @@ -10,19 +14,30 @@ toAddWorkflowLabels + + + toAddWorkflowLabels fromAddWorkflowLabelToValidate + + + toValidate toMicrocks - + + + toMicrocks fromMicrocksToCatchEvent + + + fromApprovalGatewayToRegistry toEnd @@ -36,7 +51,10 @@ API ${apiId} (version ${version}) is ready to register. Do you approve? - + + + + toApproval toApprovalGateway @@ -68,10 +86,10 @@ - ${approval == false} + ${approved == false} - ${approval == true} + ${approved == true} fromAddWorkflowLabelToValidate @@ -89,6 +107,7 @@ + fromCatchEventGatewayToSetReadOnlyTrue toApproval @@ -97,6 +116,7 @@ + fromApprovalGatewayToSetReadOnlyFalse fromSetReadOnlyFalseToCatchEvent diff --git a/ui/public/workflow_github.bpmn b/ui/public/workflow_github.bpmn new file mode 100644 index 0000000..e575c17 --- /dev/null +++ b/ui/public/workflow_github.bpmn @@ -0,0 +1,315 @@ + + + + + + + + + + + + + + toFetchContent + + + + + + toAddWorkflowLabels + fromAddWorkflowLabelToCatchEvent + + + + + + toMicrocks + fromMicrocksToCatchEvent + + + + + + fromApprovalGatewayToRegistry + toImplementAPI + + + toCatchEvent + toCatchEventGateway + + + + + API ${apiId} (version ${version}) is ready to register. Do you approve? + + + + + + + + toApproval + toApprovalGateway + + + toCatchEventGateway + fromCatchEventGatewayToSetReadOnlyTrue + fromCatchEventGatewayToOpenPR + + + toApprovalGateway + fromApprovalGatewayToSetReadOnlyFalse + fromApprovalGatewayToRegistry + + + toEnd + + + + + ${eventType == 'done'} + + + + ${approved == false} + + + ${approved == true} + + + fromAddWorkflowLabelToCatchEvent + fromMicrocksToCatchEvent + fromSetReadOnlyFalseToCatchEvent + toCatchEvent + + + + + + + + fromCatchEventGatewayToSetReadOnlyTrue + toApproval + + + + + + + fromApprovalGatewayToSetReadOnlyFalse + fromSetReadOnlyFalseToCatchEvent + + + + + + + + fromCatchEventGatewayToOpenPR + toMicrocks + + + ${eventType == 'change'} + + + + + + + + + toMarkPR + toEnd + + + + API ${apiId} (version ${version}) is ready to register. Do you approve? + + toImplementAPI + toMarkPR + + + + + + + + + + toFetchContent + toAddWorkflowLabels + + + API Created + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ui/src/app/components/apiDetails/CreateVersionModal.tsx b/ui/src/app/components/apiDetails/CreateVersionModal.tsx index 8b6567e..ab77955 100644 --- a/ui/src/app/components/apiDetails/CreateVersionModal.tsx +++ b/ui/src/app/components/apiDetails/CreateVersionModal.tsx @@ -1,7 +1,7 @@ import { FunctionComponent, useEffect, useState } from "react"; import { Button, Form, FormGroup, Modal, ModalVariant, TextArea, TextInput } from "@patternfly/react-core"; import { NewContent_source, NewVersion } from "@client/hub/models"; -import { ObjectSelect } from "@apicurio/common-ui-components"; +import { If, ObjectSelect } from "@apicurio/common-ui-components"; const EMPTY_CONTENT: string = `{ "openapi": "3.0.2", @@ -25,8 +25,10 @@ export type CreateVersionModalProps = { export const CreateVersionModal: FunctionComponent = (props: CreateVersionModalProps) => { const [version, setVersion] = useState(""); const [description, setDescription] = useState(""); + const [workflow, setWorkflow] = useState("Default"); const [contentType, setContentType] = useState("application/json"); const [content, setContent] = useState(EMPTY_CONTENT); + const [url, setUrl] = useState(""); const [isValid, setIsValid] = useState(false); useEffect(() => { @@ -40,8 +42,18 @@ export const CreateVersionModal: FunctionComponent = (p }, [props.isOpen]); useEffect(() => { - setIsValid(version.trim().length > 0 && content.trim().length > 0); - }, [version, description]); + let valid: boolean = true; + if (version.trim().length === 0) { + valid = false; + } + if (workflow === "GitHub" && url.trim().length === 0) { + valid = false; + } + if (workflow === "Default" && content.trim().length === 0) { + valid = false; + } + setIsValid(valid); + }, [version, description, content, url, workflow]); const onCreate = (): void => { const data: NewVersion = { @@ -51,8 +63,16 @@ export const CreateVersionModal: FunctionComponent = (p source: NewContent_source.INLINE, contentType, content - } + }, + workflow: workflow.toLowerCase() }; + if (workflow === "GitHub") { + data.labels = { + additionalData: { + "github:url": url + } + }; + } props.onCreate(data); }; @@ -107,26 +127,42 @@ export const CreateVersionModal: FunctionComponent = (p {}} + items={["Default", "GitHub"]} + onSelect={setWorkflow} itemToTestId={item => `select-version-workflow-item-${item}`} itemToString={item => item} /> - -