| 
1 | 1 | import { QuickInputButtons } from 'vscode';  | 
2 | 2 | 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';  | 
4 | 9 | import type { GitBranchReference, GitReference } from '../../git/models/reference';  | 
5 | 10 | import { getReferenceLabel, isBranchReference, isRevisionReference } from '../../git/models/reference.utils';  | 
6 | 11 | import { Repository } from '../../git/models/repository';  | 
@@ -61,6 +66,7 @@ interface CreateState {  | 
61 | 66 | 	suggestNameOnly?: boolean;  | 
62 | 67 | 	suggestRepoOnly?: boolean;  | 
63 | 68 | 	confirmOptions?: CreateFlags[];  | 
 | 69 | +	withIssue?: IssueShape;  | 
64 | 70 | }  | 
65 | 71 | 
 
  | 
66 | 72 | function isCreateState(state: Partial<State> | undefined): state is Partial<CreateState> {  | 
@@ -415,6 +421,25 @@ export class BranchGitCommand extends QuickCommand {  | 
415 | 421 | 			}  | 
416 | 422 | 
 
  | 
417 | 423 | 			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 | + | 
418 | 443 | 			if (state.flags.includes('--switch')) {  | 
419 | 444 | 				await state.repo.switch(state.reference.ref, { createBranch: state.name });  | 
420 | 445 | 			} else {  | 
@@ -558,6 +583,11 @@ export class BranchGitCommand extends QuickCommand {  | 
558 | 583 | 				force: state.flags.includes('--force'),  | 
559 | 584 | 				remote: state.flags.includes('--remotes'),  | 
560 | 585 | 			});  | 
 | 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 | +			}  | 
561 | 591 | 		}  | 
562 | 592 | 	}  | 
563 | 593 | 
 
  | 
 | 
0 commit comments