Skip to content

Commit c7900ec

Browse files
Associates branch with issue when created from Start Work
1 parent 7dfc857 commit c7900ec

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/commands/git/branch.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { QuickInputButtons } from 'vscode';
22
import type { Container } from '../../container';
3-
import { getNameWithoutRemote } from '../../git/models/branch.utils';
3+
import {
4+
addAssociatedIssueToBranch,
5+
clearAssociatedIssuesForBranch,
6+
getNameWithoutRemote,
7+
} from '../../git/models/branch.utils';
8+
import type { IssueShape } from '../../git/models/issue';
49
import type { GitBranchReference, GitReference } from '../../git/models/reference';
510
import { getReferenceLabel, isBranchReference, isRevisionReference } from '../../git/models/reference.utils';
611
import { Repository } from '../../git/models/repository';
@@ -61,6 +66,7 @@ interface CreateState {
6166
suggestNameOnly?: boolean;
6267
suggestRepoOnly?: boolean;
6368
confirmOptions?: CreateFlags[];
69+
withIssue?: IssueShape;
6470
}
6571

6672
function isCreateState(state: Partial<State> | undefined): state is Partial<CreateState> {
@@ -415,6 +421,25 @@ export class BranchGitCommand extends QuickCommand {
415421
}
416422

417423
endSteps(state);
424+
425+
if (state.withIssue != null) {
426+
const issue = state.withIssue;
427+
const branch = await state.repo.git.getBranch(state.name);
428+
// TODO: These descriptors are hacked in. Use an integration function to get the right resource for the issue.
429+
const resource = issue.repository
430+
? {
431+
key: `${issue.repository.owner}/${issue.repository.repo}`,
432+
owner: issue.repository.owner,
433+
name: issue.repository.repo,
434+
}
435+
: issue.project
436+
? { key: issue.project.resourceId, id: issue.project.resourceId, name: issue.project.resourceId }
437+
: undefined;
438+
if (branch != null && resource != null) {
439+
await addAssociatedIssueToBranch(this.container, branch, { ...issue, type: 'issue' }, resource);
440+
}
441+
}
442+
418443
if (state.flags.includes('--switch')) {
419444
await state.repo.switch(state.reference.ref, { createBranch: state.name });
420445
} else {
@@ -558,6 +583,11 @@ export class BranchGitCommand extends QuickCommand {
558583
force: state.flags.includes('--force'),
559584
remote: state.flags.includes('--remotes'),
560585
});
586+
587+
// Clean up any associated issue entries for the branches stored in the git config
588+
for (const ref of state.references) {
589+
await clearAssociatedIssuesForBranch(this.container, ref);
590+
}
561591
}
562592
}
563593

src/plus/startWork/startWork.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export class StartWorkCommand extends QuickCommand<State> {
225225
suggestNameOnly: true,
226226
suggestRepoOnly: true,
227227
confirmOptions: ['--switch', '--worktree'],
228+
withIssue: issue,
228229
},
229230
},
230231
this.pickedVia,
@@ -386,7 +387,6 @@ export class StartWorkCommand extends QuickCommand<State> {
386387
return {
387388
label:
388389
i.item.issue.title.length > 60 ? `${i.item.issue.title.substring(0, 60)}...` : i.item.issue.title,
389-
// description: `${i.repoAndOwner}#${i.id}, by @${i.author}`,
390390
description: `\u00a0 ${
391391
i.item.issue.repository ? `${i.item.issue.repository.owner}/${i.item.issue.repository.repo}#` : ''
392392
}${i.item.issue.id} \u00a0`,

0 commit comments

Comments
 (0)