Skip to content

Commit

Permalink
Merge branch 'main' into improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SaachiNayyer committed Oct 25, 2024
2 parents bfb8f97 + 9799d36 commit 24f5c9b
Show file tree
Hide file tree
Showing 16 changed files with 931 additions and 151 deletions.
7 changes: 7 additions & 0 deletions packages/backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# backend

## 0.7.5

### Patch Changes

- Updated dependencies [b6b406c]
- @axis-backstage/plugin-jira-dashboard-backend@3.0.0

## 0.7.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backend",
"version": "0.7.4",
"version": "0.7.5",
"main": "dist/index.cjs.js",
"types": "src/index.ts",
"private": true,
Expand Down
6 changes: 6 additions & 0 deletions plugins/jira-dashboard-backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @axis-backstage/plugin-jira-dashboard-backend

## 3.0.0

### Major Changes

- b6b406c: BREAKING: The backend has been migrated to the new backend system. The createRouter function now requires the new auth and httpAuth services to be passed in, instead of the removed identity and tokenManager services. If you are using the new backend system module, this does not affect you.

## 2.7.0

### Minor Changes
Expand Down
43 changes: 0 additions & 43 deletions plugins/jira-dashboard-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,49 +96,6 @@ jiraDashboard:

### Integrating

Here's how to get the backend plugin up and running:

1. Create a new file named `packages/backend/src/plugins/jiraDashboard.ts`, and add the following to it:

```ts
import { createRouter } from '@axis-backstage/plugin-jira-dashboard-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
return await createRouter({
logger: env.logger,
config: env.config,
discovery: env.discovery,
identity: env.identity,
tokenManager: env.tokenManager,
});
}
```

2. Wire this into the overall backend router by adding the following to `packages/backend/src/index.ts`:

```ts
import jiraDashboard from './plugins/jiraDashboard';
...
async function main() {
// Add this line under the other lines that follow the useHotMemoize pattern
const jiraDashboardEnv = useHotMemoize(module, () => createEnv('jira-dashboard'),
// Add this under the lines that add their routers to apiRouter
apiRouter.use('/jira-dashboard', await jiraDashboard(jiraDashboardEnv));
}
```

3. Now run `yarn start-backend` from the repo root.

4. In another terminal, run the command: `curl localhost:7007/api/jira-dashboard/health`. The request should return `{"status":"ok"}`.

### New Backend System

The Jira Dashboard backend plugin has support for the [new backend system](https://backstage.io/docs/backend-system/). Here is how you can set it up:

In your `packages/backend/src/index.ts` make the following changes:
Expand Down
27 changes: 2 additions & 25 deletions plugins/jira-dashboard-backend/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { AuthService } from '@backstage/backend-plugin-api';
import { BackendFeatureCompat } from '@backstage/backend-plugin-api';
import { DiscoveryService } from '@backstage/backend-plugin-api';
import express from 'express';
import { HttpAuthService } from '@backstage/backend-plugin-api';
import { IdentityService } from '@backstage/backend-plugin-api';
import { Issue } from '@axis-backstage/plugin-jira-dashboard-common';
import { LoggerService } from '@backstage/backend-plugin-api';
import { JiraQueryResults } from '@axis-backstage/plugin-jira-dashboard-common';
import { RootConfigService } from '@backstage/backend-plugin-api';
import { TokenManagerService } from '@backstage/backend-plugin-api';
import { UserInfoService } from '@backstage/backend-plugin-api';

// @public @deprecated
export function createRouter(options: RouterOptions): Promise<express.Router>;

// @public
const jiraDashboardPlugin: BackendFeatureCompat;
Expand All @@ -36,24 +25,12 @@ export type JqlQueryBuilderArgs = {
query?: string;
};

// @public @deprecated
export interface RouterOptions {
auth?: AuthService;
config: RootConfigService;
discovery: DiscoveryService;
httpAuth?: HttpAuthService;
identity?: IdentityService;
logger: LoggerService;
tokenManager?: TokenManagerService;
userInfo: UserInfoService;
}

// @public
export const searchJira: (
config: RootConfigService,
jqlQuery: string,
options: SearchOptions,
) => Promise<Issue[]>;
) => Promise<JiraQueryResults>;

