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
25 changes: 15 additions & 10 deletions src/issues/currentIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ export class CurrentIssue {
return this.issueModel;
}

public async startWorking() {
public async startWorking(): Promise<boolean> {
try {
this.repoDefaults = await this.manager.getPullRequestDefaults();
if (await this.createIssueBranch()) {
await this.setCommitMessageAndGitEvent();
this.setStatusBar();
return true;
}
} catch (e) {
// leave repoDefaults undefined
vscode.window.showErrorMessage('There is no remote. Can\'t start working on an issue.');
}
await this.createIssueBranch();
await this.setCommitMessageAndGitEvent();
this.setStatusBar();
return false;
}

public dispose() {
Expand Down Expand Up @@ -126,30 +129,32 @@ export class CurrentIssue {
return vscode.workspace.getConfiguration(ISSUES_CONFIGURATION).get<string>(BRANCH_NAME_CONFIGURATION) ?? this.getBasicBranchName(await this.getUser());
}

private async createIssueBranch(): Promise<void> {
private async createIssueBranch(): Promise<boolean> {
const createBranchConfig = this.shouldPromptForBranch ? 'prompt' : <string>vscode.workspace.getConfiguration(ISSUES_CONFIGURATION).get(BRANCH_CONFIGURATION);
if (createBranchConfig === 'off') {
return;
return true;
}
const state: IssueState = this.stateManager.getSavedIssueState(this.issueModel.number);
this._branchName = this.shouldPromptForBranch ? undefined : state.branch;
if (!this._branchName) {
const branchNameConfig = await variableSubstitution(await this.ensureBranchTitleConfigMigrated(), this.issue, undefined, await this.getUser());
if (createBranchConfig === 'on') {
const branchNameConfig = await this.ensureBranchTitleConfigMigrated();
this._branchName = await variableSubstitution(branchNameConfig, this.issue, undefined, await this.getUser());
this._branchName = branchNameConfig;
} else {
this._branchName = await vscode.window.showInputBox({ placeHolder: `issue${this.issueModel.number}`, prompt: 'Enter the label for the new branch.' });
this._branchName = await vscode.window.showInputBox({ value: branchNameConfig, prompt: 'Enter the label for the new branch.' });
}
}
if (!this._branchName) {
this._branchName = this.getBasicBranchName(await this.getUser());
// user has cancelled
return false;
}

state.branch = this._branchName;
this.stateManager.setSavedIssueState(this.issueModel, state);
if (!await this.createOrCheckoutBranch(this._branchName)) {
this._branchName = undefined;
}
return true;
}

public async getCommitMessage(): Promise<string | undefined> {
Expand Down
5 changes: 3 additions & 2 deletions src/issues/stateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,9 @@ export class StateManager {
await this._currentIssue.stopWorking();
}
this.context.workspaceState.update(CURRENT_ISSUE_KEY, issue?.issue.number);
this._currentIssue = issue;
await this._currentIssue?.startWorking();
if (!issue || await issue.startWorking()) {
this._currentIssue = issue;
}
this._onDidChangeCurrentIssue.fire();
} catch (e) {
// Error has already been surfaced
Expand Down