Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Improvements

- Added support for Rovo Dev /usage command
- Add saving of last chosen issue type

### Bug Fixes

Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1329,9 +1329,9 @@
"description": "Shows active Jira issue key in the status bar",
"scope": "window"
},
"atlascode.jira.lastCreateSiteAndProject": {
"atlascode.jira.lastCreatePreSelectedValues": {
"type": "object",
"description": "the last used site id and project key for create issue",
"description": "the last used site id, project key, and issue type id for create issue",
"scope": "window",
"properties": {
"siteId": {
Expand All @@ -1341,6 +1341,10 @@
"projectKey": {
"type": "string",
"default": ""
},
"issueTypeId": {
"type": "string",
"default": ""
}
}
},
Expand Down
19 changes: 9 additions & 10 deletions src/config/configuration.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ConfigurationChangeEvent, ExtensionContext, workspace } from 'vscode';

import { ConfigNamespace, JiraCreateSiteAndProjectKey } from '../constants';
import { ConfigNamespace, JiraPreSelectedCreateKey } from '../constants';
import { Configuration, configuration } from './configuration';
import { SiteIdAndProjectKey } from './model';
import { LastCreatePreSelectedValues } from './model';

// Mock vscode module
jest.mock('vscode', () => ({
Expand Down Expand Up @@ -156,22 +156,21 @@ describe('Configuration', () => {
});

it('should call updateEffective with correct parameters', async () => {
const siteAndProject: SiteIdAndProjectKey = { siteId: 'site1', projectKey: 'PROJ' };
const siteAndProject: LastCreatePreSelectedValues = {
siteId: 'site1',
projectKey: 'PROJ',
issueTypeId: '',
};

await config.setLastCreateSiteAndProject(siteAndProject);

expect(config.updateEffective).toHaveBeenCalledWith(
JiraCreateSiteAndProjectKey,
siteAndProject,
null,
true,
);
expect(config.updateEffective).toHaveBeenCalledWith(JiraPreSelectedCreateKey, siteAndProject, null, true);
});

it('should handle undefined siteAndProject', async () => {
await config.setLastCreateSiteAndProject(undefined);

expect(config.updateEffective).toHaveBeenCalledWith(JiraCreateSiteAndProjectKey, undefined, null, true);
expect(config.updateEffective).toHaveBeenCalledWith(JiraPreSelectedCreateKey, undefined, null, true);
});
});
});
8 changes: 4 additions & 4 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
workspace,
} from 'vscode';

import { ConfigNamespace, JiraCreateSiteAndProjectKey } from '../constants';
import { SiteIdAndProjectKey } from './model';
import { ConfigNamespace, JiraPreSelectedCreateKey } from '../constants';
import { LastCreatePreSelectedValues } from './model';

