-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathrepos.js
190 lines (109 loc) · 3.92 KB
/
repos.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
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
// create a repository object
function createRepoObj(fullName, selBranch, defaultBranch,
pushAccess, branches, private,
isFork, empty,
repoDataExpiration, branchExpiration) {
return {
fullName,
selBranch,
defaultBranch,
pushAccess,
branches,
private,
isFork,
empty,
repoDataExpiration,
branchExpiration,
}
}
// modified repos
function addRepoToModRepos(repoObj) {
modifiedRepos[repoObj.fullName] = repoObj;
updateModReposLS();
}
function deleteModRepo(fullName) {
delete modifiedRepos[fullName];
updateModReposLS();
}
function updateModRepoSelectedBranch(fullName, selBranch) {
modifiedRepos[fullName].selBranch = selBranch;
if (!isEmbed) {
updateModReposLS();
}
}
function updateModRepoDefaultBranch(fullName, defaultBranch) {
modifiedRepos[fullName].defaultBranch = defaultBranch;
updateModReposLS();
}
function updateModRepoPushAccess(fullName, pushAccess) {
modifiedRepos[fullName].pushAccess = pushAccess;
updateModReposLS();
}
function updateModRepoBranches(fullName, branches) {
modifiedRepos[fullName].branches = branches;
updateModReposLS();
}
function updateModRepoPrivateStatus(fullName, private) {
modifiedRepos[fullName].private = private;
updateModReposLS();
}
function updateModRepoEmptyStatus(fullName, empty) {
modifiedRepos[fullName].empty = empty;
updateModReposLS();
}
function updateModRepoDataExpiration(fullName, time) {
modifiedRepos[fullName].repoDataExpiration = time;
updateModReposLS();
}
function updateModRepoBranchExpiration(fullName, time) {
modifiedRepos[fullName].branchExpiration = time;
updateModReposLS();
}
// get repo obj from git
// and save to modified repos
let repoPromise;
async function fetchRepoAndSaveToModRepos(treeLoc) {
// get full name of repository
const fullName = treeLoc[0] + '/' + treeLoc[1].split(':')[0];
const selBranch = treeLoc[1].split(':')[1];
// create temporary repo object
const tempRepoObj = createRepoObj(fullName, selBranch, null,
null, null, null, null, null, 0, 0);
// add temp repo object
// to modified repos
addRepoToModRepos(tempRepoObj);
// get repository from git
// create promise
repoPromise = git.getRepo(treeLoc);
// await promise
const repo = await repoPromise;
// remove promise
repoPromise = null;
// if didn't encounter an error
if (!repo.message) {
// check temp repo changed
const tempRepo = modifiedRepos[fullName];
// get repo data expiration time
// (two days from now)
let expirationDate = new Date();
expirationDate.setDate(expirationDate.getDate() + 2);
const twoDaysFromNow = expirationDate.getTime();
// create repo obj
const repoObj = createRepoObj(fullName,
(tempRepo.selBranch ?? repo.default_branch),
repo.default_branch,
(tempRepo.pushAccess ?? ((repo.permissions && repo.permissions.push) ?? false)),
(tempRepo.branches ?? null),
repo.private, repo.fork,
(tempRepo.empty ?? false),
twoDaysFromNow,
tempRepo.branchExpiration);
// add repo object
// to modified repos
addRepoToModRepos(repoObj);
} else {
// remove temp repo object
// from modified repos
deleteModRepo(fullName);
}
}