Skip to content

Commit

Permalink
Merge branch 'main' into jira-table-filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron-Wood-Eric committed Sep 12, 2024
2 parents f83cd00 + 65ae7b3 commit 0c00872
Show file tree
Hide file tree
Showing 25 changed files with 114 additions and 274 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-pandas-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'app': minor
---

Added the JiraUserIssuesViewCard component to the Homepage
5 changes: 5 additions & 0 deletions .changeset/cyan-ears-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axis-backstage/plugin-jira-dashboard-backend': patch
---

Removed deprecated types and fixed the standalone server
5 changes: 5 additions & 0 deletions .changeset/eleven-melons-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axis-backstage/plugin-readme-backend': patch
---

Updated deprecated types and fixed the standalone server
5 changes: 5 additions & 0 deletions .changeset/thirty-bulldogs-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axis-backstage/plugin-jira-dashboard-backend': patch
---

Quote the incoming status string in the JQL. This makes it possible to have strings that contain whitespace.
9 changes: 9 additions & 0 deletions packages/app/src/components/home/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Content, Header, Page } from '@backstage/core-components';
import React from 'react';
import Grid from '@mui/material/Unstable_Grid2';
import { SearchBar } from '@backstage/plugin-search-react';
import { JiraUserIssuesViewCard } from '@axis-backstage/plugin-jira-dashboard';

