Skip to content

Commit

Permalink
Updates to Opensource Jira Plugin
Browse files Browse the repository at this point in the history
Signed-off-by: enaysaa <[email protected]>
  • Loading branch information
SaachiNayyer committed Mar 15, 2024
1 parent 36d6e6f commit a6870da
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .changeset/big-dogs-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@axis-backstage/plugin-jira-dashboard-backend': minor
---

Updated the resolveUserEmailSuffix function to utilize config.getOptionalString method, providing a more concise approach. This modification ensures that an empty string is returned if the Jira user email suffix configuration is missing, effectively preventing failures and enhancing error logging capabilities.

Modified the retrieval of project keys in the router module to handle multiple project keys specified in annotations for e.g., jira.com/project-key: abc,def,ghi
The updated logic now parses multiple project keys properly and supports comma-separated values. It's important to note that in cases where multiple project keys are present, only the first project key (projectKey[0]) is used for display on the project card i.e, in this case project-key "abc", assuming it represents the main project. However, the response table will include data from all project keys specified in the annotations.
6 changes: 1 addition & 5 deletions plugins/jira-dashboard-backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ export function resolveJiraToken(config: Config): string {
}

export function resolveUserEmailSuffix(config: Config): string {
try {
return config.getString(JIRA_USER_CONFIG_EMAIL_SUFFIX);
} catch (error) {
throw new Error(`Invalid Jira user path, ${error}`);
}
return config.getOptionalString(JIRA_USER_CONFIG_EMAIL_SUFFIX) || '';
}

export function resolveAnnotationPrefix(config: Config): string {
Expand Down
24 changes: 15 additions & 9 deletions plugins/jira-dashboard-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export async function createRouter(
return;
}

const projectKey = entity.metadata.annotations?.[projectKeyAnnotation]!;
const projectKey =
entity.metadata.annotations?.[projectKeyAnnotation]?.split(',')!;

if (!projectKey) {
const error = `No jira.com/project-key annotation found for ${entityRef}`;
Expand All @@ -118,11 +119,15 @@ export async function createRouter(
let projectResponse;

try {
projectResponse = await getProjectResponse(projectKey, config, cache);
projectResponse = await getProjectResponse(
projectKey[0],
config,
cache,
);
} catch (err) {
logger.error(`Could not find Jira project ${projectKey}`);
logger.error(`Could not find Jira project ${projectKey[0]}`);
response.status(404).json({
error: `No Jira project found with key ${projectKey}`,
error: `No Jira project found with key ${projectKey[0]}`,
});
return;
}
Expand All @@ -149,7 +154,7 @@ export async function createRouter(
);
}

let issues = await getIssuesFromFilters(projectKey, filters, config);
let issues = await getIssuesFromFilters(projectKey[0], filters, config);

let components =
entity.metadata.annotations?.[componentsAnnotation]?.split(',') ?? [];
Expand All @@ -162,7 +167,7 @@ export async function createRouter(

if (components) {
const componentIssues = await getIssuesFromComponents(
projectKey,
projectKey[0],
components,
config,
);
Expand Down Expand Up @@ -194,18 +199,19 @@ export async function createRouter(
return;
}

const projectKey = entity.metadata.annotations?.[projectKeyAnnotation]!;
const projectKey =
entity.metadata.annotations?.[projectKeyAnnotation]?.split(',')!;

const projectResponse = await getProjectResponse(
projectKey,
projectKey[0],
config,
cache,
);

if (!projectResponse) {
logger.error('Could not find project in Jira');
response.status(400).json({
error: `No Jira project found for project key ${projectKey}`,
error: `No Jira project found for project key ${projectKey[0]}`,
});
return;
}
Expand Down

0 comments on commit a6870da

Please sign in to comment.