Skip to content

Commit

Permalink
feat(jira-backend): export the JiraConfig class (AxisCommunications#217)
Browse files Browse the repository at this point in the history
This is needed to be able to use the exported searchJira function
in other backend plugins since the jira config instance is now
an argument.

Co-authored-by: Niklas Aronsson <[email protected]>
Co-authored-by: Frida Jacobsson <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 31d12ef commit 1b47182
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/grumpy-cups-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@axis-backstage/plugin-jira-dashboard-backend': patch
---

The backend now exports the `JiraConfig` class. This is needed to create config
instances for the `searchJira`function.
12 changes: 12 additions & 0 deletions plugins/jira-dashboard-backend/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
```ts
import { BackendFeatureCompat } from '@backstage/backend-plugin-api';
import { JiraQueryResults } from '@axis-backstage/plugin-jira-dashboard-common';
import { RootConfigService } from '@backstage/backend-plugin-api';

// @public
export type ConfigInstance = {
Expand All @@ -14,6 +15,17 @@ export type ConfigInstance = {
userEmailSuffix?: string;
};

// @public
export class JiraConfig {
readonly annotationPrefix: string;
static fromConfig(config: RootConfigService): JiraConfig;
getInstance(instanceName?: string): ConfigInstance;
getInstances(): string[];
resolveJiraBaseUrl(instanceName: string): string;
resolveJiraToken(instanceName: string): string;
resolveUserEmailSuffix(instanceName: string): string | undefined;
}

// @public
const jiraDashboardPlugin: BackendFeatureCompat;
export default jiraDashboardPlugin;
Expand Down
26 changes: 26 additions & 0 deletions plugins/jira-dashboard-backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ const JIRA_CONFIG_HEADERS = 'headers';
const JIRA_CONFIG_USER_EMAIL_SUFFIX = 'userEmailSuffix';
const JIRA_CONFIG_ANNOTATION = 'annotationPrefix';

/**
* Class for reading Jira configuration from the root config
*
* @public
*/
export class JiraConfig {
private instances: Record<string, ConfigInstance> = {};
/**
* The annotation prefix to use for Jira annotations
*/
public readonly annotationPrefix: string;

private constructor(config: RootConfigService) {
Expand Down Expand Up @@ -74,6 +82,9 @@ export class JiraConfig {
}
}

/**
* Create a JiraConfig from the root config
*/
public static fromConfig(config: RootConfigService): JiraConfig {
return new JiraConfig(config);
}
Expand All @@ -88,24 +99,39 @@ export class JiraConfig {
return instance;
}

/**
* Returns the configuration all instances
*/
getInstances() {
return Object.getOwnPropertyNames(this.instances);
}

/**
* Get the jira config for a specific instance
*/
getInstance(instanceName?: string): ConfigInstance {
return this.forInstance(instanceName ?? 'default');
}

/**
* Get the jira base url for a given instance
*/
resolveJiraBaseUrl(instanceName: string): string {
const instance = this.forInstance(instanceName);
return instance.baseUrl;
}

/**
* Get the auth token for a given instance
*/
resolveJiraToken(instanceName: string): string {
const instance = this.forInstance(instanceName);
return instance.token;
}

/**
* Get the email suffice for a given instance
*/
resolveUserEmailSuffix(instanceName: string): string | undefined {
const instance = this.forInstance(instanceName);
return instance.userEmailSuffix;
Expand Down
1 change: 1 addition & 0 deletions plugins/jira-dashboard-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export { jiraDashboardPlugin as default } from './plugin';
export { searchJira } from './api';
export type { SearchOptions } from './api';
export type { ConfigInstance } from './config';
export { JiraConfig } from './config';
export { jqlQueryBuilder } from './queries';
export type { JqlQueryBuilderArgs } from './queries';

0 comments on commit 1b47182

Please sign in to comment.