mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-10 15:28:47 +00:00
Add Azure DevOps (#1715)
* add azure pullrequrests * add creatorId * rename azurePullrequests->azurePullRequests * pass creatorId to FE * expose userEmail to frontend * tolower * remove unused code * merge to AzureDevOps * fix userEmail * remove whitespace in const and set true endpoint in widget * use widget params in endpoint * change approvedNotCompleted to Approved * change to lower * rename * rename * merge widgets together * limit pipeline result to 1 result * Better handle azuredevops PR call failures * change to have repositoryId and not branchName * Fix field filtering, avoid PR call if not needed --------- Co-authored-by: Nitzan Miranda <Nitzan.Miranda@bagirasys.com> Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
parent
ac61dc5d0c
commit
7e05adc02a
10 changed files with 100 additions and 51 deletions
|
@ -1,36 +0,0 @@
|
|||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { widget } = service;
|
||||
|
||||
const { data: pipelineData, error: pipelineError } = useWidgetAPI(widget);
|
||||
|
||||
if (pipelineError) {
|
||||
return <Container service={service} error={pipelineError} />;
|
||||
}
|
||||
|
||||
if (!pipelineData || !Array.isArray(pipelineData.value)) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="azurePipelines.result" />
|
||||
<Block label="azurePipelines.buildId" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
{pipelineData.value[0].result ?
|
||||
<Block label="azurePipelines.result" value={t(`azurePipelines.${pipelineData.value[0].result.toString()}`)} /> :
|
||||
<Block label="azurePipelines.status" value={t(`azurePipelines.${pipelineData.value[0].status.toString()}`)} />
|
||||
}
|
||||
<Block label="azurePipelines.buildId" value= { pipelineData.value[0].id } />
|
||||
</Container>
|
||||
);
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "https://dev.azure.com/{organization}/{project}/_apis/build/Builds?branchName={branchName}&definitions={definitionId}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
};
|
||||
|
||||
export default widget;
|
65
src/widgets/azuredevops/component.jsx
Normal file
65
src/widgets/azuredevops/component.jsx
Normal file
|
@ -0,0 +1,65 @@
|
|||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
const { widget } = service;
|
||||
const { userEmail, repositoryId } = widget;
|
||||
const includePR = userEmail !== undefined && repositoryId !== undefined;
|
||||
const { data: prData, error: prError } = useWidgetAPI(widget, includePR ? "pr" : null);
|
||||
const { data: pipelineData, error: pipelineError } = useWidgetAPI(widget, "pipeline");
|
||||
|
||||
if (
|
||||
pipelineError ||
|
||||
(includePR && (prError || prData?.errorCode !== undefined))
|
||||
) {
|
||||
let finalError = pipelineError ?? prError;
|
||||
if (includePR && prData?.errorCode !== null) {
|
||||
// pr call failed possibly with more specific message
|
||||
finalError = { message: prData?.message ?? 'Error communicating with Azure API' }
|
||||
}
|
||||
return <Container service={service} error={finalError} />;
|
||||
}
|
||||
|
||||
if (!pipelineData || !Array.isArray(pipelineData.value) || (includePR && !prData)) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="azuredevops.result" />
|
||||
<Block label="azuredevops.totalPrs" />
|
||||
<Block label="azuredevops.myPrs" />
|
||||
<Block label="azuredevops.approved" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
{pipelineData.value[0].result ? (
|
||||
<Block label="azuredevops.result" value={t(`azuredevops.${pipelineData.value[0].result.toString()}`)} />
|
||||
) : (
|
||||
<Block label="azuredevops.status" value={t(`azuredevops.${pipelineData.value[0].status.toString()}`)} />
|
||||
)}
|
||||
|
||||
{includePR && <Block label="azuredevops.totalPrs" value={t("common.number", { value: prData.count })} />}
|
||||
{includePR && <Block
|
||||
label="azuredevops.myPrs"
|
||||
value={t("common.number", {
|
||||
value: prData.value?.filter((item) => item.createdBy.uniqueName.toLowerCase() === userEmail.toLowerCase())
|
||||
.length,
|
||||
})}
|
||||
/>}
|
||||
{includePR && <Block
|
||||
label="azuredevops.approved"
|
||||
value={t("common.number", {
|
||||
value: prData.value
|
||||
?.filter((item) => item.createdBy.uniqueName.toLowerCase() === userEmail.toLowerCase())
|
||||
.filter((item) => item.reviewers.some((reviewer) => reviewer.vote === 10)).length,
|
||||
})}
|
||||
/>}
|
||||
|
||||
</Container>
|
||||
);
|
||||
}
|
18
src/widgets/azuredevops/widget.js
Normal file
18
src/widgets/azuredevops/widget.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "https://dev.azure.com/{organization}/{project}/_apis/{endpoint}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
pr: {
|
||||
endpoint: "git/repositories/{repositoryId}/pullrequests"
|
||||
},
|
||||
|
||||
pipeline: {
|
||||
endpoint: "build/Builds?branchName={branchName}&definitions={definitionId}&$top=1"
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
|
@ -5,7 +5,7 @@ const components = {
|
|||
audiobookshelf: dynamic(() => import("./audiobookshelf/component")),
|
||||
authentik: dynamic(() => import("./authentik/component")),
|
||||
autobrr: dynamic(() => import("./autobrr/component")),
|
||||
azurePipelines: dynamic(() => import("./azurePipelines/component")),
|
||||
azuredevops: dynamic(() => import("./azuredevops/component")),
|
||||
bazarr: dynamic(() => import("./bazarr/component")),
|
||||
caddy: dynamic(() => import("./caddy/component")),
|
||||
changedetectionio: dynamic(() => import("./changedetectionio/component")),
|
||||
|
|
|
@ -2,7 +2,7 @@ import adguard from "./adguard/widget";
|
|||
import audiobookshelf from "./audiobookshelf/widget";
|
||||
import authentik from "./authentik/widget";
|
||||
import autobrr from "./autobrr/widget";
|
||||
import azurePipelines from "./azurePipelines/widget";
|
||||
import azuredevops from "./azuredevops/widget";
|
||||
import bazarr from "./bazarr/widget";
|
||||
import caddy from "./caddy/widget";
|
||||
import changedetectionio from "./changedetectionio/widget";
|
||||
|
@ -93,7 +93,7 @@ const widgets = {
|
|||
audiobookshelf,
|
||||
authentik,
|
||||
autobrr,
|
||||
azurePipelines,
|
||||
azuredevops,
|
||||
bazarr,
|
||||
caddy,
|
||||
changedetectionio,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue