@@ -10,7 +10,6 @@ import validation
10
10
11
11
struct Repo {
12
12
id int [primary; sql: serial]
13
- git_repo & git.Repo [skip] // libgit wrapper repo
14
13
git_dir string
15
14
name string
16
15
user_id int
@@ -21,24 +20,26 @@ struct Repo {
21
20
is_public bool
22
21
users_contributed []string [skip]
23
22
users_authorized []string [skip]
24
- topics_count int [skip]
23
+ nr_topics int [skip]
25
24
views_count int
26
25
latest_update_hash string [skip]
27
26
latest_activity time.Time [skip]
28
27
mut :
29
- webhook_secret string
30
- tags_count int
31
- open_issues_count int
32
- open_prs_count int
33
- releases_count int
34
- branches_count int
35
- stars_count int
36
- lang_stats []LangStat [skip]
37
- created_at int
38
- contributors_count int
39
- labels []Label [skip]
40
- status RepoStatus [skip]
41
- msg_cache map [string ]string [skip]
28
+ git_repo & git.Repo [skip] // libgit wrapper repo
29
+ webhook_secret string
30
+ tags_count int
31
+ nr_open_issues int [orm: 'open_issues_count' ]
32
+ nr_open_prs int [orm: 'open_prs_count' ]
33
+ nr_releases int [orm: 'releases_count' ]
34
+ nr_branches int [orm: 'branches_count' ]
35
+ nr_tags int
36
+ nr_stars int [orm: 'stars_count' ]
37
+ lang_stats []LangStat [skip]
38
+ created_at int
39
+ nr_contributors int
40
+ labels []Label [skip]
41
+ status RepoStatus [skip]
42
+ msg_cache map [string ]string [skip]
42
43
}
43
44
44
45
// log_field_separator is declared as constant in case we need to change it later
@@ -74,32 +75,37 @@ fn (mut app App) save_repo(repo Repo) ! {
74
75
webhook_secret := repo.webhook_secret
75
76
tags_count := repo.tags_count
76
77
is_public := if repo.is_public { 1 } else { 0 }
77
- open_issues_count := repo.open_issues_count
78
- open_prs_count := repo.open_prs_count
79
- branches_count := repo.branches_count
80
- releases_count := repo.releases_count
81
- stars_count := repo.stars_count
82
- contributors_count := repo.contributors_count
78
+ open_issues_count := repo.nr_open_issues
79
+ open_prs_count := repo.nr_open_prs
80
+ branches_count := repo.nr_branches
81
+ releases_count := repo.nr_releases
82
+ stars_count := repo.nr_stars
83
+ contributors_count := repo.nr_contributors
84
+
85
+ // XTODO sql update all fields automatically
86
+ // repo.update()
83
87
84
88
sql app.db {
85
89
update Repo set description = desc , views_count = views_count , is_public = is_public,
86
- webhook_secret = webhook_secret , tags_count = tags_count , open_issues_count = open_issues_count,
87
- open_prs_count = open_prs_count , releases_count = releases_count , contributors_count = contributors_count,
88
- stars_count = stars_count , branches_count = branches_count where id == id
90
+ webhook_secret = webhook_secret , tags_count = tags_count , nr_open_issues = open_issues_count,
91
+ nr_open_prs = open_prs_count , nr_releases = releases_count , nr_contributors = contributors_count,
92
+ nr_stars = stars_count , nr_branches = branches_count where id == id
89
93
}!
90
94
}
91
95
92
96
fn (app App) find_repo_by_name_and_user_id (repo_name string , user_id int ) ? Repo {
93
97
repos := sql app.db {
94
98
select from Repo where name == repo_name && user_id == user_id limit 1
95
- } or { []Repo{} }
99
+ } or { return none }
96
100
97
101
if repos.len == 0 {
98
102
return none
99
103
}
100
104
101
- mut repo := repos. first ()
105
+ mut repo := repos[ 0 ]
102
106
repo.lang_stats = app.find_repo_lang_stats (repo.id)
107
+ println ('GIT DIR = ${repo.git_dir} ' )
108
+ repo.git_repo = git.new_repo (repo.git_dir)
103
109
104
110
return repo
105
111
}
@@ -145,7 +151,7 @@ fn (app App) search_public_repos(query string) []Repo {
145
151
name: row.vals[1 ]
146
152
user_name: user.username
147
153
description: row.vals[3 ]
148
- stars_count : row.vals[4 ].int ()
154
+ nr_stars : row.vals[4 ].int ()
149
155
}
150
156
}
151
157
@@ -175,13 +181,13 @@ fn (mut app App) increment_repo_views(repo_id int) ! {
175
181
176
182
fn (mut app App) increment_repo_stars (repo_id int ) ! {
177
183
sql app.db {
178
- update Repo set stars_count = stars_count + 1 where id == repo_id
184
+ update Repo set nr_stars = nr_stars + 1 where id == repo_id
179
185
}!
180
186
}
181
187
182
188
fn (mut app App) decrement_repo_stars (repo_id int ) ! {
183
189
sql app.db {
184
- update Repo set stars_count = stars_count - 1 where id == repo_id
190
+ update Repo set nr_stars = nr_stars - 1 where id == repo_id
185
191
}!
186
192
}
187
193
@@ -199,7 +205,7 @@ fn (mut app App) set_repo_webhook_secret(repo_id int, secret string) ! {
199
205
200
206
fn (mut app App) increment_repo_issues (repo_id int ) ! {
201
207
sql app.db {
202
- update Repo set open_issues_count = open_issues_count + 1 where id == repo_id
208
+ update Repo set nr_open_issues = nr_open_issues + 1 where id == repo_id
203
209
}!
204
210
}
205
211
@@ -254,9 +260,9 @@ fn (mut app App) update_repo_from_fs(mut repo Repo) ! {
254
260
255
261
app.db.exec ('BEGIN TRANSACTION' )!
256
262
257
- repo.analyse_lang (app)!
263
+ repo.analyze_lang (app)!
258
264
259
- app.info (repo.contributors_count .str ())
265
+ app.info (repo.nr_contributors .str ())
260
266
app.fetch_branches (repo)!
261
267
262
268
branches_output := repo.git ('branch -a' )
@@ -267,14 +273,14 @@ fn (mut app App) update_repo_from_fs(mut repo Repo) ! {
267
273
app.update_repo_branch_from_fs (mut repo, branch_name)!
268
274
}
269
275
270
- repo.contributors_count = app.get_count_repo_contributors (repo_id)!
271
- repo.branches_count = app.get_count_repo_branches (repo_id)
276
+ repo.nr_contributors = app.get_count_repo_contributors (repo_id)!
277
+ repo.nr_branches = app.get_count_repo_branches (repo_id)
272
278
273
279
// TODO: TEMPORARY - UNTIL WE GET PERSISTENT RELEASE INFO
274
280
for tag in app.get_all_repo_tags (repo_id) {
275
281
app.add_release (tag.id, repo_id, time.unix (tag.created_at), tag.message)!
276
282
277
- repo.releases_count ++
283
+ repo.nr_releases ++
278
284
}
279
285
280
286
app.save_repo (repo)!
@@ -329,9 +335,9 @@ fn (mut app App) update_repo_from_remote(mut repo Repo) ! {
329
335
330
336
app.db.exec ('BEGIN TRANSACTION' )!
331
337
332
- repo.analyse_lang (app)!
338
+ repo.analyze_lang (app)!
333
339
334
- app.info (repo.contributors_count .str ())
340
+ app.info (repo.nr_contributors .str ())
335
341
app.fetch_branches (repo)!
336
342
app.fetch_tags (repo)!
337
343
@@ -345,12 +351,11 @@ fn (mut app App) update_repo_from_remote(mut repo Repo) ! {
345
351
346
352
for tag in app.get_all_repo_tags (repo_id) {
347
353
app.add_release (tag.id, repo_id, time.unix (tag.created_at), tag.message)!
348
-
349
- repo.releases_count++
354
+ repo.nr_releases++
350
355
}
351
356
352
- repo.contributors_count = app.get_count_repo_contributors (repo_id)!
353
- repo.branches_count = app.get_count_repo_branches (repo_id)
357
+ repo.nr_contributors = app.get_count_repo_contributors (repo_id)!
358
+ repo.nr_branches = app.get_count_repo_branches (repo_id)
354
359
355
360
app.save_repo (repo)!
356
361
app.db.exec ('END TRANSACTION' )!
@@ -404,7 +409,7 @@ fn (mut app App) update_repo_after_push(repo_id int, branch_name string) ! {
404
409
app.delete_repository_files_in_branch (repo_id, branch_name)!
405
410
}
406
411
407
- fn (r &Repo) analyse_lang (app & App) ! {
412
+ fn (r &Repo) analyze_lang (app & App) ! {
408
413
file_paths := r.get_all_file_paths ()
409
414
410
415
mut all_size := 0
@@ -760,6 +765,15 @@ fn (mut app App) update_repo_primary_branch(repo_id int, branch string) ! {
760
765
}
761
766
762
767
fn (mut r Repo) clone () {
768
+ if r.git_repo != unsafe { nil } {
769
+ r.git_repo.clone (r.clone_url, r.git_dir)
770
+ } else {
771
+ println ('nil' )
772
+ }
773
+
774
+ /*
775
+ cmd := 'git clone --bare "${r.clone_url}" ${r.git_dir}'
776
+ println('CLONE() ${cmd}')
763
777
clone_result := os.execute('git clone --bare "${r.clone_url}" ${r.git_dir}')
764
778
close_exit_code := clone_result.exit_code
765
779
@@ -768,17 +782,22 @@ fn (mut r Repo) clone() {
768
782
println('git clone failed with exit code ${close_exit_code}')
769
783
return
770
784
}
785
+ */
771
786
772
787
r.status = .clone_done
773
788
}
774
789
775
790
fn (r &Repo) read_file (branch string , path string ) string {
776
791
// valid_path := path.trim_string_left('/')
777
792
778
- println ('yEPP' )
793
+ println ('yEPP path=${valid_path} ' )
794
+ if r.git_repo == unsafe { nil } {
795
+ return 'nil'
796
+ }
779
797
t := time.now ()
780
798
// s := r.git('--no-pager show ${branch}:${valid_path}')
781
- s := r.git_repo.show_file_blob (branch, path) or { '' }
799
+
800
+ s := r.git_repo.show_file_blob (branch, valid_path) or { '' }
782
801
println (time.since (t))
783
802
println (':)' )
784
803
return s
0 commit comments