2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { Limiter } from '../../../base/common/async.js';
7
>
import { Disposable } from '../../../base/common/lifecycle.js';
8
>
import { relativePath } from '../../../base/common/resources.js';
9
>
import { URI } from '../../../base/common/uri.js';
10
>
import { ILogService } from '../../log/common/log.js';
11
>
import { IAgentHostGitService } from '../common/agentHostGitService.js';
12
>
import type { ISessionFileDiff } from '../common/state/sessionState.js';
13
>
import { IAgentHostGitHubEndpointService } from './agentHostGitHubEndpointService.js';
14
>
import type { AgentHostRepoInfoResult, AgentHostTelemetryReporter } from './agentHostTelemetryReporter.js';
15
>
import type { IAgentHostRestrictedTelemetryContext } from './agentHostRestrictedTelemetry.js';
16
>
17
>
const MAX_DIFFS_JSON_BYTES = 900 * 1024;
18
>
const MAX_DIFFS_JSON_CHARS = 50 * 8192;
19
>
const MAX_CHANGES = 100;
20
>
const MAX_MERGE_BASE_AGE_MS = 30 * 24 * 60 * 60 * 1000;
21
>
const MAX_DIFF_COMMITS = 30;
22
>
const DIFF_PATCH_CONCURRENCY = 4;
23
>
const MAX_DIFF_SIZE = 100_000;
24
>
25
>
interface IRepoInfoContext extends IResolvedRepoInfoRemote {
26
>
readonly headCommitHash: string;
27
>
readonly headBranchName: string | undefined;
28
>
}
29
>
30
>
interface IRepoInfoFileDescriptor {
31
>
readonly uri: string;
32
>
readonly originalUri: string;
33
>
readonly renameUri: string | undefined;
34
>
readonly status: 'INDEX_ADDED' | 'MODIFIED' | 'DELETED' | 'INDEX_RENAMED' | 'UNTRACKED';
35
>
readonly oldPath: string | undefined;
36
>
readonly newPath: string | undefined;
37
>
}
38
>
39
>
type RepoInfoTelemetryReporter = Pick<AgentHostTelemetryReporter, 'reportRepoInfo'>;
40
>
41
>
export interface IResolvedRepoInfoRemote {
42
>
readonly remoteUrl: string;
43
>
readonly repoId: string;
44
>
readonly repoType: 'github' | 'ado';
45
>
}
46
>
47
>
/** Resolves a GitHub, GitHub Enterprise, or Azure DevOps fetch URL. */
48
>
export function resolveRepoInfoRemote(remoteUrl: string, enterpriseHost: string | undefined): IResolvedRepoInfoRemote | undefined {
49
const scpMatch = remoteUrl.includes('://') ? undefined : /^(?:[^@\s]+@)?(?<host>[^:\s]+):(?<path>.+)$/.exec(remoteUrl);
50
let host: string;