Skip to content

Commit

Permalink
Merge pull request #1701 from Nizzan943/feat/add-azure-pipelines
Browse files Browse the repository at this point in the history
Adding Azure Pipelines
  • Loading branch information
shamoon authored Jul 20, 2023
2 parents 1795126 + 04cccfd commit 460c67b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
10 changes: 10 additions & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -664,5 +664,15 @@
"kavita": {
"seriesCount": "Series",
"totalFiles": "Files"
},
"azurePipelines": {
"result": "Result",
"status": "Status",
"buildId": "Build ID",
"succeeded": "Succeeded",
"notStarted": "Not Started",
"failed": "Failed",
"canceled": "Canceled",
"inProgress": "In Progress"
}
}
3 changes: 3 additions & 0 deletions src/utils/proxy/handlers/credentialed.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export default async function credentialedProxyHandler(req, res, map) {
} else {
headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`;
}
}
else if (widget.type === "azurePipelines") {
headers.Authorization = `Basic ${Buffer.from(`$:${widget.key}`).toString("base64")}`;
} else {
headers["X-API-Key"] = `${widget.key}`;
}
Expand Down
36 changes: 36 additions & 0 deletions src/widgets/azurePipelines/component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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>
);
}
8 changes: 8 additions & 0 deletions src/widgets/azurePipelines/widget.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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;
1 change: 1 addition & 0 deletions src/widgets/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const components = {
audiobookshelf: dynamic(() => import("./audiobookshelf/component")),
authentik: dynamic(() => import("./authentik/component")),
autobrr: dynamic(() => import("./autobrr/component")),
azurePipelines: dynamic(() => import("./azurePipelines/component")),
bazarr: dynamic(() => import("./bazarr/component")),
caddy: dynamic(() => import("./caddy/component")),
changedetectionio: dynamic(() => import("./changedetectionio/component")),
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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 bazarr from "./bazarr/widget";
import caddy from "./caddy/widget";
import changedetectionio from "./changedetectionio/widget";
Expand Down Expand Up @@ -91,6 +92,7 @@ const widgets = {
audiobookshelf,
authentik,
autobrr,
azurePipelines,
bazarr,
caddy,
changedetectionio,
Expand Down

0 comments on commit 460c67b

Please sign in to comment.