Allow PRs with deleted head to show in view (#6101)

* Allow PRs with deleted head to show in view
This is to better support the new revert feature

* Fix test
This commit is contained in:
Alex Ross 2024-07-22 14:49:16 +02:00 коммит произвёл GitHub
Родитель a963d76820
Коммит ab2267ca88
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
8 изменённых файлов: 15 добавлений и 16 удалений

Просмотреть файл

@ -747,6 +747,7 @@
"command": "pr.pick",
"title": "%command.pr.pick.title%",
"category": "%command.pull.request.category%",
"enablement": "viewItem =~ /hasHeadRef/",
"icon": "$(arrow-right)"
},
{

Просмотреть файл

@ -2047,11 +2047,7 @@ export class FolderRepositoryManager implements vscode.Disposable {
if (githubRepo) {
const pr = await githubRepo.getPullRequest(pullRequestNumber);
Logger.appendLine(`Found GitHub pr repo for pr #${pullRequestNumber}: ${pr ? 'yes' : 'no'}`, this.id);
if (pr) {
if (await githubRepo.hasBranch(pr.base.name)) {
return pr;
}
}
return pr;
}
return undefined;
}

Просмотреть файл

@ -912,8 +912,8 @@ export class GitHubRepository implements vscode.Disposable {
const pullRequests = pullRequestResponses
.map(response => {
if (!response.repository?.pullRequest.headRef) {
Logger.appendLine('The remote branch for this PR was already deleted.', this.id);
if (!response.repository) {
Logger.appendLine('Pull request doesn\'t appear to exist.', this.id);
return null;
}
@ -1542,7 +1542,7 @@ export class GitHubRepository implements vscode.Disposable {
};
let reviewRequirement: PullRequestReviewRequirement | null = null;
const rule = result.data.repository.pullRequest.baseRef.refUpdateRule;
const rule = result.data.repository.pullRequest.baseRef?.refUpdateRule;
if (rule) {
const prUrl = result.data.repository.pullRequest.url;

Просмотреть файл

@ -903,7 +903,7 @@ export interface GetChecksResponse {
requiresCodeOwnerReviews: boolean;
viewerCanPush: boolean;
} | null;
};
} | null;
commits: {
nodes: {
commit: {

Просмотреть файл

@ -210,14 +210,14 @@ describe('GitHub Pull Requests view', function () {
assert.strictEqual(localItem0.tooltip, 'zero by @me');
assert.strictEqual(localItem0.description, 'by @me');
assert.strictEqual(localItem0.collapsibleState, vscode.TreeItemCollapsibleState.Collapsed);
assert.strictEqual(localItem0.contextValue, 'pullrequest:local:nonactive');
assert.strictEqual(localItem0.contextValue, 'pullrequest:local:nonactive:hasHeadRef');
assert.deepStrictEqual(localItem0.iconPath!.toString(), 'https://avatars.com/me.jpg');
assert.strictEqual(localItem1.label, '✓ one');
assert.strictEqual(localItem1.tooltip, 'Current Branch * one by @you');
assert.strictEqual(localItem1.description, 'by @you');
assert.strictEqual(localItem1.collapsibleState, vscode.TreeItemCollapsibleState.Collapsed);
assert.strictEqual(localItem1.contextValue, 'pullrequest:local:active');
assert.strictEqual(localItem1.contextValue, 'pullrequest:local:active:hasHeadRef');
assert.deepStrictEqual(localItem1.iconPath!.toString(), 'https://avatars.com/you.jpg');
});
});

Просмотреть файл

@ -389,9 +389,9 @@ export class ReviewManager {
const { owner, repositoryName } = metadata;
Logger.appendLine('Resolving pull request', this.id);
const pr = await this._folderRepoManager.resolvePullRequest(owner, repositoryName, metadata.prNumber);
let pr = await this._folderRepoManager.resolvePullRequest(owner, repositoryName, metadata.prNumber);
if (!pr || !pr.isResolved()) {
if (!pr || !pr.isResolved() || !(await pr.githubRepository.hasBranch(pr.base.name))) {
await this.clear(true);
this._prNumber = undefined;
Logger.appendLine('This PR is no longer valid', this.id);
@ -954,7 +954,7 @@ export class ReviewManager {
vscode.window.showErrorMessage(formatError(e));
}
// todo, we should try to recover, for example, git checkout succeeds but set config fails.
if (this._folderRepoManager.activePullRequest) {
if (this._folderRepoManager.activePullRequest?.number === pr.number) {
this.setStatusForPr(this._folderRepoManager.activePullRequest);
} else {
this.statusBarItem.hide();

Просмотреть файл

@ -44,6 +44,7 @@ export class DescriptionNode extends TreeNode implements vscode.TreeItem {
this.contextValue = 'description' +
(currentBranchIsForThisPR ? ':active' : ':nonactive') +
(this.pullRequestModel.hasChangesSinceLastReview ? ':hasChangesSinceReview' : '') +
(this.pullRequestModel.showChangesSinceReview ? ':showingChangesSinceReview' : ':showingAllChanges');
(this.pullRequestModel.showChangesSinceReview ? ':showingChangesSinceReview' : ':showingAllChanges') +
(this.pullRequestModel.item.isRemoteHeadDeleted ? '' : ':hasHeadRef');
}
}

Просмотреть файл

@ -313,7 +313,8 @@ export class PRNode extends TreeNode implements vscode.CommentingRangeProvider2
'pullrequest' +
(this._isLocal ? ':local' : '') +
(currentBranchIsForThisPR ? ':active' : ':nonactive') +
(hasNotification ? ':notification' : ''),
(hasNotification ? ':notification' : '') +
(this.pullRequestModel.item.isRemoteHeadDeleted ? '' : ':hasHeadRef'),
iconPath: (await DataUri.avatarCirclesAsImageDataUris(this._folderReposManager.context, [this.pullRequestModel.author], 16, 16))[0]
?? new vscode.ThemeIcon('github'),
accessibilityInformation: {