forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuri.ts
More file actions
113 lines (93 loc) · 2.63 KB
/
Copy pathuri.ts
File metadata and controls
113 lines (93 loc) · 2.63 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Uri, UriHandler, EventEmitter } from 'vscode';
import { IPullRequestModel } from '../github/interface';
export interface ReviewUriParams {
path: string;
ref?: string;
commit?: string;
base: boolean;
isOutdated: boolean;
}
export function fromReviewUri(uri: Uri): ReviewUriParams {
return JSON.parse(uri.query);
}
export interface PRUriParams {
baseCommit: string;
headCommit: string;
isBase: boolean;
fileName: string;
prNumber: number;
}
export function fromPRUri(uri: Uri): PRUriParams {
return JSON.parse(uri.query);
}
export interface GitUriOptions {
replaceFileExtension?: boolean;
submoduleOf?: string;
base: boolean;
}
// As a mitigation for extensions like ESLint showing warnings and errors
// for git URIs, let's change the file extension of these uris to .git,
// when `replaceFileExtension` is true.
export function toReviewUri(uri: Uri, filePath: string, ref: string, commit: string, isOutdated: boolean, options: GitUriOptions): Uri {
const params: ReviewUriParams = {
path: filePath ? filePath : uri.path,
ref,
commit: commit,
base: options.base,
isOutdated
};
let path = uri.path;
if (options.replaceFileExtension) {
path = `${path}.git`;
}
return uri.with({
scheme: 'review',
path,
query: JSON.stringify(params)
});
}
export interface FileChangeNodeUriParams {
hasComments?: boolean;
}
export function toFileChangeNodeUri(uri: Uri, hasComments: boolean) {
const params = {
hasComments: hasComments
};
return uri.with({
scheme: 'file',
query: JSON.stringify(params)
});
}
export function fromFileChangeNodeUri(uri: Uri): FileChangeNodeUriParams {
try {
return JSON.parse(uri.query) as FileChangeNodeUriParams;
} catch (e) {
return null;
}
}
export function toPRUri(uri: Uri, pullRequestModel: IPullRequestModel, baseCommit: string, headCommit: string, fileName: string, base: boolean): Uri {
const params: PRUriParams = {
baseCommit: baseCommit,
headCommit: headCommit,
isBase: base,
fileName: fileName,
prNumber: pullRequestModel.prNumber
};
let path = uri.path;
return uri.with({
scheme: 'pr',
path,
query: JSON.stringify(params)
});
}
class UriEventHandler extends EventEmitter<Uri> implements UriHandler {
public handleUri(uri: Uri) {
this.fire(uri);
}
}
export const handler = new UriEventHandler;