diff --git a/.changeset/big-dogs-dance.md b/.changeset/big-dogs-dance.md new file mode 100644 index 00000000..46cd8d69 --- /dev/null +++ b/.changeset/big-dogs-dance.md @@ -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. diff --git a/plugins/jira-dashboard-backend/src/config.ts b/plugins/jira-dashboard-backend/src/config.ts index 74e040e7..c84a7381 100644 --- a/plugins/jira-dashboard-backend/src/config.ts +++ b/plugins/jira-dashboard-backend/src/config.ts @@ -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 ''; } } diff --git a/plugins/jira-dashboard-backend/src/service/router.ts b/plugins/jira-dashboard-backend/src/service/router.ts index 6f77d47e..5f8a5437 100644 --- a/plugins/jira-dashboard-backend/src/service/router.ts +++ b/plugins/jira-dashboard-backend/src/service/router.ts @@ -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}`; @@ -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; } @@ -149,7 +149,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(',') ?? []; @@ -157,12 +157,12 @@ export async function createRouter( /* 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, ); @@ -194,10 +194,10 @@ 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, ); @@ -205,7 +205,7 @@ export async function createRouter( 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; }