Skip to content

Commit

Permalink
tiny refactoring related to packages update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Bakhtiyarov committed Aug 12, 2024
1 parent abbb000 commit fa7c81e
Show file tree
Hide file tree
Showing 5 changed files with 4,480 additions and 3,870 deletions.
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@parfuemerie-douglas/scaffolder-backend-module-azure-pipelines",
"version": "1.1.0",
"version": "1.2.0",
"description": "A collection of Backstage scaffolder backend modules for Azure pipelines.",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts",
Expand All @@ -10,7 +10,9 @@
"types": "dist/index.d.ts"
},
"backstage": {
"role": "backend-plugin-module"
"role": "backend-plugin-module",
"pluginId": "scaffolder",
"pluginPackage": "@backstage/plugin-scaffolder-backend"
},
"scripts": {
"start": "backstage-cli package start",
Expand Down Expand Up @@ -39,16 +41,16 @@
},
"homepage": "https://github.com/Parfuemerie-Douglas/scaffolder-backend-module-azure-pipelines#readme",
"dependencies": {
"@backstage/backend-common": "^0.20.0",
"@backstage/errors": "^1.2.3",
"@backstage/integration": "^1.8.0",
"@backstage/plugin-scaffolder-backend": "^1.19.2",
"@backstage/plugin-scaffolder-node": "^0.2.9",
"@backstage/backend-common": "^0.23.3",
"@backstage/errors": "^1.2.4",
"@backstage/integration": "^1.13.0",
"@backstage/plugin-scaffolder-backend": "^1.23.0",
"@backstage/plugin-scaffolder-node": "^0.4.8",
"@backstage/types": "^1.1.1",
"node-fetch": "^2.6.2"
"node-fetch": "^3.3.2"
},
"devDependencies": {
"@backstage/cli": "^0.25.1",
"@backstage/cli": "^0.26.11",
"@types/node-fetch": "^2.6.2"
},
"dependenciesMeta": {
Expand Down
13 changes: 4 additions & 9 deletions src/actions/run/createAzurePipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import { DefaultAzureDevOpsCredentialsProvider, ScmIntegrationRegistry } from "@backstage/integration";
import { createTemplateAction } from "@backstage/plugin-scaffolder-node";

import fetch from "node-fetch";

export const createAzurePipelineAction = (options: {
integrations: ScmIntegrationRegistry;
}) => {
Expand Down Expand Up @@ -54,11 +52,6 @@ export const createAzurePipelineAction = (options: {
title: "Create API version",
description: "The Azure Create Pipeline API version to use. Defaults to 6.1-preview.1",
},
server: {
type: "string",
title: "Host",
description: "The host of Azure DevOps. Defaults to dev.azure.com",
},
organization: {
type: "string",
title: "Organization",
Expand Down Expand Up @@ -121,6 +114,8 @@ export const createAzurePipelineAction = (options: {
`Creating an Azure pipeline for the repository ${repositoryName} with the ID ${repositoryId}.`
);

const fetchModule = await import("node-fetch");
const fetch: typeof fetchModule.default = fetchModule.default;
// See the Azure DevOps documentation for more information about the REST API:
// https://docs.microsoft.com/en-us/rest/api/azure/devops/pipelines/pipelines/create?view=azure-devops-rest-6.1
await fetch(
Expand Down Expand Up @@ -150,7 +145,7 @@ export const createAzurePipelineAction = (options: {
}),
}
)
.then((response) => {
.then((response: any) => {
if (response.ok) {
ctx.logger.info(
`Successfully created ${name} Azure pipeline in ${folder}.`
Expand All @@ -163,7 +158,7 @@ export const createAzurePipelineAction = (options: {

return response.json();
})
.then((data) => {
.then((data: any) => {
ctx.logger.info(`The Azure pipeline ID is ${data.id}.`);

ctx.output("pipelineId", data.id.toString());
Expand Down
11 changes: 3 additions & 8 deletions src/actions/run/permitAzurePipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import { DefaultAzureDevOpsCredentialsProvider, ScmIntegrationRegistry } from "@backstage/integration";
import { createTemplateAction } from "@backstage/plugin-scaffolder-node";

import fetch from "node-fetch";

export const permitAzurePipelineAction = (options: {
integrations: ScmIntegrationRegistry;
}) => {
Expand Down Expand Up @@ -53,11 +51,6 @@ export const permitAzurePipelineAction = (options: {
title: "Permits API version",
description: "The Azure Permits Pipeline API version to use. Defaults to 7.1-preview.1",
},
server: {
type: "string",
title: "Host",
description: "The host of Azure DevOps. Defaults to dev.azure.com",
},
organization: {
type: "string",
title: "Organization",
Expand Down Expand Up @@ -120,6 +113,8 @@ export const permitAzurePipelineAction = (options: {
);
}

const fetchModule = await import("node-fetch");
const fetch: typeof fetchModule.default = fetchModule.default;
// See the Azure DevOps documentation for more information about the REST API:
// https://docs.microsoft.com/en-us/rest/api/azure/devops/approvalsandchecks/pipeline-permissions/update-pipeline-permisions-for-resource?view=azure-devops-rest-7.1
await fetch(
Expand All @@ -143,7 +138,7 @@ export const permitAzurePipelineAction = (options: {
],
}),
}
).then((response) => {
).then((response: any) => {
if (response.ok) {
ctx.logger.info(
`Successfully changed the Azure pipeline permissions.`
Expand Down
20 changes: 8 additions & 12 deletions src/actions/run/runAzurePipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import { DefaultAzureDevOpsCredentialsProvider, ScmIntegrationRegistry } from "@backstage/integration";
import { createTemplateAction } from "@backstage/plugin-scaffolder-node";

import fetch from "node-fetch";

interface RunPipelineRequest {
previewRun?: boolean;
resources?: {
Expand Down Expand Up @@ -60,7 +58,7 @@ export const runAzurePipelineAction = (options: {
if (!response.ok) {
throw new Error(`Failed to retrieve pipeline run status. Status code ${response.status}.`);
}
const json = await response.json();
const json: any = await response.json();
const status = json.status;
if (status === "completed") {
return json.result === "succeeded";
Expand Down Expand Up @@ -104,11 +102,6 @@ export const runAzurePipelineAction = (options: {
title: "Build API version",
description: "The Builds API version to use. Defaults to 6.1-preview.6",
},
server: {
type: "string",
title: "Host",
description: "The host of Azure DevOps. Defaults to dev.azure.com",
},
organization: {
type: "string",
title: "Organization",
Expand Down Expand Up @@ -175,6 +168,9 @@ export const runAzurePipelineAction = (options: {

const body = JSON.stringify(request);


const fetchModule = await import("node-fetch");
const fetch: typeof fetchModule.default = fetchModule.default;
// See the Azure DevOps documentation for more information about the REST API:
// https://docs.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-7.0
await fetch(
Expand All @@ -191,12 +187,12 @@ export const runAzurePipelineAction = (options: {
},
body,
}
).then((response) => {
).then((response: any) => {
if (response.ok) {
return response.json();
}
throw new Error(`Failed to run Azure pipeline. Status code ${response.status}.`);
}).then((json) => {
}).then((json: any) => {
const pipelineUrl = json._links.web.href;
ctx.logger.info(`Successfully started Azure pipeline run: ${pipelineUrl}`);

Expand All @@ -205,14 +201,14 @@ export const runAzurePipelineAction = (options: {
// Poll the pipeline status until it completes.
return checkPipelineStatus(host, organization, project, pipelineRunId, token, apiVersions.buildApiVersion);
})
.then((success) => {
.then((success: any) => {
if (success) {
ctx.logger.info(`Azure pipeline completed successfully.`);
} else {
ctx.logger.error(`Azure pipeline failed.`);
}
})
.catch((error) => {
.catch((error: any) => {
// Handle any errors that occurred during the pipeline run or status check.
ctx.logger.error(error.message);
});
Expand Down
Loading

0 comments on commit fa7c81e

Please sign in to comment.