/
ProjectRepository.js
126 lines (85 loc) 路 3.4 KB
/
ProjectRepository.js
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
const BaseModel = require('./BaseModel');
const Utils = require('../Utils');
class ProjectRepository extends BaseModel {
listBranches(projectId) {
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/branches`);
}
showBranch(projectId, branchName) {
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/branches/${encodeURI(branchId)}`);
}
protectBranch(projectId, branchName, options = {}) {
const pId = Utils.parse(projectId);
return this.put(`projects/${pId}/repository/branches/${encodeURI(branchName)}/protect`, options);
}
unprotectBranch(projectId, branchName) {
const pId = Utils.parse(projectId);
return this.put(`projects/${pId}/repository/branches/${encodeURI(branchName)}/unprotect`);
}
createBranch(projectId, branch, ref) {
const pId = Utils.parse(projectId);
return this.post(`projects/${pId}/repository/branches`, { branch, ref });
}
deleteBranch(projectId, branchId) {
const pId = Utils.parse(projectId);
return this.delete(`projects/${pId}/repository/branches/${encodeURI(branchId)}`);
}
addTag(projectId, options = {}) {
const pId = Utils.parse(projectId);
return this.post(`projects/${pId}/repository/tags`, options);
}
deleteTag(projectId, tagName) {
const pId = Utils.parse(projectId);
return this.delete(`projects/${pId}/repository/tags/${encodeURI(tagName)}`);
}
showTag(projectId, tagName) {
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/tags/${encodeURI(tagName)}`);
}
listTags(projectId) {
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/tags`);
}
listCommits(projectId) {
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/commits`);
}
showCommit(projectId, sha) {
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/commits/${sha}`);
}
diffCommit(projectId, sha) {
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/commits/${sha}/diff`);
}
listTree(projectId, options = {}) {
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/tree`, options);
}
showFile(projectId, filePath, ref) {
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/files/${filePath}`, { ref: options.ref });
}
showRawFile(projectId, filePath, ref) {
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/files/${filePath}/raw`, { ref: options.ref });
}
createFile(projectId, filePath, branch, options = {}) {
const pId = Utils.parse(projectId);
return this.post(`projects/${pId}/repository/files/${filePath}`, Object.assign({ branch }, options));
}
updateFile(projectId, filePath, branch, options = {}) {
const pId = Utils.parse(projectId);
return this.put(`projects/${pId}/repository/files/${filePath}`, Object.assign({ branch }, options));
}
deleteFile(projectId, filePath, branch, options = {}) {
const pId = Utils.parse(projectId);
return this.delete(`projects/${pId}/repository/files/${filePath}`, Object.assign({ branch }, options));
}
compare(projectId, options = {}) {
const pId = Utils.parse(projectId);
return this.get(`projects/${pId}/repository/compare`, options);
}
}
module.exports = ProjectRepository;