/*
Configuration is a helper to manage configuration changes in various parts of the system.
Expand Down Expand Up @@ -108,8 +108,8 @@ export class Configuration extends Disposable {
.update(section, value, target);
}

async setLastCreateSiteAndProject(siteAndProject?: SiteIdAndProjectKey) {
await this.updateEffective(JiraCreateSiteAndProjectKey, siteAndProject, null, true);
async setLastCreateSiteAndProject(siteAndProject?: LastCreatePreSelectedValues) {
await this.updateEffective(JiraPreSelectedCreateKey, siteAndProject, null, true);
}

// this tries to figure out where the current value is set and update it there
Expand Down
7 changes: 4 additions & 3 deletions src/config/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface RovoDevConfig {

export interface JiraConfig {
enabled: boolean;
lastCreateSiteAndProject: SiteIdAndProjectKey;
lastCreatePreSelectedValues: LastCreatePreSelectedValues;
explorer: JiraExplorer;
issueMonitor: JiraIssueMonitor;
statusbar: JiraStatusBar;
Expand All @@ -63,9 +63,10 @@ export interface JiraConfig {
showCreateIssueProblems: boolean;
}

export type SiteIdAndProjectKey = {
export type LastCreatePreSelectedValues = {
siteId: string;
projectKey: string;
issueTypeId: string;
};

export interface JiraStatusBar {
Expand Down Expand Up @@ -207,7 +208,7 @@ const emptyStartWorkBranchTemplate: StartWorkBranchTemplate = {

const emptyJiraConfig: JiraConfig = {
enabled: true,
lastCreateSiteAndProject: { siteId: '', projectKey: '' },
lastCreatePreSelectedValues: { siteId: '', projectKey: '', issueTypeId: '' },
explorer: emptyJiraExplorer,
issueMonitor: emtpyIssueMonitor,
statusbar: emptyJiraStatusBar,
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const ExtensionId = 'atlassian.atlascode';
export const ConfigNamespace = 'atlascode';
export const extensionOutputChannelName = 'Atlassian';
export const JiraCreateSiteAndProjectKey = 'jira.lastCreateSiteAndProject';
export const JiraPreSelectedCreateKey = 'jira.lastCreatePreSelectedValues';
export const JiraEnabledKey = 'jira.enabled';
export const BitbucketEnabledKey = 'bitbucket.enabled';
export const JiraHoverProviderConfigurationKey = 'jira.hover.enabled';
Expand Down
4 changes: 3 additions & 1 deletion src/siteManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ describe('SiteManager', () => {
},
config: {
jira: {
lastCreateSiteAndProject: {
lastCreatePreSelectedValues: {
siteId: 'site1',
projectKey: '',
issueTypeId: '',
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/siteManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class SiteManager extends Disposable {
});
}

if (deletedSite.id === Container.config.jira.lastCreateSiteAndProject.siteId) {
if (deletedSite.id === Container.config.jira.lastCreatePreSelectedValues.siteId) {
configuration.setLastCreateSiteAndProject(undefined);
}

Expand Down
16 changes: 12 additions & 4 deletions src/webviews/createIssueWebview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ jest.mock('../container', () => ({
},
config: {
jira: {
lastCreateSiteAndProject: {
lastCreatePreSelectedValues: {
siteId: '',
projectKey: '',
issueTypeId: '',
},
showCreateIssueProblems: false,
},
Expand Down Expand Up @@ -1095,11 +1096,12 @@ describe('CreateIssueWebview', () => {
});
});

describe('Should correctly set site and project (updateSiteAndProject)', () => {
describe('Should correctly set site, project and issueTypeId (updateSiteAndProject)', () => {
beforeEach(() => {
Container.config.jira.lastCreateSiteAndProject = {
Container.config.jira.lastCreatePreSelectedValues = {
siteId: '',
projectKey: '',
issueTypeId: '',
};
jest.spyOn(SearchJiraHelper, 'getAssignedIssuesPerSite').mockReturnValue([]);
});
Expand All @@ -1108,9 +1110,10 @@ describe('CreateIssueWebview', () => {
const lastUsedSiteId = 'last-used-site';
const lastUsedProjectKey = 'last-used-project';

Container.config.jira.lastCreateSiteAndProject = {
Container.config.jira.lastCreatePreSelectedValues = {
siteId: lastUsedSiteId,
projectKey: lastUsedProjectKey,
issueTypeId: '',
};

Container.siteManager.getSiteForId = jest.fn().mockReturnValue({
Expand All @@ -1126,6 +1129,7 @@ describe('CreateIssueWebview', () => {
expect(configuration.setLastCreateSiteAndProject).toHaveBeenCalledWith({
siteId: lastUsedSiteId,
projectKey: lastUsedProjectKey,
issueTypeId: '',
});
});

Expand Down Expand Up @@ -1158,6 +1162,7 @@ describe('CreateIssueWebview', () => {
expect(configuration.setLastCreateSiteAndProject).toHaveBeenCalledWith({
siteId: maxIssuesSite.id,
projectKey: maxIssuesProject.key,
issueTypeId: '',
});
});

Expand All @@ -1174,6 +1179,7 @@ describe('CreateIssueWebview', () => {
expect(configuration.setLastCreateSiteAndProject).toHaveBeenCalledWith({
siteId: 'first-site',
projectKey: 'first-project',
issueTypeId: '',
});
});

Expand All @@ -1195,6 +1201,7 @@ describe('CreateIssueWebview', () => {
expect(configuration.setLastCreateSiteAndProject).toHaveBeenLastCalledWith({
projectKey: inputProject.key,
siteId: 'site-1',
issueTypeId: 'issueType-1',
});
});

Expand All @@ -1216,6 +1223,7 @@ describe('CreateIssueWebview', () => {
expect(configuration.setLastCreateSiteAndProject).toHaveBeenLastCalledWith({
siteId: inputSite.id,
projectKey: 'TEST',
issueTypeId: 'issueType-1',
});
});
});
Expand Down
23 changes: 20 additions & 3 deletions src/webviews/createIssueWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class CreateIssueWebview
if (inputSite) {
this._siteDetails = inputSite;
} else {
let siteId = Container.config.jira.lastCreateSiteAndProject.siteId;
let siteId = Container.config.jira.lastCreatePreSelectedValues.siteId;
if (!siteId) {
siteId = '';
}
Expand All @@ -281,7 +281,7 @@ export class CreateIssueWebview
} else if (inputProject) {
this._currentProject = inputProject;
} else {
let projectKey = Container.config.jira.lastCreateSiteAndProject.projectKey;
let projectKey = Container.config.jira.lastCreatePreSelectedValues.projectKey;
if (!projectKey) {
projectKey = '';
}
Expand All @@ -304,6 +304,7 @@ export class CreateIssueWebview
await configuration.setLastCreateSiteAndProject({
siteId: this._siteDetails.id,
projectKey: this._currentProject!.key,
issueTypeId: this._selectedIssueTypeId || '',
});

if (this._todoData) {
Expand Down Expand Up @@ -482,6 +483,13 @@ export class CreateIssueWebview
this._screenData = screenData;
this._selectedIssueTypeId = this._screenData.selectedIssueType.id;

if (this._currentProject) {
const savedIssueTypeId = Container.config.jira.lastCreatePreSelectedValues.issueTypeId;
if (savedIssueTypeId && this._screenData.issueTypeUIs[savedIssueTypeId]) {
this._selectedIssueTypeId = savedIssueTypeId;
}
}

if (fieldValues) {
const overrides = this.getValuesForExisitngKeys(
this._screenData.issueTypeUIs[this._selectedIssueTypeId],
Expand Down Expand Up @@ -570,6 +578,14 @@ export class CreateIssueWebview
this._screenData.issueTypeUIs[issueType.id].fieldValues['issuetype'] = issueType;
this._selectedIssueTypeId = issueType.id;

if (this._currentProject) {
configuration.setLastCreateSiteAndProject({
siteId: this._siteDetails.id,
projectKey: this._currentProject.key,
issueTypeId: issueType.id,
});
}

const createData: CreateIssueData = this._screenData.issueTypeUIs[this._selectedIssueTypeId] as CreateIssueData;
createData.type = 'update';
createData.transformerProblems = Container.config.jira.showCreateIssueProblems ? this._screenData.problems : {};
Expand Down Expand Up @@ -794,11 +810,12 @@ export class CreateIssueWebview
handled = true;
if (isCreateIssue(msg)) {
try {
const [payload, worklog, issuelinks, attachments] = this.formatCreatePayload(msg);
await configuration.setLastCreateSiteAndProject({
siteId: this._siteDetails.id,
projectKey: this._currentProject!.key,
issueTypeId: payload.issuetype?.id || this._selectedIssueTypeId,
});
const [payload, worklog, issuelinks, attachments] = this.formatCreatePayload(msg);

// Handle parent payload
if (this._siteDetails.isCloud && payload.parent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class CreateWorkItemWebviewProvider extends Disposable implements Webview

this._availableSites = this.toFieldMap(allSites);

const selectedSiteAndProject = Container.config.jira.lastCreateSiteAndProject;
const selectedSiteAndProject = Container.config.jira.lastCreatePreSelectedValues;

const selectedSite =
this._availableSites[selectedSiteAndProject.siteId] ||
Expand Down Expand Up @@ -454,6 +454,7 @@ export class CreateWorkItemWebviewProvider extends Disposable implements Webview
await configuration.setLastCreateSiteAndProject({
siteId: this._selectedSite!.id,
projectKey: this._selectedProject!.key,
issueTypeId: this._selectedIssueType?.id || '',
});
const payload = {
summary: message.payload.summary,
Expand Down Expand Up @@ -511,7 +512,7 @@ export class CreateWorkItemWebviewProvider extends Disposable implements Webview
'create',
);

const lastCreateSiteAndProject = Container.config.jira.lastCreateSiteAndProject;
const lastCreateSiteAndProject = Container.config.jira.lastCreatePreSelectedValues;
const selectedProject =
projects.projects.find((p) => p.key === lastCreateSiteAndProject.projectKey) || projects.projects[0];

Expand Down
Loading