@backstage-community/plugin-code-coverage 0.2.28 → 0.2.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/api.esm.js +48 -0
- package/dist/api.esm.js.map +1 -0
- package/dist/components/CodeCoveragePage/CodeCoveragePage.esm.js +11 -0
- package/dist/components/CodeCoveragePage/CodeCoveragePage.esm.js.map +1 -0
- package/dist/components/CoverageHistoryChart/CoverageHistoryChart.esm.js +112 -0
- package/dist/components/CoverageHistoryChart/CoverageHistoryChart.esm.js.map +1 -0
- package/dist/components/FileExplorer/CodeRow.esm.js +78 -0
- package/dist/components/FileExplorer/CodeRow.esm.js.map +1 -0
- package/dist/components/FileExplorer/FileContent.esm.js +89 -0
- package/dist/components/FileExplorer/FileContent.esm.js.map +1 -0
- package/dist/components/FileExplorer/FileExplorer.esm.js +239 -0
- package/dist/components/FileExplorer/FileExplorer.esm.js.map +1 -0
- package/dist/components/FileExplorer/Highlighter.esm.js +30 -0
- package/dist/components/FileExplorer/Highlighter.esm.js.map +1 -0
- package/dist/components/Router.esm.js +17 -0
- package/dist/components/Router.esm.js.map +1 -0
- package/dist/index.esm.js +3 -618
- package/dist/index.esm.js.map +1 -1
- package/dist/plugin.esm.js +27 -0
- package/dist/plugin.esm.js.map +1 -0
- package/dist/routes.esm.js +8 -0
- package/dist/routes.esm.js.map +1 -0
- package/package.json +14 -9
package/CHANGELOG.md
CHANGED
package/dist/api.esm.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { stringifyEntityRef } from '@backstage/catalog-model';
|
|
2
|
+
import { ResponseError } from '@backstage/errors';
|
|
3
|
+
import { createApiRef } from '@backstage/core-plugin-api';
|
|
4
|
+
|
|
5
|
+
const codeCoverageApiRef = createApiRef({
|
|
6
|
+
id: "plugin.code-coverage.service"
|
|
7
|
+
});
|
|
8
|
+
class CodeCoverageRestApi {
|
|
9
|
+
discoveryApi;
|
|
10
|
+
fetchApi;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.discoveryApi = options.discoveryApi;
|
|
13
|
+
this.fetchApi = options.fetchApi;
|
|
14
|
+
}
|
|
15
|
+
async fetch(path) {
|
|
16
|
+
const url = await this.discoveryApi.getBaseUrl("code-coverage");
|
|
17
|
+
const resp = await this.fetchApi.fetch(`${url}${path}`);
|
|
18
|
+
if (!resp.ok) {
|
|
19
|
+
throw await ResponseError.fromResponse(resp);
|
|
20
|
+
}
|
|
21
|
+
if (resp.headers.get("content-type")?.includes("application/json")) {
|
|
22
|
+
return await resp.json();
|
|
23
|
+
}
|
|
24
|
+
return await resp.text();
|
|
25
|
+
}
|
|
26
|
+
async getCoverageForEntity(entityName) {
|
|
27
|
+
const entity = encodeURIComponent(stringifyEntityRef(entityName));
|
|
28
|
+
return await this.fetch(
|
|
29
|
+
`/report?entity=${entity}`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
async getFileContentFromEntity(entityName, filePath) {
|
|
33
|
+
const entity = encodeURIComponent(stringifyEntityRef(entityName));
|
|
34
|
+
return await this.fetch(
|
|
35
|
+
`/file-content?entity=${entity}&path=${encodeURI(filePath)}`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
async getCoverageHistoryForEntity(entityName, limit) {
|
|
39
|
+
const entity = encodeURIComponent(stringifyEntityRef(entityName));
|
|
40
|
+
const hasValidLimit = limit && limit > 0;
|
|
41
|
+
return await this.fetch(
|
|
42
|
+
`/history?entity=${entity}${hasValidLimit ? `&limit=${encodeURIComponent(String(limit))}` : ""}`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { CodeCoverageRestApi, codeCoverageApiRef };
|
|
48
|
+
//# sourceMappingURL=api.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.esm.js","sources":["../src/api.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n CompoundEntityRef,\n stringifyEntityRef,\n} from '@backstage/catalog-model';\nimport { ResponseError } from '@backstage/errors';\nimport { JsonCodeCoverage, JsonCoverageHistory } from './types';\nimport {\n createApiRef,\n DiscoveryApi,\n FetchApi,\n} from '@backstage/core-plugin-api';\n\nexport type CodeCoverageApi = {\n getCoverageForEntity: (\n entity: CompoundEntityRef,\n ) => Promise<JsonCodeCoverage>;\n getFileContentFromEntity: (\n entity: CompoundEntityRef,\n filePath: string,\n ) => Promise<string>;\n getCoverageHistoryForEntity: (\n entity: CompoundEntityRef,\n limit?: number,\n ) => Promise<JsonCoverageHistory>;\n};\n\nexport const codeCoverageApiRef = createApiRef<CodeCoverageApi>({\n id: 'plugin.code-coverage.service',\n});\n\nexport class CodeCoverageRestApi implements CodeCoverageApi {\n private readonly discoveryApi: DiscoveryApi;\n private readonly fetchApi: FetchApi;\n\n public constructor(options: {\n discoveryApi: DiscoveryApi;\n fetchApi: FetchApi;\n }) {\n this.discoveryApi = options.discoveryApi;\n this.fetchApi = options.fetchApi;\n }\n\n private async fetch<T = unknown | string | JsonCoverageHistory>(\n path: string,\n ): Promise<T | string> {\n const url = await this.discoveryApi.getBaseUrl('code-coverage');\n const resp = await this.fetchApi.fetch(`${url}${path}`);\n if (!resp.ok) {\n throw await ResponseError.fromResponse(resp);\n }\n if (resp.headers.get('content-type')?.includes('application/json')) {\n return await resp.json();\n }\n return await resp.text();\n }\n\n async getCoverageForEntity(\n entityName: CompoundEntityRef,\n ): Promise<JsonCodeCoverage> {\n const entity = encodeURIComponent(stringifyEntityRef(entityName));\n return (await this.fetch<JsonCodeCoverage>(\n `/report?entity=${entity}`,\n )) as JsonCodeCoverage;\n }\n\n async getFileContentFromEntity(\n entityName: CompoundEntityRef,\n filePath: string,\n ): Promise<string> {\n const entity = encodeURIComponent(stringifyEntityRef(entityName));\n return await this.fetch<string>(\n `/file-content?entity=${entity}&path=${encodeURI(filePath)}`,\n );\n }\n\n async getCoverageHistoryForEntity(\n entityName: CompoundEntityRef,\n limit?: number,\n ): Promise<JsonCoverageHistory> {\n const entity = encodeURIComponent(stringifyEntityRef(entityName));\n const hasValidLimit = limit && limit > 0;\n return (await this.fetch<JsonCoverageHistory>(\n `/history?entity=${entity}${\n hasValidLimit ? `&limit=${encodeURIComponent(String(limit))}` : ''\n }`,\n )) as JsonCoverageHistory;\n }\n}\n"],"names":[],"mappings":";;;;AA0CO,MAAM,qBAAqB,YAA8B,CAAA;AAAA,EAC9D,EAAI,EAAA,8BAAA;AACN,CAAC,EAAA;AAEM,MAAM,mBAA+C,CAAA;AAAA,EACzC,YAAA,CAAA;AAAA,EACA,QAAA,CAAA;AAAA,EAEV,YAAY,OAGhB,EAAA;AACD,IAAA,IAAA,CAAK,eAAe,OAAQ,CAAA,YAAA,CAAA;AAC5B,IAAA,IAAA,CAAK,WAAW,OAAQ,CAAA,QAAA,CAAA;AAAA,GAC1B;AAAA,EAEA,MAAc,MACZ,IACqB,EAAA;AACrB,IAAA,MAAM,GAAM,GAAA,MAAM,IAAK,CAAA,YAAA,CAAa,WAAW,eAAe,CAAA,CAAA;AAC9D,IAAM,MAAA,IAAA,GAAO,MAAM,IAAK,CAAA,QAAA,CAAS,MAAM,CAAG,EAAA,GAAG,CAAG,EAAA,IAAI,CAAE,CAAA,CAAA,CAAA;AACtD,IAAI,IAAA,CAAC,KAAK,EAAI,EAAA;AACZ,MAAM,MAAA,MAAM,aAAc,CAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AAAA,KAC7C;AACA,IAAA,IAAI,KAAK,OAAQ,CAAA,GAAA,CAA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} from '../CoverageHistoryChart/CoverageHistoryChart.esm.js';
|
|
3
|
+
import { FileExplorer } from '../FileExplorer/FileExplorer.esm.js';
|
|
4
|
+
import { Page, Content, ContentHeader } from '@backstage/core-components';
|
|
5
|
+
|
|
6
|
+
const CodeCoveragePage = () => {
|
|
7
|
+
return /* @__PURE__ */ React.createElement(Page, { themeId: "tool" }, /* @__PURE__ */ React.createElement(Content, null, /* @__PURE__ */ React.createElement(ContentHeader, { title: "Code coverage" }), /* @__PURE__ */ React.createElement(CoverageHistoryChart, null), /* @__PURE__ */ React.createElement(FileExplorer, null)));
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { CodeCoveragePage };
|
|
11
|
+
//# sourceMappingURL=CodeCoveragePage.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeCoveragePage.esm.js","sources":["../../../src/components/CodeCoveragePage/CodeCoveragePage.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React from 'react';\nimport { CoverageHistoryChart } from '../CoverageHistoryChart';\nimport { FileExplorer } from '../FileExplorer';\nimport { Content, ContentHeader, Page } from '@backstage/core-components';\n\nexport const CodeCoveragePage = () => {\n return (\n <Page themeId=\"tool\">\n <Content>\n <ContentHeader title=\"Code coverage\" />\n <CoverageHistoryChart />\n <FileExplorer />\n </Content>\n </Page>\n );\n};\n"],"names":[],"mappings":";;;;;AAoBO,MAAM,mBAAmB,MAAM;AACpC,EAAA,2CACG,IAAK,EAAA,EAAA,OAAA,EAAQ,MACZ,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,+BACE,KAAA,CAAA,aAAA,CAAA,aAAA,EAAA,EAAc,KAAM,EAAA,eAAA,EAAgB,mBACpC,KAAA,CAAA,aAAA,CAAA,oBAAA,EAAA,IAAqB,mBACrB,KAAA,CAAA,aAAA,CAAA,YAAA,EAAA,IAAa,CAChB,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { useEntity } from '@backstage/plugin-catalog-react';
|
|
2
|
+
import Box from '@material-ui/core/Box';
|
|
3
|
+
import Card from '@material-ui/core/Card';
|
|
4
|
+
import CardContent from '@material-ui/core/CardContent';
|
|
5
|
+
import CardHeader from '@material-ui/core/CardHeader';
|
|
6
|
+
import Typography from '@material-ui/core/Typography';
|
|
7
|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
8
|
+
import TrendingDownIcon from '@material-ui/icons/TrendingDown';
|
|
9
|
+
import TrendingFlatIcon from '@material-ui/icons/TrendingFlat';
|
|
10
|
+
import TrendingUpIcon from '@material-ui/icons/TrendingUp';
|
|
11
|
+
import Alert from '@material-ui/lab/Alert';
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import useAsync from 'react-use/esm/useAsync';
|
|
14
|
+
import { ResponsiveContainer, LineChart, CartesianGrid, XAxis, YAxis, Tooltip, Legend, Line } from 'recharts';
|
|
15
|
+
import { codeCoverageApiRef } from '../../api.esm.js';
|
|
16
|
+
import { Progress, ResponseErrorPanel } from '@backstage/core-components';
|
|
17
|
+
import { useApi } from '@backstage/core-plugin-api';
|
|
18
|
+
import { DateTime } from 'luxon';
|
|
19
|
+
|
|
20
|
+
const useStyles = makeStyles((theme) => ({
|
|
21
|
+
trendDown: {
|
|
22
|
+
color: theme.palette.status.warning
|
|
23
|
+
},
|
|
24
|
+
trendUp: {
|
|
25
|
+
color: theme.palette.status.ok
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
const getTrendIcon = (trend, classes) => {
|
|
29
|
+
switch (true) {
|
|
30
|
+
case trend > 0:
|
|
31
|
+
return /* @__PURE__ */ React.createElement(TrendingUpIcon, { className: classes.trendUp });
|
|
32
|
+
case trend < 0:
|
|
33
|
+
return /* @__PURE__ */ React.createElement(TrendingDownIcon, { className: classes.trendDown });
|
|
34
|
+
case trend === 0:
|
|
35
|
+
default:
|
|
36
|
+
return /* @__PURE__ */ React.createElement(TrendingFlatIcon, null);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
function formatDateToHuman(timeStamp) {
|
|
40
|
+
return DateTime.fromMillis(Number(timeStamp)).toLocaleString(
|
|
41
|
+
DateTime.DATETIME_MED
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
const CoverageHistoryChart = () => {
|
|
45
|
+
const { entity } = useEntity();
|
|
46
|
+
const codeCoverageApi = useApi(codeCoverageApiRef);
|
|
47
|
+
const {
|
|
48
|
+
loading: loadingHistory,
|
|
49
|
+
error: errorHistory,
|
|
50
|
+
value: valueHistory
|
|
51
|
+
} = useAsync(
|
|
52
|
+
async () => await codeCoverageApi.getCoverageHistoryForEntity({
|
|
53
|
+
kind: entity.kind,
|
|
54
|
+
namespace: entity.metadata.namespace || "default",
|
|
55
|
+
name: entity.metadata.name
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
const classes = useStyles();
|
|
59
|
+
if (loadingHistory) {
|
|
60
|
+
return /* @__PURE__ */ React.createElement(Progress, null);
|
|
61
|
+
}
|
|
62
|
+
if (errorHistory) {
|
|
63
|
+
return /* @__PURE__ */ React.createElement(ResponseErrorPanel, { error: errorHistory });
|
|
64
|
+
} else if (!valueHistory) {
|
|
65
|
+
return /* @__PURE__ */ React.createElement(Alert, { severity: "warning" }, "No history found.");
|
|
66
|
+
}
|
|
67
|
+
if (!valueHistory.history.length) {
|
|
68
|
+
return /* @__PURE__ */ React.createElement(Card, null, /* @__PURE__ */ React.createElement(CardHeader, { title: "History" }), /* @__PURE__ */ React.createElement(CardContent, null, "No coverage history found"));
|
|
69
|
+
}
|
|
70
|
+
const [oldestCoverage] = valueHistory.history.slice(-1);
|
|
71
|
+
const latestCoverage = valueHistory.history[0];
|
|
72
|
+
const getTrendForCoverage = (type) => {
|
|
73
|
+
if (!oldestCoverage[type].percentage) {
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
return (latestCoverage[type].percentage - oldestCoverage[type].percentage) / oldestCoverage[type].percentage * 100;
|
|
77
|
+
};
|
|
78
|
+
const lineTrend = getTrendForCoverage("line");
|
|
79
|
+
const branchTrend = getTrendForCoverage("branch");
|
|
80
|
+
return /* @__PURE__ */ React.createElement(Card, null, /* @__PURE__ */ React.createElement(CardHeader, { title: "History" }), /* @__PURE__ */ React.createElement(CardContent, null, /* @__PURE__ */ React.createElement(Box, { px: 6, display: "flex" }, /* @__PURE__ */ React.createElement(Box, { display: "flex", mr: 4 }, getTrendIcon(lineTrend, classes), /* @__PURE__ */ React.createElement(Typography, null, "Current line: ", latestCoverage.line.percentage, "%", /* @__PURE__ */ React.createElement("br", null), "(", Math.floor(lineTrend), "% change over ", valueHistory.history.length, " ", "builds)")), /* @__PURE__ */ React.createElement(Box, { display: "flex" }, getTrendIcon(branchTrend, classes), /* @__PURE__ */ React.createElement(Typography, null, "Current branch: ", latestCoverage.branch.percentage, "%", /* @__PURE__ */ React.createElement("br", null), "(", Math.floor(branchTrend), "% change over", " ", valueHistory.history.length, " builds)"))), /* @__PURE__ */ React.createElement(ResponsiveContainer, { width: "100%", height: 300 }, /* @__PURE__ */ React.createElement(
|
|
81
|
+
LineChart,
|
|
82
|
+
{
|
|
83
|
+
data: valueHistory.history,
|
|
84
|
+
margin: { right: 48, top: 32 }
|
|
85
|
+
},
|
|
86
|
+
/* @__PURE__ */ React.createElement(CartesianGrid, { strokeDasharray: "3 3" }),
|
|
87
|
+
/* @__PURE__ */ React.createElement(
|
|
88
|
+
XAxis,
|
|
89
|
+
{
|
|
90
|
+
dataKey: "timestamp",
|
|
91
|
+
tickFormatter: formatDateToHuman,
|
|
92
|
+
reversed: true
|
|
93
|
+
}
|
|
94
|
+
),
|
|
95
|
+
/* @__PURE__ */ React.createElement(YAxis, { dataKey: "line.percentage" }),
|
|
96
|
+
/* @__PURE__ */ React.createElement(YAxis, { dataKey: "branch.percentage" }),
|
|
97
|
+
/* @__PURE__ */ React.createElement(Tooltip, { labelFormatter: formatDateToHuman }),
|
|
98
|
+
/* @__PURE__ */ React.createElement(Legend, null),
|
|
99
|
+
/* @__PURE__ */ React.createElement(
|
|
100
|
+
Line,
|
|
101
|
+
{
|
|
102
|
+
type: "monotone",
|
|
103
|
+
dataKey: "branch.percentage",
|
|
104
|
+
stroke: "#8884d8"
|
|
105
|
+
}
|
|
106
|
+
),
|
|
107
|
+
/* @__PURE__ */ React.createElement(Line, { type: "monotone", dataKey: "line.percentage", stroke: "#82ca9d" })
|
|
108
|
+
))));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export { CoverageHistoryChart };
|
|
112
|
+
//# sourceMappingURL=CoverageHistoryChart.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoverageHistoryChart.esm.js","sources":["../../../src/components/CoverageHistoryChart/CoverageHistoryChart.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useEntity } from '@backstage/plugin-catalog-react';\nimport Box from '@material-ui/core/Box';\nimport Card from '@material-ui/core/Card';\nimport CardContent from '@material-ui/core/CardContent';\nimport CardHeader from '@material-ui/core/CardHeader';\nimport Typography from '@material-ui/core/Typography';\nimport { makeStyles } from '@material-ui/core/styles';\nimport TrendingDownIcon from '@material-ui/icons/TrendingDown';\nimport TrendingFlatIcon from '@material-ui/icons/TrendingFlat';\nimport TrendingUpIcon from '@material-ui/icons/TrendingUp';\nimport Alert from '@material-ui/lab/Alert';\nimport { ClassNameMap } from '@material-ui/styles/withStyles';\nimport React from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport {\n CartesianGrid,\n Legend,\n Line,\n LineChart,\n ResponsiveContainer,\n Tooltip,\n XAxis,\n YAxis,\n} from 'recharts';\nimport { codeCoverageApiRef } from '../../api';\n\nimport { Progress, ResponseErrorPanel } from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\n\nimport { DateTime } from 'luxon';\n\ntype Coverage = 'line' | 'branch';\n\nconst useStyles = makeStyles(theme => ({\n trendDown: {\n color: theme.palette.status.warning,\n },\n trendUp: {\n color: theme.palette.status.ok,\n },\n}));\n\nconst getTrendIcon = (trend: number, classes: ClassNameMap) => {\n switch (true) {\n case trend > 0:\n return <TrendingUpIcon className={classes.trendUp} />;\n case trend < 0:\n return <TrendingDownIcon className={classes.trendDown} />;\n case trend === 0:\n default:\n return <TrendingFlatIcon />;\n }\n};\n\n// convert timestamp to human friendly form\nfunction formatDateToHuman(timeStamp: string | number) {\n return DateTime.fromMillis(Number(timeStamp)).toLocaleString(\n DateTime.DATETIME_MED,\n );\n}\n\nexport const CoverageHistoryChart = () => {\n const { entity } = useEntity();\n const codeCoverageApi = useApi(codeCoverageApiRef);\n const {\n loading: loadingHistory,\n error: errorHistory,\n value: valueHistory,\n } = useAsync(\n async () =>\n await codeCoverageApi.getCoverageHistoryForEntity({\n kind: entity.kind,\n namespace: entity.metadata.namespace || 'default',\n name: entity.metadata.name,\n }),\n );\n const classes = useStyles();\n\n if (loadingHistory) {\n return <Progress />;\n }\n if (errorHistory) {\n return <ResponseErrorPanel error={errorHistory} />;\n } else if (!valueHistory) {\n return <Alert severity=\"warning\">No history found.</Alert>;\n }\n\n if (!valueHistory.history.length) {\n return (\n <Card>\n <CardHeader title=\"History\" />\n <CardContent>No coverage history found</CardContent>\n </Card>\n );\n }\n\n const [oldestCoverage] = valueHistory.history.slice(-1);\n const latestCoverage = valueHistory.history[0];\n\n const getTrendForCoverage = (type: Coverage) => {\n if (!oldestCoverage[type].percentage) {\n return 0;\n }\n return (\n ((latestCoverage[type].percentage - oldestCoverage[type].percentage) /\n oldestCoverage[type].percentage) *\n 100\n );\n };\n\n const lineTrend = getTrendForCoverage('line');\n const branchTrend = getTrendForCoverage('branch');\n\n return (\n <Card>\n <CardHeader title=\"History\" />\n <CardContent>\n <Box px={6} display=\"flex\">\n <Box display=\"flex\" mr={4}>\n {getTrendIcon(lineTrend, classes)}\n <Typography>\n Current line: {latestCoverage.line.percentage}%<br />(\n {Math.floor(lineTrend)}% change over {valueHistory.history.length}{' '}\n builds)\n </Typography>\n </Box>\n <Box display=\"flex\">\n {getTrendIcon(branchTrend, classes)}\n <Typography>\n Current branch: {latestCoverage.branch.percentage}%<br />(\n {Math.floor(branchTrend)}% change over{' '}\n {valueHistory.history.length} builds)\n </Typography>\n </Box>\n </Box>\n <ResponsiveContainer width=\"100%\" height={300}>\n <LineChart\n data={valueHistory.history}\n margin={{ right: 48, top: 32 }}\n >\n <CartesianGrid strokeDasharray=\"3 3\" />\n <XAxis\n dataKey=\"timestamp\"\n tickFormatter={formatDateToHuman}\n reversed\n />\n <YAxis dataKey=\"line.percentage\" />\n <YAxis dataKey=\"branch.percentage\" />\n <Tooltip labelFormatter={formatDateToHuman} />\n <Legend />\n <Line\n type=\"monotone\"\n dataKey=\"branch.percentage\"\n stroke=\"#8884d8\"\n />\n <Line type=\"monotone\" dataKey=\"line.percentage\" stroke=\"#82ca9d\" />\n </LineChart>\n </ResponsiveContainer>\n </CardContent>\n </Card>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAiDA,MAAM,SAAA,GAAY,WAAW,CAAU,KAAA,MAAA;AAAA,EACrC,SAAW,EAAA;AAAA,IACT,KA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|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
3
|
+
|
|
4
|
+
const useStyles = makeStyles((theme) => ({
|
|
5
|
+
lineNumberCell: {
|
|
6
|
+
color: `${theme.palette.grey[500]}`,
|
|
7
|
+
fontSize: "90%",
|
|
8
|
+
borderRight: `1px solid ${theme.palette.grey[500]}`,
|
|
9
|
+
paddingRight: theme.spacing(1),
|
|
10
|
+
textAlign: "right"
|
|
11
|
+
},
|
|
12
|
+
hitCountCell: {
|
|
13
|
+
width: "50px",
|
|
14
|
+
borderRight: `1px solid ${theme.palette.grey[500]}`,
|
|
15
|
+
textAlign: "center",
|
|
16
|
+
color: theme.palette.common.white,
|
|
17
|
+
// need to enforce this color since it needs to stand out against colored background
|
|
18
|
+
paddingLeft: theme.spacing(1),
|
|
19
|
+
paddingRight: theme.spacing(1)
|
|
20
|
+
},
|
|
21
|
+
countRoundedRectangle: {
|
|
22
|
+
borderRadius: "45px",
|
|
23
|
+
fontSize: "90%",
|
|
24
|
+
padding: "1px 3px 1px 3px",
|
|
25
|
+
width: "50px"
|
|
26
|
+
},
|
|
27
|
+
hitCountRoundedRectangle: {
|
|
28
|
+
backgroundColor: `${theme.palette.success.main}`,
|
|
29
|
+
color: `${theme.palette.success.contrastText}`
|
|
30
|
+
},
|
|
31
|
+
notHitCountRoundedRectangle: {
|
|
32
|
+
backgroundColor: `${theme.palette.error.main}`,
|
|
33
|
+
color: `${theme.palette.error.contrastText}`
|
|
34
|
+
},
|
|
35
|
+
codeLine: {
|
|
36
|
+
paddingLeft: `${theme.spacing(1)}`,
|
|
37
|
+
whiteSpace: "pre",
|
|
38
|
+
fontSize: "90%"
|
|
39
|
+
},
|
|
40
|
+
hitCodeLine: {
|
|
41
|
+
backgroundColor: `${theme.palette.success.main}`,
|
|
42
|
+
color: `${theme.palette.success.contrastText}`
|
|
43
|
+
},
|
|
44
|
+
notHitCodeLine: {
|
|
45
|
+
backgroundColor: `${theme.palette.error.main}`,
|
|
46
|
+
color: `${theme.palette.error.contrastText}`
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
const CodeRow = ({
|
|
50
|
+
lineNumber,
|
|
51
|
+
lineContent,
|
|
52
|
+
lineHits = null
|
|
53
|
+
}) => {
|
|
54
|
+
const classes = useStyles();
|
|
55
|
+
const hitCountRoundedRectangleClass = [classes.countRoundedRectangle];
|
|
56
|
+
const lineContentClass = [classes.codeLine];
|
|
57
|
+
let hitRoundedRectangle = null;
|
|
58
|
+
if (lineHits !== null) {
|
|
59
|
+
if (lineHits > 0) {
|
|
60
|
+
hitCountRoundedRectangleClass.push(classes.hitCountRoundedRectangle);
|
|
61
|
+
lineContentClass.push(classes.hitCodeLine);
|
|
62
|
+
} else {
|
|
63
|
+
hitCountRoundedRectangleClass.push(classes.notHitCountRoundedRectangle);
|
|
64
|
+
lineContentClass.push(classes.notHitCodeLine);
|
|
65
|
+
}
|
|
66
|
+
hitRoundedRectangle = /* @__PURE__ */ React.createElement("div", { className: hitCountRoundedRectangleClass.join(" ") }, lineHits);
|
|
67
|
+
}
|
|
68
|
+
return /* @__PURE__ */ React.createElement("tr", null, /* @__PURE__ */ React.createElement("td", { className: classes.lineNumberCell }, lineNumber), /* @__PURE__ */ React.createElement("td", { className: classes.hitCountCell }, hitRoundedRectangle), /* @__PURE__ */ React.createElement(
|
|
69
|
+
"td",
|
|
70
|
+
{
|
|
71
|
+
className: lineContentClass.join(" "),
|
|
72
|
+
dangerouslySetInnerHTML: { __html: lineContent }
|
|
73
|
+
}
|
|
74
|
+
));
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export { CodeRow };
|
|
78
|
+
//# sourceMappingURL=CodeRow.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeRow.esm.js","sources":["../../../src/components/FileExplorer/CodeRow.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\nimport { makeStyles } from '@material-ui/core/styles';\n\nconst useStyles = makeStyles(theme => ({\n lineNumberCell: {\n color: `${theme.palette.grey[500]}`,\n fontSize: '90%',\n borderRight: `1px solid ${theme.palette.grey[500]}`,\n paddingRight: theme.spacing(1),\n textAlign: 'right',\n },\n hitCountCell: {\n width: '50px',\n borderRight: `1px solid ${theme.palette.grey[500]}`,\n textAlign: 'center',\n color: theme.palette.common.white, // need to enforce this color since it needs to stand out against colored background\n paddingLeft: theme.spacing(1),\n paddingRight: theme.spacing(1),\n },\n countRoundedRectangle: {\n borderRadius: '45px',\n fontSize: '90%',\n padding: '1px 3px 1px 3px',\n width: '50px',\n },\n hitCountRoundedRectangle: {\n backgroundColor: `${theme.palette.success.main}`,\n color: `${theme.palette.success.contrastText}`,\n },\n notHitCountRoundedRectangle: {\n backgroundColor: `${theme.palette.error.main}`,\n color: `${theme.palette.error.contrastText}`,\n },\n codeLine: {\n paddingLeft: `${theme.spacing(1)}`,\n whiteSpace: 'pre',\n fontSize: '90%',\n },\n hitCodeLine: {\n backgroundColor: `${theme.palette.success.main}`,\n color: `${theme.palette.success.contrastText}`,\n },\n notHitCodeLine: {\n backgroundColor: `${theme.palette.error.main}`,\n color: `${theme.palette.error.contrastText}`,\n },\n}));\n\ntype CodeRowProps = {\n lineNumber: number;\n lineContent: string;\n lineHits?: number | null;\n};\n\nexport const CodeRow = ({\n lineNumber,\n lineContent,\n lineHits = null,\n}: CodeRowProps) => {\n const classes = useStyles();\n const hitCountRoundedRectangleClass = [classes.countRoundedRectangle];\n const lineContentClass = [classes.codeLine];\n\n let hitRoundedRectangle = null;\n if (lineHits !== null) {\n if (lineHits > 0) {\n hitCountRoundedRectangleClass.push(classes.hitCountRoundedRectangle);\n lineContentClass.push(classes.hitCodeLine);\n } else {\n hitCountRoundedRectangleClass.push(classes.notHitCountRoundedRectangle);\n lineContentClass.push(classes.notHitCodeLine);\n }\n hitRoundedRectangle = (\n <div className={hitCountRoundedRectangleClass.join(' ')}>{lineHits}</div>\n );\n }\n\n return (\n <tr>\n <td className={classes.lineNumberCell}>{lineNumber}</td>\n <td className={classes.hitCountCell}>{hitRoundedRectangle}</td>\n <td\n className={lineContentClass.join(' ')}\n dangerouslySetInnerHTML={{ __html: lineContent }}\n />\n </tr>\n );\n};\n"],"names":[],"mappings":";;;AAmBA,MAAM,SAAA,GAAY,WAAW,CAAU,KAAA,MAAA;AAAA,EACrC,cAAgB,EAAA;AAAA,IACd,OAAO,CAAG,EAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA;AAAA,IACjC,QAAU,EAAA,KAAA;AAAA,IACV,aAAa,CAAa,UAAA,EAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA;AAAA,IACjD,YAAA,EAAc,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,IAC7B,SAAW,EAAA,OAAA;AAAA,GACb;AAAA,EACA,YAAc,EAAA;AAAA,IACZ,KAAO,EAAA,MAAA;AAAA,IACP,aAAa,CAAa,UAAA,EAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,CAAK,GAAG,CAAC,CAAA,CAAA;AAAA,IACjD,SAAW,EAAA,QAAA;AAAA,IACX,KAAA,EAAO,KAAM,CAAA,OAAA,CAAQ,MAAO,CAAA,KAAA;AAAA;AAAA,IAC5B,WAAA,EAAa,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,IAC5B,YAAA,EAAc,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,GAC/B;AAAA,EACA,qBAAuB,EAAA;AAAA,IACrB,YAAc,E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,0 +1,89 @@
|
|
|
1
|
+
import { useEntity } from '@backstage/plugin-catalog-react';
|
|
2
|
+
import Paper from '@material-ui/core/Paper';
|
|
3
|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
4
|
+
import Alert from '@material-ui/lab/Alert';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import useAsync from 'react-use/esm/useAsync';
|
|
7
|
+
import { codeCoverageApiRef } from '../../api.esm.js';
|
|
8
|
+
import { CodeRow } from './CodeRow.esm.js';
|
|
9
|
+
import { highlightLines } from './Highlighter.esm.js';
|
|
10
|
+
import { Progress, ResponseErrorPanel } from '@backstage/core-components';
|
|
11
|
+
import { useApi } from '@backstage/core-plugin-api';
|
|
12
|
+
|
|
13
|
+
const useStyles = makeStyles((theme) => ({
|
|
14
|
+
paper: {
|
|
15
|
+
margin: "auto",
|
|
16
|
+
top: "2em",
|
|
17
|
+
width: "80%",
|
|
18
|
+
border: `2px solid ${theme.palette.common.black}`,
|
|
19
|
+
boxShadow: theme.shadows[5],
|
|
20
|
+
padding: theme.spacing(2, 4, 3),
|
|
21
|
+
overflow: "scroll"
|
|
22
|
+
},
|
|
23
|
+
coverageFileViewTable: {
|
|
24
|
+
borderSpacing: "0px",
|
|
25
|
+
width: "80%",
|
|
26
|
+
marginTop: theme.spacing(2)
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
const FormattedLines = ({
|
|
30
|
+
highlightedLines,
|
|
31
|
+
lineHits
|
|
32
|
+
}) => {
|
|
33
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, highlightedLines.map((lineContent, idx) => {
|
|
34
|
+
const line = idx + 1;
|
|
35
|
+
return /* @__PURE__ */ React.createElement(
|
|
36
|
+
CodeRow,
|
|
37
|
+
{
|
|
38
|
+
key: line,
|
|
39
|
+
lineNumber: line,
|
|
40
|
+
lineContent,
|
|
41
|
+
lineHits: lineHits[line]
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
46
|
+
const FileContent = ({ filename, coverage }) => {
|
|
47
|
+
const { entity } = useEntity();
|
|
48
|
+
const codeCoverageApi = useApi(codeCoverageApiRef);
|
|
49
|
+
const { loading, error, value } = useAsync(
|
|
50
|
+
async () => await codeCoverageApi.getFileContentFromEntity(
|
|
51
|
+
{
|
|
52
|
+
kind: entity.kind,
|
|
53
|
+
namespace: entity.metadata.namespace || "default",
|
|
54
|
+
name: entity.metadata.name
|
|
55
|
+
},
|
|
56
|
+
filename
|
|
57
|
+
),
|
|
58
|
+
[entity]
|
|
59
|
+
);
|
|
60
|
+
const classes = useStyles();
|
|
61
|
+
if (loading) {
|
|
62
|
+
return /* @__PURE__ */ React.createElement(Progress, null);
|
|
63
|
+
}
|
|
64
|
+
if (error) {
|
|
65
|
+
return /* @__PURE__ */ React.createElement(ResponseErrorPanel, { error });
|
|
66
|
+
}
|
|
67
|
+
if (!value) {
|
|
68
|
+
return /* @__PURE__ */ React.createElement(Alert, { severity: "warning" }, "Unable to retrieve file content for ", filename);
|
|
69
|
+
}
|
|
70
|
+
const [language] = filename.split(".").slice(-1);
|
|
71
|
+
const highlightedLines = highlightLines(language, value.split("\n"));
|
|
72
|
+
const lineHits = Object.entries(coverage.lineHits).reduce(
|
|
73
|
+
(acc, next) => {
|
|
74
|
+
acc[next[0]] = next[1];
|
|
75
|
+
return acc;
|
|
76
|
+
},
|
|
77
|
+
{}
|
|
78
|
+
);
|
|
79
|
+
return /* @__PURE__ */ React.createElement(Paper, { variant: "outlined", className: classes.paper }, /* @__PURE__ */ React.createElement("table", { className: classes.coverageFileViewTable }, /* @__PURE__ */ React.createElement("tbody", null, /* @__PURE__ */ React.createElement(
|
|
80
|
+
FormattedLines,
|
|
81
|
+
{
|
|
82
|
+
highlightedLines,
|
|
83
|
+
lineHits
|
|
84
|
+
}
|
|
85
|
+
))));
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export { FileContent };
|
|
89
|
+
//# sourceMappingURL=FileContent.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileContent.esm.js","sources":["../../../src/components/FileExplorer/FileContent.tsx"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { useEntity } from '@backstage/plugin-catalog-react';\nimport Paper from '@material-ui/core/Paper';\nimport { makeStyles } from '@material-ui/core/styles';\nimport Alert from '@material-ui/lab/Alert';\nimport React from 'react';\nimport useAsync from 'react-use/esm/useAsync';\nimport { codeCoverageApiRef } from '../../api';\nimport { FileEntry } from '../../types';\nimport { CodeRow } from './CodeRow';\nimport { highlightLines } from './Highlighter';\n\nimport { Progress, ResponseErrorPanel } from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\n\ntype Props = {\n filename: string;\n coverage: FileEntry;\n};\n\nconst useStyles = makeStyles(theme => ({\n paper: {\n margin: 'auto',\n top: '2em',\n width: '80%',\n border: `2px solid ${theme.palette.common.black}`,\n boxShadow: theme.shadows[5],\n padding: theme.spacing(2, 4, 3),\n overflow: 'scroll',\n },\n coverageFileViewTable: {\n borderSpacing: '0px',\n width: '80%',\n marginTop: theme.spacing(2),\n },\n}));\n\ntype FormattedLinesProps = {\n highlightedLines: string[];\n lineHits: Record<number, number>;\n};\nconst FormattedLines = ({\n highlightedLines,\n lineHits,\n}: FormattedLinesProps) => {\n return (\n <>\n {highlightedLines.map((lineContent, idx) => {\n const line = idx + 1;\n return (\n <CodeRow\n key={line}\n lineNumber={line}\n lineContent={lineContent}\n lineHits={lineHits[line]}\n />\n );\n })}\n </>\n );\n};\n\nexport const FileContent = ({ filename, coverage }: Props) => {\n const { entity } = useEntity();\n const codeCoverageApi = useApi(codeCoverageApiRef);\n const { loading, error, value } = useAsync(\n async () =>\n await codeCoverageApi.getFileContentFromEntity(\n {\n kind: entity.kind,\n namespace: entity.metadata.namespace || 'default',\n name: entity.metadata.name,\n },\n filename,\n ),\n [entity],\n );\n\n const classes = useStyles();\n\n if (loading) {\n return <Progress />;\n }\n if (error) {\n return <ResponseErrorPanel error={error} />;\n }\n if (!value) {\n return (\n <Alert severity=\"warning\">\n Unable to retrieve file content for {filename}\n </Alert>\n );\n }\n\n const [language] = filename.split('.').slice(-1);\n const highlightedLines = highlightLines(language, value.split('\\n'));\n\n // List of formatted nodes containing highlighted code\n // lineHits array where lineHits[i] is number of hits for line i + 1\n const lineHits = Object.entries(coverage.lineHits).reduce(\n (acc: Record<string, number>, next: [string, number]) => {\n acc[next[0]] = next[1];\n return acc;\n },\n {},\n );\n\n return (\n <Paper variant=\"outlined\" className={classes.paper}>\n <table className={classes.coverageFileViewTable}>\n <tbody>\n <FormattedLines\n highlightedLines={highlightedLines}\n lineHits={lineHits}\n />\n </tbody>\n </table>\n </Paper>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AAmCA,MAAM,SAAA,GAAY,WAAW,CAAU,KAAA,MAAA;AAAA,EACrC,KAAO,EAAA;AAAA,IACL,MAAQ,EAAA,MAAA;AAAA,IACR,GAAK,EAAA,KAAA;AAAA,IACL,KAAO,EAAA,KAAA;AAAA,IACP,MAAQ,EAAA,CAAA,UAAA,EAAa,KAAM,CAAA,OAAA,CAAQ,OAAO,KAAK,CAAA,CAAA;AAAA,IAC/C,SAAA,EAAW,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,IAC1B,OAAS,EAAA,KAAA,CAAM,OAAQ,CAAA,CAAA,EAAG,GAAG,CAAC,CAAA;AAAA,IAC9B,QAAU,EAAA,QAAA;AAAA,GACZ;AAAA,EACA,qBAAuB,EAAA;AAAA,IACrB,aAAe,EAAA,KAAA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