-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-interface.ts
120 lines (100 loc) · 2.75 KB
/
git-interface.ts
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
import { GithubRepository } from "./vendors/github"
import { GitlabRepository } from "./vendors/gitlab"
export class Repository {
public url: string
public vendor: string
public vendorClient: any
public vendorInstance: any
public isDebug: boolean
// supported vendors
public vendors = [
{ name: 'github', client: GithubRepository },
{ name: 'gitlab', client: GitlabRepository }
]
constructor(repositoryUrl: string, repositoryVendor?: string, debug = false) {
this.url = repositoryUrl
this.vendor = repositoryVendor ? repositoryVendor : this.getRepositoryVendor(repositoryUrl)
this.isDebug = debug
if (this.vendor) {
for (let i = 0; i < this.vendors.length; i++) {
if (this.vendor === this.vendors[i].name) {
this.vendorClient = this.vendors[i].client
this.vendorInstance = new this.vendorClient(this.url, debug = this.isDebug)
}
}
if (!this.vendorClient) {
throw new Error('Repository vendor is not supported')
}
} else {
throw new Error('Repository vendor not found')
}
}
public getRepositoryVendor (url: string): string | undefined {
if (url) {
if (url.includes('github')) {
return 'github'
} else if (url.includes('gitlab')) {
return 'gitlab'
} else {
return undefined
}
} else {
return undefined
}
}
public async init () {
if (this.vendorInstance) {
await this.vendorInstance.init()
}
}
public async getRepositoryApi () {
if (this.vendorInstance) {
return await this.vendorInstance.getRepositoryApi()
}
}
public async getRepositoryInstance () {
if (this.vendorInstance) {
return await this.vendorInstance.getRepositoryInstance()
}
}
public async getUser () {
if (this.vendorInstance) {
return await this.vendorInstance.getUser()
}
}
public async getUsername () {
if (this.vendorInstance) {
return await this.vendorInstance.getUsername()
}
}
public async getDefaultBranch () {
if (this.vendorInstance) {
return await this.vendorInstance.getDefaultBranch()
}
}
public async getReadme () {
if (this.vendorInstance) {
return await this.vendorInstance.getReadme()
}
}
public async getReleases () {
if (this.vendorInstance) {
return await this.vendorInstance.getReleases()
}
}
public async getTags () {
if (this.vendorInstance) {
return await this.vendorInstance.getTags()
}
}
public async getBranches () {
if (this.vendorInstance) {
return await this.vendorInstance.getBranches()
}
}
public async getContributors () {
if (this.vendorInstance) {
return await this.vendorInstance.getContributors()
}
}
}