Skip to content

Commit eaab56f

Browse files
authored
Error notifications when using GitHub Enterprise Server (#7902)
* Error notifications when using GitHub Enterprise Server Fixes #7901 * lint error
1 parent e317a8d commit eaab56f

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/github/folderRepositoryManager.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { ConflictModel } from './conflictGuide';
4343
import { ConflictResolutionCoordinator } from './conflictResolutionCoordinator';
4444
import { Conflict, ConflictResolutionModel } from './conflictResolutionModel';
4545
import { CredentialStore } from './credentials';
46-
import { CopilotWorkingStatus, GitHubRepository, GraphQLError, GraphQLErrorType, IMetadata, ItemsData, PULL_REQUEST_PAGE_SIZE, PullRequestChangeEvent, PullRequestData, TeamReviewerRefreshKind, ViewerPermission } from './githubRepository';
46+
import { CopilotWorkingStatus, GitHubRepository, GraphQLError, GraphQLErrorType, ItemsData, PULL_REQUEST_PAGE_SIZE, PullRequestChangeEvent, PullRequestData, TeamReviewerRefreshKind, ViewerPermission } from './githubRepository';
4747
import { MergeMethod as GraphQLMergeMethod, MergePullRequestInput, MergePullRequestResponse, PullRequestResponse, PullRequestState } from './graphql';
4848
import { IAccount, ILabel, IMilestone, IProject, IPullRequestsPagingOptions, Issue, ITeam, MergeMethod, PRType, PullRequestMergeability, RepoAccessAndMergeMethods, User } from './interface';
4949
import { IssueModel } from './issueModel';
@@ -1177,7 +1177,6 @@ export class FolderRepositoryManager extends Disposable {
11771177
}
11781178

11791179
async getPullRequestsForCategory(githubRepository: GitHubRepository, categoryQuery: string, page?: number): Promise<PullRequestData | undefined> {
1180-
let repo: IMetadata | undefined;
11811180
try {
11821181
Logger.debug(`Fetch pull request category ${categoryQuery} - enter`, this.id);
11831182
const { octokit, query, schema } = await githubRepository.ensure();
@@ -1189,8 +1188,6 @@ export class FolderRepositoryManager extends Disposable {
11891188
this.telemetry.sendTelemetryEvent('pr.search.category');
11901189

11911190
const user = (await githubRepository.getAuthenticatedUser()).login;
1192-
// Search api will not try to resolve repo that redirects, so get full name first
1193-
repo = await githubRepository.getMetadata();
11941191
const { data, headers } = await octokit.call(octokit.api.search.issuesAndPullRequests, {
11951192
q: getPRFetchQuery(user, categoryQuery),
11961193
per_page: PULL_REQUEST_PAGE_SIZE,
@@ -1243,7 +1240,7 @@ export class FolderRepositoryManager extends Disposable {
12431240
if (e.status === 404) {
12441241
// not found
12451242
vscode.window.showWarningMessage(
1246-
`Fetching pull requests for remote ${githubRepository.remote.remoteName} with query failed, please check if the repo ${repo?.full_name} is valid.`,
1243+
`Fetching pull requests for remote ${githubRepository.remote.remoteName} with query failed, please check if the repo ${githubRepository.remote.owner}/${githubRepository.remote.repositoryName} is valid.`,
12471244
);
12481245
} else {
12491246
throw e;

src/view/treeNodes/categoryNode.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,17 +291,21 @@ export class CategoryTreeNode extends TreeNode implements vscode.TreeItem {
291291
hasMorePages = response.hasMorePages;
292292
hasUnsearchedRepositories = response.hasUnsearchedRepositories;
293293
} catch (e) {
294-
const error = formatError(e);
295-
const actions: string[] = [];
296-
if (error.includes('Bad credentials')) {
297-
actions.push(vscode.l10n.t('Login again'));
298-
}
299-
vscode.window.showErrorMessage(vscode.l10n.t('Fetching pull requests failed: {0}', formatError(e)), ...actions).then(action => {
300-
if (action && action === actions[0]) {
301-
this.folderRepoManager.credentialStore.recreate(vscode.l10n.t('Your login session is no longer valid.'));
294+
if (this.isCopilot && (e.response.status === 422) && e.message.includes('the users do not exist')) {
295+
// Skip it, it's copilot and the repo doesn't have copilot
296+
} else {
297+
const error = formatError(e);
298+
const actions: string[] = [];
299+
if (error.includes('Bad credentials')) {
300+
actions.push(vscode.l10n.t('Login again'));
302301
}
303-
});
304-
needLogin = e instanceof AuthenticationError;
302+
vscode.window.showErrorMessage(vscode.l10n.t('Fetching pull requests failed: {0}', formatError(e)), ...actions).then(action => {
303+
if (action && action === actions[0]) {
304+
this.folderRepoManager.credentialStore.recreate(vscode.l10n.t('Your login session is no longer valid.'));
305+
}
306+
});
307+
needLogin = e instanceof AuthenticationError;
308+
}
305309
}
306310
}
307311

0 commit comments

Comments
 (0)