private async getBranchDeletionItems()

in src/github/folderRepositoryManager.ts [1444:1536]


	private async getBranchDeletionItems() {
		const allConfigs = await this.repository.getConfigs();
		const branchInfos: Map<string, { remote?: string; metadata?: PullRequestMetadata }> = new Map();

		allConfigs.forEach(config => {
			const key = config.key;
			const matches = /^branch\.(.*)\.(.*)$/.exec(key);

			if (matches && matches.length === 3) {
				const branchName = matches[1];

				if (!branchInfos.has(branchName)) {
					branchInfos.set(branchName, {});
				}

				const value = branchInfos.get(branchName);
				if (matches[2] === 'remote') {
					value!['remote'] = config.value;
				}

				if (matches[2] === 'github-pr-owner-number') {
					const metadata = PullRequestGitHelper.parsePullRequestMetadata(config.value);
					value!['metadata'] = metadata;
				}

				branchInfos.set(branchName, value!);
			}
		});

		const actions: (vscode.QuickPickItem & { metadata: PullRequestMetadata; legacy?: boolean })[] = [];
		branchInfos.forEach((value, key) => {
			if (value.metadata) {
				const activePRUrl = this.activePullRequest && this.activePullRequest.base.repositoryCloneUrl;
				const matchesActiveBranch = activePRUrl
					? activePRUrl.owner === value.metadata.owner &&
					activePRUrl.repositoryName === value.metadata.repositoryName &&
					this.activePullRequest &&
					this.activePullRequest.number === value.metadata.prNumber
					: false;

				if (!matchesActiveBranch) {
					actions.push({
						label: `${key}`,
						description: `${value.metadata!.repositoryName}/${value.metadata!.owner} #${value.metadata.prNumber
							}`,
						picked: false,
						metadata: value.metadata!,
					});
				}
			}
		});

		const results = await Promise.all(
			actions.map(async action => {
				const metadata = action.metadata;
				const githubRepo = this._githubRepositories.find(
					repo =>
						repo.remote.owner.toLowerCase() === metadata!.owner.toLowerCase() &&
						repo.remote.repositoryName.toLowerCase() === metadata!.repositoryName.toLowerCase(),
				);

				if (!githubRepo) {
					return action;
				}

				const { remote, query, schema } = await githubRepo.ensure();
				try {
					const { data } = await query<PullRequestState>({
						query: schema.PullRequestState,
						variables: {
							owner: remote.owner,
							name: remote.repositoryName,
							number: metadata!.prNumber,
						},
					});

					action.legacy = data.repository.pullRequest.state !== 'OPEN';
				} catch { }

				return action;
			}),
		);

		results.forEach(result => {
			if (result.legacy) {
				result.picked = true;
			} else {
				result.description = `${result.description} is still Open`;
			}
		});

		return results;
	}