Skip to content

Commit 2ae17d8

Browse files
committed
Adds a start work action step that lets user to choose whether they want
just to create a branch or start working on an issue (#3621)
1 parent 7aa9d24 commit 2ae17d8

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/plus/startWork/startWork.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,20 @@ export class StartWorkCommand extends QuickCommand<State> {
133133
}
134134
}
135135

136+
const result = yield* this.selectCommandStep(state);
137+
if (result === StepResultBreak) continue;
138+
state.action = result.action;
139+
136140
await updateContextItems(this.container, context);
137141

138-
if (state.counter < 1 || state.item == null) {
142+
if (state.counter < 1 || (state.item == null && !state.action)) {
139143
const result = yield* this.pickIssueStep(state, context);
140144
if (result === StepResultBreak) continue;
141145
state.item = result;
142146
}
143147

144-
assertsStartWorkStepState(state);
145-
146148
if (state.action == null && this.confirm(state.confirm)) {
149+
assertsStartWorkStepState(state);
147150
const result = yield* this.confirmStep(state, context);
148151
if (result === StepResultBreak) {
149152
state.item = undefined!;
@@ -153,8 +156,8 @@ export class StartWorkCommand extends QuickCommand<State> {
153156
state.action = result;
154157
}
155158

156-
const issue = state.item.item.issue;
157-
const repo = await getOrOpenIssueRepository(this.container, issue);
159+
const issue = state.item?.item?.issue;
160+
const repo = issue && (await getOrOpenIssueRepository(this.container, issue));
158161

159162
if (typeof state.action === 'string') {
160163
switch (state.action) {
@@ -166,7 +169,7 @@ export class StartWorkCommand extends QuickCommand<State> {
166169
state: {
167170
subcommand: 'create',
168171
repo: repo,
169-
name: slug(`${issue.id}-${issue.title}`),
172+
name: issue ? slug(`${issue.id}-${issue.title}`) : undefined,
170173
suggestNameOnly: true,
171174
suggestRepoOnly: true,
172175
},
@@ -183,6 +186,20 @@ export class StartWorkCommand extends QuickCommand<State> {
183186
return state.counter < 0 ? StepResultBreak : undefined;
184187
}
185188

189+
private *selectCommandStep(state: StepState<State>): StepResultGenerator<{ action?: StartWorkAction }> {
190+
const step = createPickStep({
191+
placeholder: 'Start work by creating a new branch',
192+
items: [
193+
createQuickPickItemOfT('Create a branch', {
194+
action: 'start',
195+
}),
196+
createQuickPickItemOfT('Create a branch from an issue', {}),
197+
],
198+
});
199+
const selection: StepSelection<typeof step> = yield step;
200+
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResultBreak;
201+
}
202+
186203
private async *confirmLocalIntegrationConnectStep(
187204
state: StepState<State>,
188205
context: Context,

0 commit comments

Comments
 (0)