// @public
export type SearchOptions = {
Expand Down
4 changes: 4 additions & 0 deletions plugins/jira-dashboard-backend/dev/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { createBackend } from '@backstage/backend-defaults';

const backend = createBackend();

backend.add(import('@backstage/plugin-auth-backend'));
backend.add(import('@backstage/plugin-auth-backend-module-guest-provider'));
backend.add(import('../src'));

backend.start();
8 changes: 5 additions & 3 deletions plugins/jira-dashboard-backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@axis-backstage/plugin-jira-dashboard-backend",
"version": "2.7.0",
"version": "3.0.0",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
Expand Down Expand Up @@ -35,15 +35,17 @@
"@backstage/backend-plugin-api": "^0.8.0",
"@backstage/catalog-client": "^1.6.6",
"@backstage/catalog-model": "^1.6.0",
"@backstage/plugin-permission-common": "^0.8.1",
"@types/express": "*",
"@backstage/errors": "^1.2.4",
"express": "^4.17.1",
"express-promise-router": "^4.1.0",
"node-fetch": "^2.6.7"
},
"devDependencies": {
"@backstage/backend-test-utils": "^0.5.0",
"@backstage/cli": "^0.27.0",
"@backstage/plugin-auth-backend": "^0.23.0",
"@backstage/plugin-auth-backend-module-guest-provider": "^0.2.0",
"@types/express": "*",
"@types/supertest": "^2.0.12",
"msw": "^1.0.0",
"supertest": "^6.2.4"
Expand Down
3 changes: 1 addition & 2 deletions plugins/jira-dashboard-backend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@ export const getIssuesByComponent = async (
};

export async function getProjectAvatar(url: string, config: RootConfigService) {
const response = await fetch(url, {
return await fetch(url, {
method: 'GET',
headers: {
Authorization: resolveJiraToken(config),
},
});
return response;
}
1 change: 0 additions & 1 deletion plugins/jira-dashboard-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @packageDocumentation
*/

export * from './service/router';
export { jiraDashboardPlugin as default } from './plugin';
export { searchJira } from './api';
export type { SearchOptions } from './api';
Expand Down
14 changes: 9 additions & 5 deletions plugins/jira-dashboard-backend/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,37 @@ export const jiraDashboardPlugin = createBackendPlugin({
register(env) {
env.registerInit({
deps: {
auth: coreServices.auth,
httpRouter: coreServices.httpRouter,
logger: coreServices.logger,
config: coreServices.rootConfig,
discovery: coreServices.discovery,
httpRouter: coreServices.httpRouter,
auth: coreServices.auth,
httpAuth: coreServices.httpAuth,
userInfo: coreServices.userInfo,
},
async init({
auth,
httpRouter,
logger,
config,
discovery,
httpRouter,
auth,
httpAuth,
userInfo,
}) {
httpRouter.use(
await createRouter({
auth,
logger,
config,
discovery,
auth,
httpAuth,
userInfo,
}),
);
httpRouter.addAuthPolicy({
path: '/health',
allow: 'unauthenticated',
});
},
});
},
Expand Down
1 change: 0 additions & 1 deletion plugins/jira-dashboard-backend/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export type JqlQueryBuilderArgs = {

/**
* Creates a jql query string.
*
* @public
*/
export const jqlQueryBuilder = ({
Expand Down
3 changes: 3 additions & 0 deletions plugins/jira-dashboard-backend/src/service/defaultValues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const DEFAULT_TTL = 1000 * 60;

export const DEFAULT_MAX_RESULTS_USER_ISSUES = 10;
14 changes: 6 additions & 8 deletions plugins/jira-dashboard-backend/src/service/router.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { mockServices } from '@backstage/backend-test-utils';
import express from 'express';
import request from 'supertest';

import { createRouter } from './router';
import { mockServices } from '@backstage/backend-test-utils';

describe('createRouter', () => {
let app: express.Express;
const tokenManager = mockServices.tokenManager.mock();
const testDiscovery = mockServices.discovery.mock();
const identity = mockServices.identity.mock();

beforeAll(async () => {
const router = await createRouter({
auth: mockServices.auth.mock(),
logger: mockServices.logger.mock(),
config: mockServices.rootConfig(),
discovery: testDiscovery,
identity,
tokenManager,
userInfo: mockServices.userInfo({ userEntityRef: 'user:default/guest' }),
discovery: mockServices.discovery.mock(),
httpAuth: mockServices.httpAuth.mock(),
userInfo: mockServices.userInfo.mock(),
});
app = express().use(router);
});
Expand Down
Loading

0 comments on commit 24f5c9b

Please sign in to comment.