Skip to content

Commit

Permalink
Provide module for the new backend system (#32)
Browse files Browse the repository at this point in the history
* add module file and update readme

* Bump versions

* fix: upgrade dependencies & imports

* fix: switch branch with clone instead of checkout

* add module file and update readme

* Bump versions

* bump backend-plugin-api to 0.7.0 and update yarn.lock

* increment minor

---------

Co-authored-by: Johannes Bradt <[email protected]>
Co-authored-by: Gio Divino <[email protected]>
  • Loading branch information
3 people authored Aug 12, 2024
1 parent 75ec167 commit 60cec64
Show file tree
Hide file tree
Showing 5 changed files with 3,937 additions and 351 deletions.
54 changes: 7 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,56 +28,16 @@ yarn add --cwd packages/backend @parfuemerie-douglas/scaffolder-backend-module-a
```

Configure the actions (you can check the
[docs](https://backstage.io/docs/features/software-templates/writing-custom-actions#registering-custom-actions)
[docs](https://backstage.io/docs/features/software-templates/writing-custom-actions/#register-action-with-new-backend-system)
to see all options):

```typescript
// packages/backend/src/plugins/scaffolder.ts

import { CatalogClient } from '@backstage/catalog-client';
import { ScmIntegrations } from "@backstage/integration";

import {
cloneAzureRepoAction,
pushAzureRepoAction,
pullRequestAzureRepoAction,
} from "@parfuemerie-douglas/scaffolder-backend-module-azure-repositories";

import { Router } from 'express';

import type { PluginEnvironment } from '../types';

export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
const catalogClient = new CatalogClient({
discoveryApi: env.discovery,
});

const integrations = ScmIntegrations.fromConfig(env.config);

const actions = [
cloneAzureRepoAction({ integrations }),
pushAzureRepoAction({ integrations, config: env.config }),
pullRequestAzureRepoAction({ integrations }),
...createBuiltInActions({
containerRunner,
catalogClient,
integrations,
config: env.config,
reader: env.reader,
}),
];

return await createRouter({
containerRunner,
catalogClient,
actions,
logger: env.logger,
config: env.config,
database: env.database,
reader: env.reader,
});
// packages/backend/src/index.ts
const backend = createBackend();

// ...

backend.add(import('@parfuemerie-douglas/scaffolder-backend-module-azure-repositories'))
```

The Azure repository actions use an [Azure PAT (personal access
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@parfuemerie-douglas/scaffolder-backend-module-azure-repositories",
"version": "0.2.8",
"version": "0.4.0",
"description": "A collection of Backstage scaffolder backend modules for Azure repositories.",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -40,12 +40,12 @@
"homepage": "https://github.com/Parfuemerie-Douglas/scaffolder-backend-module-azure-repositories#readme",
"dependencies": {
"@backstage/backend-common": "^0.22.0",
"@backstage/backend-plugin-api": "^0.6.18",
"@backstage/cli-common": "^0.1.13",
"@backstage/config": "^1.1.1",
"@backstage/backend-plugin-api": "^0.7.0",
"@backstage/config": "^1.2.0",
"@backstage/errors": "^1.2.3",
"@backstage/integration": "^1.8.0",
"@backstage/plugin-scaffolder-node": "^0.4.4",
"@backstage/plugin-scaffolder-backend": "^1.22.6",
"@backstage/plugin-scaffolder-node": "^0.2.9",
"@backstage/types": "^1.1.1",
"azure-devops-node-api": "^13.0.0",
"winston": "^3.2.1"
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
* limitations under the License.
*/

export { scaffolderModuleAzureRepositories as default } from './module';
export * from "./actions";
30 changes: 30 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';
import {
createBackendModule,
coreServices,
} from '@backstage/backend-plugin-api';
import { ScmIntegrations } from '@backstage/integration';

import {
cloneAzureRepoAction,
pushAzureRepoAction,
pullRequestAzureRepoAction,
} from "./actions";

export const scaffolderModuleAzureRepositories = createBackendModule({
pluginId: 'scaffolder',
moduleId: 'azure-repos',
register(env) {
env.registerInit({
deps: {
scaffolder: scaffolderActionsExtensionPoint,
config: coreServices.rootConfig,
},
async init({ scaffolder, config }) {
const integrations = ScmIntegrations.fromConfig(config);

scaffolder.addActions(cloneAzureRepoAction({ integrations }), pushAzureRepoAction({ integrations, config }), pullRequestAzureRepoAction({ integrations }));
},
});
},
});
Loading

0 comments on commit 60cec64

Please sign in to comment.