/* * Copyright 2020 EPAM Systems * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import React, { useEffect, useState } from "react"; import { Icons } from "@drill4j/ui-kit"; import tw from "twin.macro"; import { copyToClipboard, percentFormatter } from "@drill4j/common-utils"; import { ConditionSettingByType, Results } from "types/quality-gate-type"; import { useAdminConnection, useAgentRouteParams, useFilteredData } from "hooks"; import { KEY_METRICS_EVENT_NAMES, sendKeyMetricsEvent } from "common/analytic"; import { Metrics } from "types/metrics"; import { AnalyticsInfo } from "types"; import { QualityGateConfigurationUrl } from "./quality-gate-configuration-url"; import { getQualityGateConfigurationUrl } from "./get-quality-gate-configuration-url"; import { Condition } from "./condition"; interface Props { conditionSettingByType: ConditionSettingByType; results: Results; } export const QualityGateStatus = ({ conditionSettingByType, results }: Props) => { const [copied, setCopied] = useState(false); const { pluginId = "", agentId = "" } = useAgentRouteParams(); const { isAnalyticsDisabled } = useAdminConnection("/api/analytics/info") || {}; const { coverage = 0, risks: risksCount = 0, tests: testToRunCount = 0 } = useFilteredData("/data/stats") || {}; useEffect(() => { const timeout = setTimeout(() => setCopied(false), 5000); copied && timeout; return () => clearTimeout(timeout); }, [copied]); return ( <>
{conditionSettingByType.coverage?.enabled && (
{results.coverage ? "Passed" : "Failed"}. Your coverage is  {percentFormatter(coverage || 0)} %
)} {conditionSettingByType.risks?.enabled && (
{results.risks ? "Passed" : "Failed"}. You have  {risksCount}  not covered risk methods
)} {conditionSettingByType.tests?.enabled && (
{results.tests ? "Passed" : "Failed"}. You have  {testToRunCount}  not executed tests to run
)}
This is Quality Gate configuration for this build. Use this Curl in your command line to get JSON:
{copied ? (
Copied to clipboard.
) : ( { copyToClipboard(getQualityGateConfigurationUrl(agentId, pluginId)); setCopied(true); !isAnalyticsDisabled && sendKeyMetricsEvent({ name: KEY_METRICS_EVENT_NAMES.CLICK_ON_COPY_ICON_IN_QG_PANEL, }); }} /> )}
); };