export const homePage = (
<Page themeId="home">
Expand All @@ -33,6 +34,14 @@ export const homePage = (
<Grid xs={12}>
<HomePageRandomJoke />
</Grid>
<Grid xs={12}>
<JiraUserIssuesViewCard
bottomLinkProps={{
link: 'https://our-jira-server/issues',
title: 'Open in Jira',
}}
/>
</Grid>
</Grid>
</Grid>
</Content>
Expand Down
10 changes: 5 additions & 5 deletions plugins/jira-dashboard-backend/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
```ts
import { AuthService } from '@backstage/backend-plugin-api';
import { BackendFeatureCompat } from '@backstage/backend-plugin-api';
import { Config } from '@backstage/config';
import { DiscoveryService } from '@backstage/backend-plugin-api';
import express from 'express';
import { HttpAuthService } from '@backstage/backend-plugin-api';
import { IdentityApi } from '@backstage/plugin-auth-node';
import { IdentityService } from '@backstage/backend-plugin-api';
import { Issue } from '@axis-backstage/plugin-jira-dashboard-common';
import { LoggerService } from '@backstage/backend-plugin-api';
import { RootConfigService } from '@backstage/backend-plugin-api';
import { TokenManagerService } from '@backstage/backend-plugin-api';
import { UserInfoService } from '@backstage/backend-plugin-api';

Expand Down Expand Up @@ -39,18 +39,18 @@ export type JqlQueryBuilderArgs = {
// @public
export interface RouterOptions {
auth?: AuthService;
config: Config;
config: RootConfigService;
discovery: DiscoveryService;
httpAuth?: HttpAuthService;
identity?: IdentityApi;
identity?: IdentityService;
logger: LoggerService;
tokenManager?: TokenManagerService;
userInfo: UserInfoService;
}

// @public
export const searchJira: (
config: Config,
config: RootConfigService,
jqlQuery: string,
options: SearchOptions,
) => Promise<Issue[]>;
Expand Down
5 changes: 5 additions & 0 deletions plugins/jira-dashboard-backend/dev/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createBackend } from '@backstage/backend-defaults';

const backend = createBackend();
backend.add(import('../src'));
backend.start();
6 changes: 2 additions & 4 deletions plugins/jira-dashboard-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@
"dependencies": {
"@axis-backstage/plugin-jira-dashboard-common": "workspace:^",
"@backstage/backend-common": "^0.24.0",
"@backstage/backend-defaults": "^0.4.3",
"@backstage/backend-plugin-api": "^0.8.0",
"@backstage/catalog-client": "^1.6.6",
"@backstage/catalog-model": "^1.6.0",
"@backstage/config": "^1.2.0",
"@backstage/plugin-auth-node": "^0.5.0",
"@backstage/plugin-permission-common": "^0.8.1",
"@types/express": "*",
"express": "^4.17.1",
"express-promise-router": "^4.1.0",
"node-fetch": "^2.6.7",
"yn": "^4.0.0"
"node-fetch": "^2.6.7"
},
"devDependencies": {
"@backstage/backend-test-utils": "^0.5.0",
Expand Down
14 changes: 7 additions & 7 deletions plugins/jira-dashboard-backend/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from '@backstage/config';
import { RootConfigService } from '@backstage/backend-plugin-api';
import fetch from 'node-fetch';
import {
Filter,
Expand All @@ -10,7 +10,7 @@ import { jqlQueryBuilder } from './queries';

export const getProjectInfo = async (
projectKey: string,
config: Config,
config: RootConfigService,
): Promise<Project> => {
const response = await fetch(
`${resolveJiraBaseUrl(config)}project/${projectKey}`,
Expand All @@ -32,7 +32,7 @@ export const getProjectInfo = async (

export const getFilterById = async (
id: string,
config: Config,
config: RootConfigService,
): Promise<Filter> => {
const response = await fetch(`${resolveJiraBaseUrl(config)}filter/${id}`, {
method: 'GET',
Expand All @@ -52,7 +52,7 @@ export const getIssuesByFilter = async (
projectKey: string,
components: string[],
query: string,
config: Config,
config: RootConfigService,
): Promise<Issue[]> => {
const jql = jqlQueryBuilder({ project: projectKey, components, query });
const response = await fetch(
Expand Down Expand Up @@ -97,7 +97,7 @@ export type SearchOptions = {
* @public
*/
export const searchJira = async (
config: Config,
config: RootConfigService,
jqlQuery: string,
options: SearchOptions,
): Promise<Issue[]> => {
Expand All @@ -116,7 +116,7 @@ export const searchJira = async (
export const getIssuesByComponent = async (
projectKey: string,
componentKey: string,
config: Config,
config: RootConfigService,
): Promise<Issue[]> => {
const jql = jqlQueryBuilder({
project: projectKey,
Expand All @@ -135,7 +135,7 @@ export const getIssuesByComponent = async (
return response.issues;
};

export async function getProjectAvatar(url: string, config: Config) {
export async function getProjectAvatar(url: string, config: RootConfigService) {
const response = await fetch(url, {
method: 'GET',
headers: {
Expand Down
12 changes: 7 additions & 5 deletions plugins/jira-dashboard-backend/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import { Config } from '@backstage/config';
import { RootConfigService } from '@backstage/backend-plugin-api';

const JIRA_BASE_URL_CONFIG_PATH = 'jiraDashboard.baseUrl';
const JIRA_TOKEN_CONFIG_PATH = 'jiraDashboard.token';
const JIRA_USER_CONFIG_EMAIL_SUFFIX = 'jiraDashboard.userEmailSuffix';
const JIRA_ANNOTATION = 'jiraDashboard.annotationPrefix';

export function resolveJiraBaseUrl(config: Config): string {
export function resolveJiraBaseUrl(config: RootConfigService): string {
try {
return config.getString(JIRA_BASE_URL_CONFIG_PATH);
} catch (error) {
throw new Error(`Invalid Jira baseUrl, ${error}`);
}
}

export function resolveJiraToken(config: Config): string {
export function resolveJiraToken(config: RootConfigService): string {
try {
return config.getString(JIRA_TOKEN_CONFIG_PATH);
} catch (error) {
throw new Error(`Invalid Jira token, ${error}`);
}
}

export function resolveUserEmailSuffix(config: Config): string | undefined {
export function resolveUserEmailSuffix(
config: RootConfigService,
): string | undefined {
return config.getOptionalString(JIRA_USER_CONFIG_EMAIL_SUFFIX);
}

export function resolveAnnotationPrefix(config: Config): string {
export function resolveAnnotationPrefix(config: RootConfigService): string {
const annotationPrefix = config.getOptionalString(JIRA_ANNOTATION);
return annotationPrefix ?? 'jira.com';
}
10 changes: 5 additions & 5 deletions plugins/jira-dashboard-backend/src/filters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from '@backstage/config';
import { RootConfigService } from '@backstage/backend-plugin-api';
import { resolveUserEmailSuffix } from './config';
import { Filter } from '@axis-backstage/plugin-jira-dashboard-common';
import { UserEntity } from '@backstage/catalog-model';
Expand All @@ -12,7 +12,7 @@ const openFilter: Filter = {
const getIncomingFilter = (incomingStatus: string): Filter => ({
name: 'Incoming Issues',
shortName: 'INCOMING',
query: `status = ${incomingStatus} ORDER BY created ASC`,
query: `status = '${incomingStatus}' ORDER BY created ASC`,
});

/**
Expand All @@ -23,7 +23,7 @@ const getIncomingFilter = (incomingStatus: string): Filter => ({
* @param userEntity user entity instance
*/
export const getAssigneUser = (
config: Config,
config: RootConfigService,
userEntity: UserEntity,
): string => {
const emailSuffixConfig = resolveUserEmailSuffix(config);
Expand All @@ -35,7 +35,7 @@ export const getAssigneUser = (

const getAssignedToMeFilter = (
userEntity: UserEntity,
config: Config,
config: RootConfigService,
): Filter => {
const email = getAssigneUser(config, userEntity);

Expand All @@ -47,7 +47,7 @@ const getAssignedToMeFilter = (
};

export const getDefaultFiltersForUser = (
config: Config,
config: RootConfigService,
userEntity?: UserEntity,
incomingStatus?: string,
): Filter[] => {
Expand Down
4 changes: 2 additions & 2 deletions plugins/jira-dashboard-backend/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
FILTERS_NAME,
INCOMING_ISSUES_STATUS,
} from '@axis-backstage/plugin-jira-dashboard-common';
import { Config } from '@backstage/config';
import { RootConfigService } from '@backstage/backend-plugin-api';

export const getAnnotations = (config: Config) => {
export const getAnnotations = (config: RootConfigService) => {
const prefix = resolveAnnotationPrefix(config);

const projectKeyAnnotation = `${prefix}/${PROJECT_KEY_NAME}`;
Expand Down
17 changes: 0 additions & 17 deletions plugins/jira-dashboard-backend/src/run.ts

This file was deleted.

46 changes: 6 additions & 40 deletions plugins/jira-dashboard-backend/src/service/router.test.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,20 @@
import {
getVoidLogger,
PluginEndpointDiscovery,
ServerTokenManager,
} from '@backstage/backend-common';
import express from 'express';
import request from 'supertest';
import { createRouter } from './router';
import {
BackstageIdentityResponse,
IdentityApiGetIdentityRequest,
} from '@backstage/plugin-auth-node';
import { ConfigReader } from '@backstage/config';
import { mockServices } from '@backstage/backend-test-utils';

const testDiscovery: jest.Mocked<PluginEndpointDiscovery> = {
getBaseUrl: jest
.fn()
.mockResolvedValue('http://localhost:7007/api/jira-dashboard'),
getExternalBaseUrl: jest.fn(),
};

describe('createRouter', () => {
let app: express.Express;
const tokenManager = ServerTokenManager.noop();

const getIdentity = jest
.fn()
.mockImplementation(
async ({
request: _request,
}: IdentityApiGetIdentityRequest): Promise<
BackstageIdentityResponse | undefined
> => {
return {
identity: {
userEntityRef: 'user:default/guest',
ownershipEntityRefs: [],
type: 'user',
},
token: 'token',
};
},
);
const tokenManager = mockServices.tokenManager.mock();
const testDiscovery = mockServices.discovery.mock();
const identity = mockServices.identity.mock();

beforeAll(async () => {
const router = await createRouter({
logger: getVoidLogger(),
config: new ConfigReader({}),
logger: mockServices.logger.mock(),
config: mockServices.rootConfig(),
discovery: testDiscovery,
identity: { getIdentity },
identity,
tokenManager,
userInfo: mockServices.userInfo({ userEntityRef: 'user:default/guest' }),
});
Expand Down
Loading

0 comments on commit 0c00872

Please sign in to comment.