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 12, 2024
1 parent 36d6e6f commit afe270b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .changeset/big-dogs-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@axis-backstage/plugin-jira-dashboard-backend': minor
---

Updated the resolveUserEmailSuffix function to return an empty string if the Jira user email suffix configuration is missing, preventing failures and providing better error logging.

Modified the retrieval of project keys in the router module to handle multiple project keys specified in annotations, allowing for proper parsing and support for comma-separated values.
4 changes: 3 additions & 1 deletion plugins/jira-dashboard-backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ 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}`);
console.error(`Invalid Jira user path, ${error}`);
// Return an empty string as the default value
return '';
}
}

Expand Down
20 changes: 10 additions & 10 deletions plugins/jira-dashboard-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ 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 +118,11 @@ 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,20 +149,20 @@ 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(',') ?? [];

/* Adding support for Roadie's component annotation */
components = components.concat(
entity.metadata.annotations?.[componentRoadieAnnotation]?.split(',') ??
[],
[],
);

if (components) {
const componentIssues = await getIssuesFromComponents(
projectKey,
projectKey[0],
components,
config,
);
Expand Down Expand Up @@ -194,18 +194,18 @@ 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 afe270b

Please sign in to comment.