forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote.ts
More file actions
71 lines (61 loc) · 1.82 KB
/
remote.ts
File metadata and controls
71 lines (61 loc) · 1.82 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Protocol } from './protocol';
import { Repository } from '../git/api';
export class Remote {
public get host(): string {
return this.gitProtocol.host;
}
public get owner(): string {
return this.gitProtocol.owner;
}
public get repositoryName(): string {
return this.gitProtocol.repositoryName;
}
public get normalizedHost(): string {
const normalizedUri = this.gitProtocol.normalizeUri();
return `${normalizedUri!.scheme}://${normalizedUri!.authority}`;
}
constructor(
public readonly remoteName: string,
public readonly url: string,
public readonly gitProtocol: Protocol,
) { }
equals(remote: Remote): boolean {
if (this.remoteName !== remote.remoteName) {
return false;
}
if (this.host !== remote.host) {
return false;
}
if (this.owner !== remote.owner) {
return false;
}
if (this.repositoryName !== remote.repositoryName) {
return false;
}
return true;
}
}
export function parseRemote(remoteName: string, url: string | undefined, originalProtocol?: Protocol): Remote | null {
if (!url) {
return null;
}
let gitProtocol = new Protocol(url);
if (originalProtocol) {
gitProtocol.update({
type: originalProtocol.type
});
}
if (gitProtocol.host) {
return new Remote(remoteName, url, gitProtocol);
}
return null;
}
export function parseRepositoryRemotes(repository: Repository): Remote[] {
return repository.state.remotes
.map(r => parseRemote(r.name, r.fetchUrl || r.pushUrl))
.filter(r => !!r) as Remote[];
}