forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.d.ts
More file actions
306 lines (257 loc) · 9.67 KB
/
api.d.ts
File metadata and controls
306 lines (257 loc) · 9.67 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CancellationToken, Disposable, Event, Uri } from 'vscode';
import { APIState, PublishEvent } from '../@types/git';
export interface InputBox {
value: string;
}
export { RefType } from './api1';
export interface Ref {
readonly type: RefType;
readonly name?: string;
readonly commit?: string;
readonly remote?: string;
}
export interface UpstreamRef {
readonly remote: string;
readonly name: string;
}
export interface Branch extends Ref {
readonly upstream?: UpstreamRef;
readonly ahead?: number;
readonly behind?: number;
}
export interface Commit {
readonly hash: string;
readonly message: string;
readonly parents: string[];
readonly authorDate?: Date;
readonly authorName?: string;
readonly authorEmail?: string;
readonly commitDate?: Date;
}
export interface Submodule {
readonly name: string;
readonly path: string;
readonly url: string;
}
export interface Remote {
readonly name: string;
readonly fetchUrl?: string;
readonly pushUrl?: string;
readonly isReadOnly: boolean;
}
export { Status } from './api1';
export interface Change {
/**
* Returns either `originalUri` or `renameUri`, depending
* on whether this change is a rename change. When
* in doubt always use `uri` over the other two alternatives.
*/
readonly uri: Uri;
readonly originalUri: Uri;
readonly renameUri: Uri | undefined;
readonly status: Status;
}
export interface RepositoryState {
readonly HEAD: Branch | undefined;
readonly remotes: Remote[];
readonly submodules: Submodule[];
readonly rebaseCommit: Commit | undefined;
readonly mergeChanges: Change[];
readonly indexChanges: Change[];
readonly workingTreeChanges: Change[];
readonly onDidChange: Event<void>;
}
export interface RepositoryUIState {
readonly selected: boolean;
readonly onDidChange: Event<void>;
}
export interface CommitOptions {
all?: boolean | 'tracked';
amend?: boolean;
signoff?: boolean;
signCommit?: boolean;
empty?: boolean;
}
export interface FetchOptions {
remote?: string;
ref?: string;
all?: boolean;
prune?: boolean;
depth?: number;
}
export interface RefQuery {
readonly contains?: string;
readonly count?: number;
readonly pattern?: string;
readonly sort?: 'alphabetically' | 'committerdate';
}
export interface BranchQuery extends RefQuery {
readonly remote?: boolean;
}
export interface Repository {
readonly inputBox: InputBox;
readonly rootUri: Uri;
readonly state: RepositoryState;
readonly ui: RepositoryUIState;
/**
* GH PR saves pull request related information to git config when users checkout a pull request.
* There are two mandatory config for a branch
* 1. `remote`, which refers to the related github repository
* 2. `github-pr-owner-number`, which refers to the related pull request
*
* There is one optional config for a remote
* 1. `github-pr-remote`, which indicates if the remote is created particularly for GH PR review. By default, GH PR won't load pull requests from remotes created by itself (`github-pr-remote=true`).
*
* Sample config:
* ```git
* [remote "pr"]
* url = https://github.com/pr/vscode-pull-request-github
* fetch = +refs/heads/*:refs/remotes/pr/*
* github-pr-remote = true
* [branch "fix-123"]
* remote = pr
* merge = refs/heads/fix-123
* github-pr-owner-number = "Microsoft#vscode-pull-request-github#123"
* ```
*/
getConfigs(): Promise<{ key: string; value: string }[]>;
/**
* Git providers are recommended to implement a minimal key value lookup for git config but you can only provide config for following keys to activate GH PR successfully
* 1. `branch.${branchName}.github-pr-owner-number`
* 2. `remote.${remoteName}.github-pr-remote`
* 3. `branch.${branchName}.remote`
*/
getConfig(key: string): Promise<string>;
/**
* The counterpart of `getConfig`
*/
setConfig(key: string, value: string): Promise<string>;
unsetConfig?(key: string): Promise<string>;
getGlobalConfig(key: string): Promise<string>;
getObjectDetails(treeish: string, path: string): Promise<{ mode: string; object: string; size: number }>;
detectObjectType(object: string): Promise<{ mimetype: string; encoding?: string }>;
buffer(ref: string, path: string): Promise<Buffer>;
show(ref: string, path: string): Promise<string>;
getCommit(ref: string): Promise<Commit>;
clean(paths: string[]): Promise<void>;
apply(patch: string, reverse?: boolean): Promise<void>;
diff(cached?: boolean): Promise<string>;
diffWithHEAD(): Promise<Change[]>;
diffWithHEAD(path: string): Promise<string>;
diffWith(ref: string): Promise<Change[]>;
diffWith(ref: string, path: string): Promise<string>;
diffIndexWithHEAD(): Promise<Change[]>;
diffIndexWithHEAD(path: string): Promise<string>;
diffIndexWith(ref: string): Promise<Change[]>;
diffIndexWith(ref: string, path: string): Promise<string>;
diffBlobs(object1: string, object2: string): Promise<string>;
diffBetween(ref1: string, ref2: string): Promise<Change[]>;
diffBetween(ref1: string, ref2: string, path: string): Promise<string>;
hashObject(data: string): Promise<string>;
createBranch(name: string, checkout: boolean, ref?: string): Promise<void>;
deleteBranch(name: string, force?: boolean): Promise<void>;
getBranch(name: string): Promise<Branch>;
getBranches(query: BranchQuery): Promise<Ref[]>;
getBranchBase(name: string): Promise<Branch | undefined>;
setBranchUpstream(name: string, upstream: string): Promise<void>;
getRefs?(query: RefQuery, cancellationToken?: CancellationToken): Promise<Ref[]>; // Optional, because Remote Hub doesn't support this
getMergeBase(ref1: string, ref2: string): Promise<string | undefined>;
status(): Promise<void>;
checkout(treeish: string): Promise<void>;
addRemote(name: string, url: string): Promise<void>;
removeRemote(name: string): Promise<void>;
renameRemote(name: string, newName: string): Promise<void>;
fetch(options?: FetchOptions): Promise<void>;
fetch(remote?: string, ref?: string, depth?: number): Promise<void>;
pull(unshallow?: boolean): Promise<void>;
push(remoteName?: string, branchName?: string, setUpstream?: boolean): Promise<void>;
blame(path: string): Promise<string>;
log(options?: LogOptions): Promise<Commit[]>;
commit(message: string, opts?: CommitOptions): Promise<void>;
add(paths: string[]): Promise<void>;
merge(ref: string): Promise<void>;
mergeAbort(): Promise<void>;
}
/**
* Log options.
*/
export interface LogOptions {
/** Max number of log entries to retrieve. If not specified, the default is 32. */
readonly maxEntries?: number;
readonly path?: string;
/** A commit range, such as "0a47c67f0fb52dd11562af48658bc1dff1d75a38..0bb4bdea78e1db44d728fd6894720071e303304f" */
readonly range?: string;
}
export interface PostCommitCommandsProvider {
getCommands(repository: Repository): Command[];
}
export { GitErrorCodes } from './api1';
export interface IGit {
readonly repositories: Repository[];
readonly onDidOpenRepository: Event<Repository>;
readonly onDidCloseRepository: Event<Repository>;
// Used by the actual git extension to indicate it has finished initializing state information
readonly state?: APIState;
readonly onDidChangeState?: Event<APIState>;
readonly onDidPublish?: Event<PublishEvent>;
registerPostCommitCommandsProvider?(provider: PostCommitCommandsProvider): Disposable;
getRepositoryWorkspace?(uri: Uri): Promise<Uri[] | null>;
clone?(uri: Uri, options?: CloneOptions): Promise<Uri | null>;
}
export interface TitleAndDescriptionProvider {
provideTitleAndDescription(context: { commitMessages: string[], patches: string[] | { patch: string, fileUri: string, previousFileUri?: string }[], issues?: { reference: string, content: string }[], template?: string }, token: CancellationToken): Promise<{ title: string, description?: string } | undefined>;
}
export interface ReviewerComments {
// To tell which files we should add a comment icon in the "Files Changed" view
files: Uri[];
succeeded: boolean;
// For removing comments
disposable?: Disposable;
}
export interface ReviewerCommentsProvider {
provideReviewerComments(context: { repositoryRoot: string, commitMessages: string[], patches: { patch: string, fileUri: string, previousFileUri?: string }[] }, token: CancellationToken): Promise<ReviewerComments>;
}
export interface RepositoryDescription {
owner: string;
repositoryName: string;
defaultBranch: string;
pullRequest?: {
title: string;
url: string;
number: number;
id: number;
};
}
export interface API {
/**
* Register a [git provider](#IGit)
*/
registerGitProvider(provider: IGit): Disposable;
/**
* Returns the [git provider](#IGit) that contains a given uri.
*
* @param uri An uri.
* @return A git provider or `undefined`
*/
getGitProvider(uri: Uri): IGit | undefined;
/**
* Register a PR title and description provider.
*/
registerTitleAndDescriptionProvider(title: string, provider: TitleAndDescriptionProvider): Disposable;
/**
* Register a PR reviewer comments provider.
*/
registerReviewerCommentsProvider(title: string, provider: ReviewerCommentsProvider): Disposable;
/**
* Get the repository description for a given URI, where the URI is a subpath of one of the workspace folders.
* This includes the owner, repository name, default branch,
* and pull request information (if applicable).
*
* @returns A promise that resolves to a `RepositoryDescription` object or `undefined` if no repository is found.
*/
getRepositoryDescription(uri: vscode.Uri): Promise<RepositoryDescription | undefined>;
}