forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.ts
More file actions
192 lines (179 loc) · 9 KB
/
common.ts
File metadata and controls
192 lines (179 loc) · 9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as OctokitRest from '@octokit/rest';
import { Endpoints } from '@octokit/types';
import { DocumentNode } from 'graphql';
import { ChatSessionStatus, Uri } from 'vscode';
import { SessionInfo, SessionSetupStep } from './copilotApi';
import { FolderRepositoryManager } from './folderRepositoryManager';
import { GitHubRepository } from './githubRepository';
import { Repository } from '../api/api';
import { CopilotPRStatus } from '../common/copilot';
import { GitHubRemote } from '../common/remote';
import { EventType, TimelineEvent } from '../common/timelineEvent';
export namespace OctokitCommon {
export type IssuesAssignParams = OctokitRest.RestEndpointMethodTypes['issues']['addAssignees']['parameters'];
export type IssuesCreateParams = OctokitRest.RestEndpointMethodTypes['issues']['create']['parameters'];
export type IssuesCreateResponseData = OctokitRest.RestEndpointMethodTypes['issues']['create']['response']['data'];
export type IssuesListCommentsResponseData = OctokitRest.RestEndpointMethodTypes['issues']['listComments']['response']['data'];
export type IssuesListEventsForTimelineResponseData = Endpoints['GET /repos/{owner}/{repo}/issues/{issue_number}/timeline']['response']['data'];
export type IssuesListEventsForTimelineResponseItemActor = {
name?: string | null;
email?: string | null;
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string;
url: string;
html_url: string;
followers_url: string;
following_url: string;
gists_url: string;
starred_url: string;
subscriptions_url: string;
organizations_url: string;
repos_url: string;
events_url: string;
received_events_url: string;
type: string;
site_admin: boolean;
starred_at: string;
user_view_type: string;
}
export type PullsCreateParams = OctokitRest.RestEndpointMethodTypes['pulls']['create']['parameters'];
export type PullsCreateReviewResponseData = Endpoints['POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews']['response']['data'] & {
submitted_at: string;
};
export type PullsCreateReviewCommentResponseData = Endpoints['POST /repos/{owner}/{repo}/pulls/{pull_number}/comments']['response']['data'];
export type PullsGetResponseData = OctokitRest.RestEndpointMethodTypes['pulls']['get']['response']['data'];
export type IssuesGetResponseData = OctokitRest.RestEndpointMethodTypes['issues']['get']['response']['data'];
export type PullsGetResponseUser = Exclude<PullsGetResponseData['user'], null>;
export type PullsListCommitsResponseData = Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}/commits']['response']['data'];
export type PullsListRequestedReviewersResponseData = Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers']['response']['data'];
export type PullsListResponseItem = OctokitRest.RestEndpointMethodTypes['pulls']['list']['response']['data'][0];
export type PullsListResponseItemHead = PullsListResponseItem['head'];
export type PullsListResponseItemBase = PullsListResponseItem['base'];
export type PullsListResponseItemHeadRepo = PullsListResponseItemHead['repo'];
export type PullsListResponseItemBaseRepo = PullsListResponseItemBase['repo'];
export type PullsListResponseItemUser = Exclude<PullsListResponseItem['user'], null>;
export type PullsListResponseItemAssignee = PullsListResponseItem['assignee'];
export type PullsListResponseItemAssigneesItem = (Exclude<PullsListResponseItem['assignees'], null | undefined>)[0];
export type PullsListResponseItemRequestedReviewersItem = (Exclude<PullsListResponseItem['requested_reviewers'], null | undefined>)[0];
export type PullsListResponseItemBaseUser = PullsListResponseItemBase['user'];
export type PullsListResponseItemBaseRepoOwner = PullsListResponseItemBase['repo']['owner'];
export type PullsListResponseItemHeadUser = PullsListResponseItemHead['user'];
export type PullsListResponseItemHeadRepoOwner = PullsListResponseItemHead['repo']['owner'];
export type PullsListReviewRequestsResponseTeamsItem = Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers']['response']['data']['teams'][0];
export type PullsListCommitsResponseItem = Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}/commits']['response']['data'][0];
export type ReposCompareCommitsResponseData = OctokitRest.RestEndpointMethodTypes['repos']['compareCommits']['response']['data'];
export type ReposGetCombinedStatusForRefResponseStatusesItem = Endpoints['GET /repos/{owner}/{repo}/commits/{ref}/status']['response']['data']['statuses'][0];
export type ReposGetCommitResponseData = Endpoints['GET /repos/{owner}/{repo}/commits/{ref}']['response']['data'];
export type ReposGetCommitResponseFiles = Endpoints['GET /repos/{owner}/{repo}/commits/{ref}']['response']['data']['files'];
export type ReposGetResponseData = Endpoints['GET /repos/{owner}/{repo}']['response']['data'];
export type ReposGetResponseCodeOfConduct = ReposGetResponseData['code_of_conduct'];
export type ReposGetResponseOrganization = ReposGetResponseData['organization'];
export type ReposListBranchesResponseData = Endpoints['GET /repos/{owner}/{repo}/branches']['response']['data'];
export type SearchReposResponseItem = Endpoints['GET /search/repositories']['response']['data']['items'][0];
export type CompareCommits = Endpoints['GET /repos/{owner}/{repo}/compare/{base}...{head}']['response']['data'];
export type Commit = CompareCommits['commits'][0];
export type CommitFiles = CompareCommits['files']
export type Notification = Endpoints['GET /notifications']['response']['data'][0];
export type ListEventsForTimelineResponse = Endpoints['GET /repos/{owner}/{repo}/issues/{issue_number}/timeline']['response']['data'][0];
export type ListWorkflowRunsForRepo = Endpoints['GET /repos/{owner}/{repo}/actions/runs']['response']['data'];
export type WorkflowRun = Endpoints['GET /repos/{owner}/{repo}/actions/runs']['response']['data']['workflow_runs'][0];
export type WorkflowJob = Endpoints['GET /repos/{owner}/{repo}/actions/jobs/{job_id}']['response']['data'];
export type WorkflowJobs = Endpoints['GET /repos/{owner}/{repo}/actions/runs/{run_id}/jobs']['response']['data'];
}
export function mergeQuerySchemaWithShared(sharedSchema: DocumentNode, schema: DocumentNode) {
const sharedSchemaDefinitions = sharedSchema.definitions;
const schemaDefinitions = schema.definitions;
const mergedDefinitions = schemaDefinitions.concat(sharedSchemaDefinitions);
return {
...schema,
...sharedSchema,
definitions: mergedDefinitions
};
}
type RemoteAgentSuccessResult = { link: string; state: 'success'; number: number; webviewUri: Uri; llmDetails: string; sessionId: string };
type RemoteAgentErrorResult = { error: string; innerError?: string; state: 'error' };
export type RemoteAgentResult = RemoteAgentSuccessResult | RemoteAgentErrorResult;
export interface IAPISessionLogs {
readonly info: SessionInfo;
readonly logs: string;
readonly setupSteps: SessionSetupStep[] | undefined;
}
export interface ICopilotRemoteAgentCommandArgs {
userPrompt: string;
summary?: string;
source?: 'prompt' | (string & {});
followup?: string;
_version?: number; // TODO(jospicer): Remove once stabilized/engine version enforced
}
export interface ICopilotRemoteAgentCommandResponse {
uri: string;
title: string;
description: string;
author: string;
linkTag: string;
}
export interface ToolCall {
function: {
arguments: string;
name: 'bash' | 'reply_to_comment' | (string & {});
};
id: string;
type: string;
index: number;
}
export interface AssistantDelta {
content?: string;
role: 'assistant' | (string & {});
tool_calls?: ToolCall[];
}
export interface Choice {
finish_reason?: 'tool_calls' | (string & {});
delta: {
content?: string;
role: 'assistant' | (string & {});
tool_calls?: ToolCall[];
};
}
export interface RepoInfo {
owner: string;
repo: string;
baseRef: string;
remote: GitHubRemote;
repository: Repository;
ghRepository: GitHubRepository;
fm: FolderRepositoryManager;
}
export function copilotEventToSessionStatus(event: TimelineEvent | undefined): ChatSessionStatus {
if (!event) {
return ChatSessionStatus.InProgress;
}
switch (event.event) {
case EventType.CopilotStarted:
return ChatSessionStatus.InProgress;
case EventType.CopilotFinished:
return ChatSessionStatus.Completed;
case EventType.CopilotFinishedError:
return ChatSessionStatus.Failed;
default:
return ChatSessionStatus.InProgress;
}
}
export function copilotPRStatusToSessionStatus(event: CopilotPRStatus): ChatSessionStatus {
switch (event) {
case CopilotPRStatus.Started:
return ChatSessionStatus.InProgress;
case CopilotPRStatus.Completed:
return ChatSessionStatus.Completed;
case CopilotPRStatus.Failed:
return ChatSessionStatus.Failed;
default:
return ChatSessionStatus.InProgress;
}
}