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>pull/1740/head^2
parent
ac61dc5d0c
commit
7e05adc02a
@ -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;
|
@ -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>
|
||||
);
|
||||
}
|
@ -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;
|
Loading…
Reference in new issue